-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.py
278 lines (224 loc) · 9.27 KB
/
window.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/env python
#
# Lara Maia <dev@lara.click> 2019
#
# The RGBFanControl is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# The RGBFanControl is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
from time import sleep
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio
from collections import OrderedDict
import utils
import config
auto_effect_dict = OrderedDict([
("00", "Disabled"),
("01", "Color Cycle"),
("10", "Color Pulse"),
("02", "Color Cycle Pulse"),
("03", "Red"),
("04", "Green"),
("05", "Blue"),
("06", "Purple"),
("07", "Cyan"),
("08", "Yellow"),
("09", "White"),
])
primary_effects_dict = OrderedDict([
("000", "Disabled"),
("050", "Solid Color"),
("051", "Solid Color Rotating"),
("100", "Two Colors"),
("101", "Two Colors Gradient"),
("102", "Two Colors Up-Down"),
("103", "Two Colors Up-Down Oposite"),
("200", "Rainbow"),
("201", "Rainbow Rotating"),
])
secondary_effects_dict = OrderedDict([
("000", "Disabled"),
("001", "Fade"),
("002", "Pulse"),
])
extra_effects_dict = OrderedDict([
("000", "Disabled"),
("104", "Two Colors Random"),
("500", "Party"),
("501", "Police"),
("502", "RGB Cycle"),
])
extra_effect_block_list = ["050", "100", "101", "200", "201"]
color_effect_block_list = ["200", "201", "500", "501", "502"]
primary_color_effect_block_list = [] + color_effect_block_list
secondary_color_effect_block_list = ["050", "051"] + color_effect_block_list
class Main(Gtk.ApplicationWindow):
def __init__(self, *, application: Gtk.Application, title: str) -> None:
super().__init__(application=application, title=title)
self.application = application
header_bar = Gtk.HeaderBar()
header_bar.set_show_close_button(True)
# icon_image = GdkPixbuf.Pixbuf.new_from_file_at_size(<image_path>, 28, 28)
# icon = Gtk.Image()
# icon.set_from_pixbuf(icon_image)
# header_bar.pack_start(icon)
menu = Gio.Menu()
menu.append("About", "app.about")
menu.append("Exit", "app.exit")
menu_button = Gtk.MenuButton()
# menu_button.set_relief(Gtk.ReliefStyle.NONE)
menu_button.set_menu_model(menu)
header_bar.pack_end(menu_button)
self.set_titlebar(header_bar)
# self.set_default_size(650, 450)
self.set_resizable(False)
self.set_position(Gtk.WindowPosition.CENTER)
self.set_title(title)
main_grid = Gtk.Grid()
main_grid.set_border_width(10)
main_grid.set_row_spacing(10)
main_grid.set_column_spacing(10)
main_grid.set_column_homogeneous(True)
self.add(main_grid)
auto_effect_section = utils.Section("auto_effect", "Auto Effect")
main_grid.attach(auto_effect_section, 1, 0, 1, 1)
self.auto_effect = auto_effect_section.new(
"effect",
"Effect",
Gtk.ComboBoxText,
0, 0,
items=auto_effect_dict
)
self.auto_effect.connect("changed", self.on_auto_effect_changed)
self.auto_effect.load()
effects_section = utils.Section("effects", "Effects")
main_grid.attach(effects_section, 0, 0, 1, 2)
self.primary_color = effects_section.new("primary_color", "Primary Color", Gtk.ColorButton, 0, 3)
self.primary_color.connect("notify::color", self.on_color_changed)
self.primary_color.load()
self.secondary_color = effects_section.new("secondary_color", "Secondary Color", Gtk.ColorButton, 0, 4)
self.secondary_color.connect("notify::color", self.on_color_changed)
self.secondary_color.load()
self.primary_effect = effects_section.new(
"primary_effect",
"Primary Effect",
Gtk.ComboBoxText,
0, 0,
items=primary_effects_dict
)
self.secondary_effect = effects_section.new(
"secondary_effect",
"Secondary Effect",
Gtk.ComboBoxText,
0, 1,
items=secondary_effects_dict
)
self.extra_effect = effects_section.new(
"extra_effect",
"Extra Effect",
Gtk.ComboBoxText,
0, 2,
items=extra_effects_dict
)
self.primary_effect.connect("changed", self.on_effects_changed)
self.secondary_effect.connect("changed", self.on_effects_changed)
self.extra_effect.connect("changed", self.on_effects_changed)
self.primary_effect.load()
self.secondary_effect.load()
self.extra_effect.load()
advanced_section = utils.Section("advanced", "Advanced")
main_grid.attach(advanced_section, 1, 1, 1, 1)
speed = advanced_section.new("speed", "Speed", Gtk.Scale, 0, 0)
speed.connect('change-value', self.on_scale_changed)
speed.load()
brightness = advanced_section.new("brightness", "Brightness", Gtk.Scale, 0, 1)
brightness.connect('change-value', self.on_scale_changed)
brightness.load()
reset = Gtk.Button("Reset Arduino")
reset.connect('clicked', self.on_reset_clicked)
main_grid.attach(reset, 0, 2, 1, 1)
save = Gtk.Button("EEPROM Save")
save.connect('clicked', self.on_save_clicked)
main_grid.attach(save, 1, 2, 1, 1)
self.connect("destroy", self.application.on_exit_activate, None)
self.show_all()
def on_scale_changed(self, scale: Gtk.Scale, type_=str, value=str) -> None:
name = scale.get_name()
if int(value) > 255:
value = "255"
elif int(value) < 0:
value = "0"
else:
value = str(int(value))
config.new("advanced", name, value)
serial_message = 'l{}{:0=3d}'.format(name[0:1], int(value))
self.application.send_serial(serial_message)
def on_auto_effect_changed(self, combo: Gtk.ComboBoxText) -> None:
name = combo.get_name()
effect = list(auto_effect_dict)[combo.get_active()]
config.new('auto_effect', name, effect)
serial_message = 'la'
serial_message += config.parser.get("auto_effect", name)
self.application.send_serial(serial_message)
sleep(1.5)
def on_effects_changed(self, combo: Gtk.ComboBoxText) -> None:
self.primary_effect.set_sensitive(True)
self.secondary_effect.set_sensitive(True)
self.primary_color.set_sensitive(True)
self.secondary_color.set_sensitive(True)
name = combo.get_name()
if name == "primary_effect":
effect = list(primary_effects_dict)[combo.get_active()]
if effect in extra_effect_block_list:
self.extra_effect.set_active(0)
self.extra_effect.set_sensitive(False)
else:
self.extra_effect.set_sensitive(True)
elif name == "secondary_effect":
effect = list(secondary_effects_dict)[combo.get_active()]
else:
effect = list(extra_effects_dict)[combo.get_active()]
if self.primary_effect.get_active() == 0:
self.secondary_effect.set_active(0)
self.secondary_effect.set_sensitive(False)
if self.extra_effect.get_active() == 0 or self.primary_effect.get_active() == 0:
current_effect_list = [
list(primary_effects_dict)[self.primary_effect.get_active()],
list(extra_effects_dict)[self.extra_effect.get_active()],
]
if any((effect in primary_color_effect_block_list) for effect in current_effect_list):
self.primary_color.set_sensitive(False)
if any((effect in secondary_color_effect_block_list) for effect in current_effect_list):
self.secondary_color.set_sensitive(False)
config.new('effects', name, effect)
serial_message = 'le'
serial_message += config.parser.get("effects", "extra_effect")
serial_message += config.parser.get("effects", "secondary_effect")
serial_message += config.parser.get("effects", "primary_effect")
self.application.send_serial(serial_message)
def on_color_changed(self, color_button: Gtk.ColorButton, param: str) -> None:
name = color_button.get_name()
color_string = utils.rgba_to_led_color(color_button.get_rgba())
config.new("effects", name, color_string)
if name == "primary_color":
serial_message = "lc"
else:
serial_message = "ls"
serial_message += color_string
self.application.send_serial(serial_message)
def on_reset_clicked(self, button: Gtk.Button) -> None:
self.application.do_reset()
def on_save_clicked(self, button: Gtk.Button) -> None:
serial_message = 'ms'
self.application.send_serial(serial_message)
button.set_label("Saved!")