1
|
|
|
""" |
2
|
|
|
Allow easy manipulations of the rainmeter themes. |
3
|
|
|
|
4
|
|
|
The rainmeter themes are hidden to the default system |
5
|
|
|
so other systems can not use these color schemes. |
6
|
|
|
""" |
7
|
|
|
|
8
|
|
|
import re |
9
|
|
|
|
10
|
|
|
import sublime |
11
|
|
|
import sublime_plugin |
12
|
|
|
|
13
|
|
|
from . import logger |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class EditThemeCommand(sublime_plugin.ApplicationCommand): |
17
|
|
|
"""Bind to the sublime text API via the ApplicationCommand.""" |
18
|
|
|
|
19
|
|
|
def run(self, theme): # pylint: disable=R0201; sublime text API, no need for class reference |
20
|
|
|
""" |
21
|
|
|
Search all *.tmTheme files in the Rainmeter space and tries to match it to the theme param. |
22
|
|
|
|
23
|
|
|
If no matching theme was found an error is reported to the log |
24
|
|
|
and tell the user that his intended operation failed. |
25
|
|
|
|
26
|
|
|
Parameters |
27
|
|
|
---------- |
28
|
|
|
self: EditThemeCommand |
29
|
|
|
the current instance given to the method. |
30
|
|
|
|
31
|
|
|
theme: String |
32
|
|
|
Given String through the menu. Should match one of the tmTheme in the Rainmeter space |
33
|
|
|
""" |
34
|
|
|
all_themes = sublime.find_resources("*.hidden-tmTheme") |
35
|
|
|
|
36
|
|
|
# only list rainmeter themes |
37
|
|
|
# could be installed via "add repository" then the file is named after the repository |
38
|
|
|
rm_exp = re.compile(r"Packages/Rainmeter/", re.IGNORECASE) |
39
|
|
|
|
40
|
|
|
theme_exp = re.compile(re.escape(theme)) |
41
|
|
|
filtered_themes = [theme for theme in all_themes if rm_exp.search(theme) and theme_exp.search(theme)] |
42
|
|
|
|
43
|
|
|
if len(filtered_themes) != 1: |
44
|
|
|
str_all_themes = '\n'.join(str(t) for t in all_themes) |
45
|
|
|
str_filtered_themes = '\n'.join(str(t) for t in filtered_themes) |
46
|
|
|
message = """searched for '{theme}' in |
47
|
|
|
|
48
|
|
|
{stringified_all_themes} |
49
|
|
|
|
50
|
|
|
but resulted into more or less than 1 result with |
51
|
|
|
|
52
|
|
|
{stringified_filtered_themes}""" |
53
|
|
|
formatted_message = message.format( |
54
|
|
|
theme=theme, |
55
|
|
|
stringified_all_themes=str_all_themes, |
56
|
|
|
stringified_filtered_themes=str_filtered_themes |
57
|
|
|
) |
58
|
|
|
logger.error(formatted_message) |
59
|
|
|
sublime.error_message(formatted_message) |
60
|
|
|
|
61
|
|
|
# we found only one |
62
|
|
|
theme = filtered_themes[0] |
63
|
|
|
settings = sublime.load_settings("Rainmeter.sublime-settings") |
64
|
|
|
settings.set("color_scheme", theme) |
65
|
|
|
sublime.save_settings("Rainmeter.sublime-settings") |
66
|
|
|
|
67
|
|
|
def is_checked(self, theme): # pylint: disable=R0201; sublime text API, no need for class reference |
68
|
|
|
""" |
69
|
|
|
Return True if a checkbox should be shown next to the menu item. |
70
|
|
|
|
71
|
|
|
The .sublime-menu file must have the checkbox attribute set to true for this to be used. |
72
|
|
|
""" |
73
|
|
|
settings = sublime.load_settings("Rainmeter.sublime-settings") |
74
|
|
|
color_scheme = settings.get("color_scheme", None) |
75
|
|
|
theme_exp = re.compile(re.escape(theme)) |
76
|
|
|
|
77
|
|
|
return theme_exp.search(color_scheme) is not None |
78
|
|
|
|