-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathglassit.py
128 lines (108 loc) · 5.43 KB
/
glassit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import sublime, sublime_plugin, os, sys, re, subprocess
def findApp(app_name):
# ST2: main program path isn't included in sys.path, but sys.executable points to the main program.
if sys.version_info[0] == 2:
st_path = os.path.dirname(sys.executable)
else:
# ST3 & ST4: main program path from sublime.executable_path()
st_path = os.path.dirname(sublime.executable_path())
absPath = st_path + "\\" + app_name
if(os.path.isfile(absPath)):
return True, absPath
return False, ""
def findAppAlt(app_name):
absPathAlt = os.path.join(config.app_path_alt, app_name)
if (os.path.isfile(absPathAlt)):
return True, absPathAlt
return False, ""
def set_window_transparency_nt(pid, alpha, app_title, app_name):
found, app_path = findApp(app_name)
if (not found):
found, app_path = findAppAlt(app_name)
if(found):
command = "\"" + app_path + "\"" + " " + str(pid) + " " + str(alpha) + " " + app_title
subprocess.Popen(command, shell=True)
print('Using transparency utility from "%s"' %(app_path))
print("Sublime window transparency is set to %d" %(alpha))
else:
print("Cannot find %s! Please download and put into sublime path or application_path_alt." %(app_name))
return found
def update_window_transparency_nt():
if (set_window_transparency_nt(config.st_pid, config.alpha_current if config.enabled else config.alpha_max, config.st_title, config.app_name)):
if (config.enabled_saved != config.enabled or config.alpha_per_current_saved != config.alpha_per_current):
if (config.enabled_saved != config.enabled):
config.settings.set('enabled', config.enabled)
config.enabled_saved = config.enabled
if (config.alpha_per_current_saved != config.alpha_per_current):
config.settings.set('alpha_percentage', config.alpha_per_current)
config.alpha_per_current_saved = config.alpha_per_current
sublime.save_settings('glassit.sublime-settings')
def plugin_loaded():
settings = sublime.load_settings('glassit.sublime-settings')
global config
class config:
def load(self):
if (sublime.platform() == "windows"):
config.settings = settings
config.enabled = bool(settings.get('enabled', True))
config.enabled_saved = config.enabled
config.alpha_per_default = int(settings.get('alpha_percentage_default', 90))
config.alpha_per_current = int(settings.get('alpha_percentage', config.alpha_per_default))
config.alpha_per_current_saved = config.alpha_per_current
config.alpha_step = int(settings.get('alpha_step', 5))
config.alpha_max = 255
config.app_name = settings.get('application', "SetTransparency.exe")
config.app_path_alt = settings.get('application_path_alt', "")
config.st_title = settings.get('st_title', "Sublime Text")
config.delay = 5000
config.alpha_current = config.alpha_max * config.alpha_per_current / 100
if sys.version_info[0] == 2:
# ST2 load plugin within main process
config.st_pid = os.getpid()
else:
# ST3 load plugin in the child process "plugin_host.exe"
config.st_pid = os.getppid()
else:
print("Set transparency doesn't support this platform yet!")
def reload(self):
self.load()
if (sublime.platform() == "windows"):
update_window_transparency_nt()
config = config()
config.load()
if (sublime.platform() == "windows"):
# Delay set transparency until main window is created.
sublime.set_timeout(update_window_transparency_nt, config.delay)
else:
print("Set transparency doesn't support this platform yet!")
settings.add_on_change('reload', lambda:config.reload())
if sys.version_info[0] == 2:
plugin_loaded()
class ToggleTransparencyCommand(sublime_plugin.TextCommand):
def run(self, edit):
config.enabled = not config.enabled
update_window_transparency_nt()
def is_checked(self, **args):
return config.enabled
class ResetTransparencyCommand(sublime_plugin.TextCommand):
def run(self, edit):
if(config.enabled == True):
config.alpha_per_current = config.alpha_per_default
config.alpha_current = config.alpha_max * config.alpha_per_current / 100
update_window_transparency_nt()
class IncreaseTransparencyCommand(sublime_plugin.TextCommand):
def run(self, edit):
if(config.enabled == True):
config.alpha_per_current = config.alpha_per_current - config.alpha_step
if(config.alpha_per_current < 0):
config.alpha_per_current = 0
config.alpha_current = config.alpha_max * config.alpha_per_current / 100
update_window_transparency_nt()
class DecreaseTransparencyCommand(sublime_plugin.TextCommand):
def run(self, edit):
if(config.enabled == True):
config.alpha_per_current = config.alpha_per_current + config.alpha_step
if(config.alpha_per_current > 100):
config.alpha_per_current = 100
config.alpha_current = config.alpha_max * config.alpha_per_current / 100
update_window_transparency_nt()