Fri, 09 Dec 2011 22:15:50 +0100
pitlane response enter/exit pitlane, led lit when car is in pitlane
23 | 1 | #!/usr/bin/env python |
2 | ||
3 | import pygtk | |
4 | pygtk.require('2.0') | |
5 | import gtk | |
6 | ||
24
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
7 | class Window: |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
8 | """ |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
9 | Base Window Class |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
10 | """ |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
11 | def delete_event(self, widget, event, data=None): |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
12 | return False |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
13 | |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
14 | def __init__(self, title="unnamed window"): |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
15 | self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
16 | self.window.connect("delete_event", self.delete_event) |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
17 | self.window.set_title(title) |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
18 | |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
19 | class SlotCars(Window): |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
20 | """ |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
21 | Car configuration window |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
22 | """ |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
23 | def __init__(self): |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
24 | Window.__init__(self, "Car configuration") |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
25 | #self.slot = gtk.ComboBox("Select car") |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
26 | #self.slot.show() |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
27 | #window.add(self.slot) |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
28 | |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
29 | class SlotUi(Window): |
23 | 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) | |
24
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
37 | Window.delete_event(self, widget, event, data) |
23 | 38 | return False |
39 | ||
40 | def destroy(self, widget, data=None): | |
41 | gtk.main_quit() | |
42 | ||
43 | def __init__(self): | |
24
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
44 | Window.__init__(self, "FreeSlot UI") |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
45 | |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
46 | # define toolbar buttons |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
47 | self.buttons = { |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
48 | "config": gtk.Button("Settings"), |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
49 | "cars": gtk.Button("Car Config"), |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
50 | } |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
51 | self.buttons["config"].connect("clicked", self.openwindow, "config") |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
52 | self.buttons["cars"].connect("clicked", self.openwindow, "cars") |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
53 | #setup the toolbar box |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
54 | self.toolbar = gtk.HBox(False, 0) |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
55 | self.toolbar.show() |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
56 | for btn in self.buttons: |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
57 | self.toolbar.add(self.buttons[btn]) |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
58 | self.buttons[btn].show() |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
59 | |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
60 | # create subwindow objects |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
61 | self.cars = SlotCars() |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
62 | self.windows = { |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
63 | "config": None, |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
64 | "cars": self.cars.window, |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
65 | } |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
66 | |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
67 | self.window.add(self.toolbar) |
23 | 68 | self.window.show() |
69 | ||
24
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
70 | def openwindow(self, widget, name): |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
71 | self.windows[name].show() |
23 | 72 | |
73 | def main(self): | |
74 | gtk.main() | |
75 | ||
76 | if __name__ == "__main__": | |
24
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
77 | print "FreeSlot UI starting..." |
84f6f0592555
basic example gtk ui to be coded later
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
78 | print "Note: this will be part of paepke development, no function at the moment :)" |
23 | 79 | app = SlotUi() |
80 | app.main() |