slotUI/SlotUi.py

changeset 24
84f6f0592555
parent 23
6edcf4666e3b
equal deleted inserted replaced
23:6edcf4666e3b 24:84f6f0592555
2 2
3 import pygtk 3 import pygtk
4 pygtk.require('2.0') 4 pygtk.require('2.0')
5 import gtk 5 import gtk
6 6
7 class SlotUi: 7 class Window:
8 """
9 Base Window Class
10 """
11 def delete_event(self, widget, event, data=None):
12 return False
13
14 def __init__(self, title="unnamed window"):
15 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
16 self.window.connect("delete_event", self.delete_event)
17 self.window.set_title(title)
18
19 class SlotCars(Window):
20 """
21 Car configuration window
22 """
23 def __init__(self):
24 Window.__init__(self, "Car configuration")
25 #self.slot = gtk.ComboBox("Select car")
26 #self.slot.show()
27 #window.add(self.slot)
28
29 class SlotUi(Window):
8 """ 30 """
9 Graphical User Interface 31 Graphical User Interface
10 using GTK 32 using GTK
11 """ 33 """
12 def delete_event(self, widget, event, data=None): 34 def delete_event(self, widget, event, data=None):
13 if widget == self.window: 35 if widget == self.window:
14 self.destroy(widget, data) 36 self.destroy(widget, data)
15 #return true to stop window destruction 37 Window.delete_event(self, widget, event, data)
16 return False 38 return False
17 39
18 def destroy(self, widget, data=None): 40 def destroy(self, widget, data=None):
19 gtk.main_quit() 41 gtk.main_quit()
20 42
21 def __init__(self): 43 def __init__(self):
22 # create main window 44 Window.__init__(self, "FreeSlot UI")
23 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) 45
24 self.window.connect("delete_event", self.delete_event) 46 # define toolbar buttons
25 self.button = gtk.Button("Hello World") 47 self.buttons = {
26 self.button.connect("clicked", self.hello, None) 48 "config": gtk.Button("Settings"),
27 49 "cars": gtk.Button("Car Config"),
28 self.window.add(self.button) 50 }
29 self.button.show() 51 self.buttons["config"].connect("clicked", self.openwindow, "config")
52 self.buttons["cars"].connect("clicked", self.openwindow, "cars")
53 #setup the toolbar box
54 self.toolbar = gtk.HBox(False, 0)
55 self.toolbar.show()
56 for btn in self.buttons:
57 self.toolbar.add(self.buttons[btn])
58 self.buttons[btn].show()
59
60 # create subwindow objects
61 self.cars = SlotCars()
62 self.windows = {
63 "config": None,
64 "cars": self.cars.window,
65 }
66
67 self.window.add(self.toolbar)
30 self.window.show() 68 self.window.show()
31 69
32 def hello(self, widget, param1): 70 def openwindow(self, widget, name):
33 print widget 71 self.windows[name].show()
34 print "hello"
35 72
36 def main(self): 73 def main(self):
37 gtk.main() 74 gtk.main()
38 75
39 if __name__ == "__main__": 76 if __name__ == "__main__":
77 print "FreeSlot UI starting..."
78 print "Note: this will be part of paepke development, no function at the moment :)"
40 app = SlotUi() 79 app = SlotUi()
41 app.main() 80 app.main()

mercurial