-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
oomox_plugin.py
187 lines (156 loc) · 6.19 KB
/
oomox_plugin.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import os
from typing import TYPE_CHECKING
from gi.repository import Gtk
from oomox_gui.export_common import ExportConfig, FileBasedExportDialog
from oomox_gui.i18n import translate
from oomox_gui.plugin_api import OomoxExportPlugin
if TYPE_CHECKING:
from typing import Any, Final
from oomox_gui.theme_file import ThemeT
PLUGIN_DIR: "Final" = os.path.dirname(os.path.realpath(__file__))
OOMOXIFY_SCRIPT_PATH: "Final" = os.path.join(
PLUGIN_DIR, "oomoxify.sh",
)
OPTION_SPOTIFY_PATH: "Final" = "spotify_path"
OPTION_FONT_NAME: "Final" = "font_name"
OPTION_FONT_OPTIONS: "Final" = "font_options"
VALUE_FONT_DEFAULT: "Final" = "default"
VALUE_FONT_NORMALIZE: "Final" = "normalize"
VALUE_FONT_CUSTOM: "Final" = "custom"
class SpotifyExportDialog(FileBasedExportDialog):
export_config = None
timeout = 120
def do_export(self) -> None:
self.export_config[OPTION_FONT_NAME] = self.font_name_entry.get_text()
self.export_config[OPTION_SPOTIFY_PATH] = self.spotify_path_entry.get_text()
self.export_config.save()
export_args = [
"bash",
OOMOXIFY_SCRIPT_PATH,
self.temp_theme_path,
"--gui",
"--spotify-apps-path", self.export_config[OPTION_SPOTIFY_PATH],
]
if self.export_config[OPTION_FONT_OPTIONS] == VALUE_FONT_NORMALIZE:
export_args.append("--font-weight")
elif self.export_config[OPTION_FONT_OPTIONS] == VALUE_FONT_CUSTOM:
export_args.extend(("--font", self.export_config[OPTION_FONT_NAME]))
self.command = export_args
super().do_export()
def on_font_radio_toggled(self, button: Gtk.Button, value: bool) -> None: # noqa: FBT001
if button.get_active():
self.export_config[OPTION_FONT_OPTIONS] = value
self.font_name_entry.set_sensitive(value == VALUE_FONT_CUSTOM)
def _init_radios(self) -> None:
self.font_radio_default = \
Gtk.RadioButton.new_with_mnemonic_from_widget(
None,
translate("Don't change _default font"),
)
self.font_radio_default.connect(
"toggled", self.on_font_radio_toggled, VALUE_FONT_DEFAULT,
)
self.options_box.add(self.font_radio_default)
self.font_radio_normalize = \
Gtk.RadioButton.new_with_mnemonic_from_widget(
self.font_radio_default,
translate("_Normalize font weight"),
)
self.font_radio_normalize.connect(
"toggled", self.on_font_radio_toggled, VALUE_FONT_NORMALIZE,
)
self.options_box.add(self.font_radio_normalize)
self.font_radio_custom = Gtk.RadioButton.new_with_mnemonic_from_widget(
self.font_radio_default,
translate("Use custom _font:"),
)
self.font_radio_custom.connect(
"toggled", self.on_font_radio_toggled, VALUE_FONT_CUSTOM,
)
self.options_box.add(self.font_radio_custom)
self.font_name_entry = Gtk.Entry(text=self.export_config[OPTION_FONT_NAME])
self.options_box.add(self.font_name_entry)
self.font_name_entry.set_sensitive(
self.export_config[OPTION_FONT_OPTIONS] == VALUE_FONT_CUSTOM,
)
if self.export_config[OPTION_FONT_OPTIONS] == VALUE_FONT_NORMALIZE:
self.font_radio_normalize.set_active(True)
if self.export_config[OPTION_FONT_OPTIONS] == VALUE_FONT_CUSTOM:
self.font_radio_custom.set_active(True)
def __init__(
self,
transient_for: Gtk.Window,
colorscheme: "ThemeT",
theme_name: str,
**kwargs: "Any",
) -> None:
super().__init__(
transient_for=transient_for,
headline=translate("Spotify Options"),
colorscheme=colorscheme,
theme_name=theme_name,
**kwargs,
)
self.label.hide()
self.export_config = ExportConfig(
config_name="spotify",
default_config={
OPTION_SPOTIFY_PATH: "/usr/share/spotify/Apps",
OPTION_FONT_NAME: "sans-serif",
OPTION_FONT_OPTIONS: VALUE_FONT_DEFAULT,
},
)
export_options_headline = Gtk.Label()
export_options_headline.set_markup("<b>" + translate("Font Options") + "</b>")
export_options_headline.set_justify(Gtk.Justification.LEFT)
export_options_headline.set_alignment(0.0, 0.0)
self.options_box.add(export_options_headline)
self._init_radios()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
spotify_path_label = Gtk.Label(label=translate("Spotify _path:"),
use_underline=True)
self.spotify_path_entry = Gtk.Entry(text=self.export_config[OPTION_SPOTIFY_PATH])
spotify_path_label.set_mnemonic_widget(self.spotify_path_entry)
hbox.add(spotify_path_label)
hbox.add(self.spotify_path_entry)
self.options_box.add(hbox)
self.box.add(self.options_box)
self.options_box.show_all()
self.box.add(self.apply_button)
self.apply_button.show()
class Plugin(OomoxExportPlugin):
name = "spotify"
display_name = "Oomoxify"
export_text = translate("Apply Spotif_y Theme…")
about_text = translate("Apply the current theme to Spotify Desktop app.")
about_links = [
{
"name": translate("Homepage"),
"url": "https://github.com/themix-project/oomoxify/",
},
]
export_dialog = SpotifyExportDialog
theme_model_extra = [
{
"type": "separator",
"display_name": translate("Spotify"),
},
{
"key": "SPOTIFY_PROTO_BG",
"type": "color",
"fallback_key": "HDR_BG",
"display_name": translate("Background"),
},
{
"key": "SPOTIFY_PROTO_FG",
"type": "color",
"fallback_key": "HDR_FG",
"display_name": translate("Foreground"),
},
{
"key": "SPOTIFY_PROTO_SEL",
"type": "color",
"fallback_key": "SEL_BG",
"display_name": translate("Accent Color"),
},
]