-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetting_dialog.py
107 lines (74 loc) · 3.18 KB
/
setting_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import gi
gi.require_version('Gtk','3.0')
from gi.repository import Gtk
class SettingDialog(Gtk.Dialog):
def __init__(self,parent,currentIp,currentTransitionType,currentTransitionTime):
Gtk.Dialog.__init__(self,"Settings",
parent,
0)
#Setup GUI
self.createWidget()
self.createButtons()
#Fill informations
self.ipEntery.set_text(currentIp)
if(currentTransitionType == "sudden"):
self.transitionTypeCombo.set_active(0)
else:
self.transitionTypeCombo.set_active(1)
self.transitionTimeSpin.set_value(currentTransitionTime)
self.show_all()
def createWidget(self):
# Main box
self.contentArea = self.get_content_area()
self.mainBox = Gtk.Box(orientation=Gtk.STYLE_CLASS_VERTICAL,spacing=2)
self.contentArea.add(self.mainBox)
# IP Box
self.ipBox = Gtk.Box(orientation=Gtk.STYLE_CLASS_HORIZONTAL,spacing = 2)
self.mainBox.add(self.ipBox)
self.ipLabel = Gtk.Label("Bulb IP address :")
self.ipBox.pack_start(self.ipLabel,False,True,0)
self.ipEntery = Gtk.Entry()
self.ipBox.pack_start(self.ipEntery,True,True,0)
#Transition Type Box
self.transitionTypeBox = Gtk.Box(orientation=Gtk.STYLE_CLASS_HORIZONTAL,spacing = 2)
self.mainBox.add(self.transitionTypeBox)
self.transitionTypeLabel = Gtk.Label("Transition type : ")
self.transitionTypeBox.pack_start(self.transitionTypeLabel,False,True,0)
transitionTypes = [["Sudden"],["Smooth"]]
transitionsModel = Gtk.ListStore(str)
for i in range(0,len(transitionTypes)):
transitionsModel.append(transitionTypes[i])
self.transitionTypeCombo = Gtk.ComboBox(model=transitionsModel)
cell = Gtk.CellRendererText()
self.transitionTypeCombo.connect("changed",self.onTransitionTypeChanged)
self.transitionTypeCombo.pack_start(cell,False)
self.transitionTypeCombo.add_attribute(cell,"text",0)
self.transitionTypeBox.pack_start(self.transitionTypeCombo,True,True,0)
#Transition Time Box
self.transitionTimeBox = Gtk.Box(orientation=Gtk.STYLE_CLASS_HORIZONTAL,spacing=2)
self.mainBox.add(self.transitionTimeBox)
self.transitionTimeLabel = Gtk.Label("Transition time : ")
self.transitionTimeBox.pack_start(self.transitionTimeLabel,False,True,0)
self.spinAdjustment = Gtk.Adjustment(value = 500,lower=30,upper=10000,step_increment=100,page_increment=0,page_size=0)
self.transitionTimeSpin = Gtk.SpinButton(adjustment=self.spinAdjustment,climb_rate=100,digits=0)
self.transitionTimeBox.pack_start(self.transitionTimeSpin,True,True,0)
# Seperator
self.seperator = Gtk.Separator(orientation=Gtk.STYLE_CLASS_HORIZONTAL)
self.mainBox.add(self.seperator)
def createButtons(self):
#Cancel button
self.add_buttons(Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL)
#Ok button
self.add_buttons(Gtk.STOCK_OK,Gtk.ResponseType.OK)
def onTransitionTypeChanged(self,widget):
#If the selected transition type is sudden
if(self.transitionTypeCombo.get_active() == 0):
self.transitionTimeSpin.set_sensitive(False)
else:
self.transitionTimeSpin.set_sensitive(True)
def getIp(self):
return self.ipEntery.get_text()
def getTransitionType(self):
return self.transitionTypeCombo.get_active()
def getTransitionTime(self):
return int(self.transitionTimeSpin.get_value())