-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
ch_dev.py
43 lines (34 loc) · 1.45 KB
/
ch_dev.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
"""Development tools for color helper."""
import sublime
import sublime_plugin
from . import ch_util as util
import sys
import traceback
PY38 = (3, 8) <= sys.version_info
if PY38:
from importlib import reload as imp_reload
else:
from imp import reload as imp_reload
class ColorHelperReloadColorClassCommand(sublime_plugin.ApplicationCommand):
"""Force a reload of custom color class modules."""
def run(self):
"""Run command."""
color_classes = util.get_settings_colors()
for k, v in color_classes.items():
color_class = v.get("class", "ColorHelper.lib.coloraide.Color")
# Don't reload the built-in module.
if not color_class.startswith('ColorHelper.lib.coloraide.'):
module = color_class.rsplit('.', 1)[0]
if module in sys.modules:
try:
sys.modules[module] = imp_reload(sys.modules[module])
util.log("Reloaded '{}'".format(module))
except Exception:
util.log(str(traceback.format_exc()))
# Ensure all windows refresh their cache of color classes
for window in sublime.windows():
for view in window.views():
view.settings().set('color_helper.refresh', True)
def is_enabled(self, **kwargs):
"""Check if enabled."""
return sublime.load_settings('color_helper.sublime-settings').get("debug", False)