-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme_dialog.py
86 lines (60 loc) · 1.82 KB
/
theme_dialog.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
import gi
import os
gi.require_version('Gtk','3.0')
from gi.repository import Gtk
from yeelight_lib import Bulb
import JSONutils as themeFile
class ThemeDialog(Gtk.Dialog):
def __init__(self,parent,bulb):
Gtk.Dialog.__init__(self,"Themes",
parent,
0)
#Get the bulb control
self.bulb = bulb
#Load themes
self.themes = themeFile.loadTheme()
#Setup GUI
self.createWidget()
self.createButtons()
self.show_all()
def createWidget(self):
#Main grid
self.contentArea = self.get_content_area()
self.mainGrid = Gtk.Grid()
self.mainGrid.set_property("row-spacing",4)
self.mainGrid.set_property("column-spacing",10)
self.contentArea.add(self.mainGrid)
#Setup grid 3xN
i = 0
j = 0
id = 0
for currentTheme in self.themes.items():
#Create template
tmpBox = Gtk.Box(orientation=Gtk.STYLE_CLASS_VERTICAL,spacing = 2)
#Load the image
tmpImage = Gtk.Image()
tmpImage.set_from_file("img/themes/"+currentTheme[1]["pic"])
tmpBox.add(tmpImage)
#Load the label
tmpButton = Gtk.Button(label=currentTheme[1]["name"])
tmpButton.connect("clicked",self.buttonPressed,currentTheme[0])
tmpBox.add(tmpButton)
#Add to the grid
self.mainGrid.attach(tmpBox,j,i,1,1)
#Continue to the next cell
j += 1
if(j == 2):
i += 1
j = 0
id += 1
# Seperator
self.seperator = Gtk.Separator(orientation=Gtk.STYLE_CLASS_HORIZONTAL)
self.contentArea.pack_start(self.seperator,False,True,4)
def createButtons(self):
#Cancel button
self.add_buttons(Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL)
def buttonPressed(self,widget,themeName):
# Set the bulb property
self.bulb.setColorInt(self.themes[themeName]["rgb"])
self.bulb.adjustBrightness(self.themes[themeName]["brightness"])
self.bulb.adjustTemperature(self.themes[themeName]["temperature"])