|
1 #!/usr/bin/env python |
|
2 |
|
3 import pygtk |
|
4 pygtk.require('2.0') |
|
5 import gtk |
|
6 |
|
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): |
|
30 """ |
|
31 Graphical User Interface |
|
32 using GTK |
|
33 """ |
|
34 def delete_event(self, widget, event, data=None): |
|
35 if widget == self.window: |
|
36 self.destroy(widget, data) |
|
37 Window.delete_event(self, widget, event, data) |
|
38 return False |
|
39 |
|
40 def destroy(self, widget, data=None): |
|
41 gtk.main_quit() |
|
42 |
|
43 def __init__(self): |
|
44 Window.__init__(self, "FreeSlot UI") |
|
45 |
|
46 # define toolbar buttons |
|
47 self.buttons = { |
|
48 "config": gtk.Button("Settings"), |
|
49 "cars": gtk.Button("Car Config"), |
|
50 } |
|
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) |
|
68 self.window.show() |
|
69 |
|
70 def openwindow(self, widget, name): |
|
71 self.windows[name].show() |
|
72 |
|
73 def main(self): |
|
74 gtk.main() |
|
75 |
|
76 if __name__ == "__main__": |
|
77 print "FreeSlot UI starting..." |
|
78 print "Note: this will be part of paepke development, no function at the moment :)" |
|
79 app = SlotUi() |
|
80 app.main() |