basic example gtk ui to be coded later

Fri, 02 Dec 2011 22:52:10 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Fri, 02 Dec 2011 22:52:10 +0100
changeset 24
84f6f0592555
parent 23
6edcf4666e3b
child 25
646ee4dc3a6b

basic example gtk ui to be coded later

slotUI/SlotUi.py file | annotate | diff | comparison | revisions
--- a/slotUI/SlotUi.py	Fri Dec 02 20:41:36 2011 +0100
+++ b/slotUI/SlotUi.py	Fri Dec 02 22:52:10 2011 +0100
@@ -4,7 +4,29 @@
 pygtk.require('2.0')
 import gtk
 
-class SlotUi:
+class Window:
+    """
+    Base Window Class
+    """
+    def delete_event(self, widget, event, data=None):
+        return False
+
+    def __init__(self, title="unnamed window"):
+        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+        self.window.connect("delete_event", self.delete_event)
+        self.window.set_title(title)
+
+class SlotCars(Window):
+    """
+    Car configuration window
+    """
+    def __init__(self):
+        Window.__init__(self, "Car configuration")
+        #self.slot = gtk.ComboBox("Select car")
+        #self.slot.show()
+        #window.add(self.slot)
+
+class SlotUi(Window):
     """
     Graphical User Interface
     using GTK
@@ -12,30 +34,47 @@
     def delete_event(self, widget, event, data=None):
         if widget == self.window:
             self.destroy(widget, data)
-        #return true to stop window destruction
+        Window.delete_event(self, widget, event, data)
         return False
 
     def destroy(self, widget, data=None):
         gtk.main_quit()
 
     def __init__(self):
-        # create main window
-        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
-        self.window.connect("delete_event", self.delete_event)
-        self.button = gtk.Button("Hello World")
-        self.button.connect("clicked", self.hello, None)
-        
-        self.window.add(self.button)
-        self.button.show()
+        Window.__init__(self, "FreeSlot UI")
+
+        # define toolbar buttons
+        self.buttons = {
+                "config":       gtk.Button("Settings"),
+                "cars":         gtk.Button("Car Config"),
+            }
+        self.buttons["config"].connect("clicked", self.openwindow, "config")
+        self.buttons["cars"].connect("clicked", self.openwindow, "cars")
+        #setup the toolbar box
+        self.toolbar = gtk.HBox(False, 0)
+        self.toolbar.show()
+        for btn in self.buttons:
+            self.toolbar.add(self.buttons[btn])
+            self.buttons[btn].show()
+
+        # create subwindow objects
+        self.cars = SlotCars()
+        self.windows = {
+            "config": None,
+            "cars": self.cars.window,
+            }
+
+        self.window.add(self.toolbar)
         self.window.show()
 
-    def hello(self, widget, param1):
-        print widget
-        print "hello"
+    def openwindow(self, widget, name):
+        self.windows[name].show()
 
     def main(self):
         gtk.main()
 
 if __name__ == "__main__":
+    print "FreeSlot UI starting..."
+    print "Note: this will be part of paepke development, no function at the moment :)"
     app = SlotUi()
     app.main()
\ No newline at end of file

mercurial