[pygobject] [gtk-demo] make GtkDemoApp a Gtk.Window subclass and adapt main() to demonstrate the GLib.MainLoop



commit 58797c355a08a35375988881a17958bb42ad54bb
Author: Dieter Verfaillie <dieterv optionexplicit be>
Date:   Fri Aug 19 14:40:00 2011 +0200

    [gtk-demo] make GtkDemoApp a Gtk.Window subclass and adapt main() to demonstrate the GLib.MainLoop

 demos/gtk-demo/gtk-demo.py |   43 ++++++++++++++++++++++++++-----------------
 1 files changed, 26 insertions(+), 17 deletions(-)
---
diff --git a/demos/gtk-demo/gtk-demo.py b/demos/gtk-demo/gtk-demo.py
index 1a030e2..f65d0e4 100755
--- a/demos/gtk-demo/gtk-demo.py
+++ b/demos/gtk-demo/gtk-demo.py
@@ -48,25 +48,22 @@ class Demo(GObject.GObject):
         else:
             self.isdir = False
 
-class GtkDemoApp(object):
-    def _quit(self, *args):
-        Gtk.main_quit()
 
-    def __init__(self):
-        super(GtkDemoApp, self).__init__()
+class GtkDemoWindow(Gtk.Window):
+    __gtype_name__ = 'GtkDemoWindow'
 
-        self._demos = []
-        self.load_demos()
+    def __init__(self):
+        super(GtkDemoWindow, self).__init__(type=Gtk.WindowType.TOPLEVEL)
 
+        self.set_title('PyGI GTK+ Code Demos')
+        self.set_default_size (600, 400)
         self.setup_default_icon()
 
-        window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
-        window.set_title('PyGI GTK+ Code Demos')
-
-        window.connect_after('destroy', self._quit)
+        self._demos = []
+        self.load_demos()
 
-        hbox = Gtk.HBox(homogeneous = False, spacing = 0)
-        window.add(hbox)
+        hbox = Gtk.HBox(homogeneous=False, spacing=0)
+        self.add(hbox)
 
         tree = self.create_tree()
         hbox.pack_start(tree, False, False, 0)
@@ -98,12 +95,10 @@ class GtkDemoApp(object):
                                         foreground = 'DarkGoldenrod4')
 
         self.source_buffer = source_buffer
-        window.set_default_size (600, 400)
-        window.show_all()
+        self.show_all()
 
         self.selection_cb(self.tree_view.get_selection(),
                           self.tree_view.get_model())
-        Gtk.main()
 
     def load_demos_from_list(self, file_list, demo_list):
         for fullpath in file_list:
@@ -307,5 +302,19 @@ class GtkDemoApp(object):
 
         return(scrolled_window, buffer)
 
+
+def main():
+    mainloop = GLib.MainLoop()
+
+    demowindow = GtkDemoWindow()
+    demowindow.connect('delete-event', quit, mainloop)
+    demowindow.show()
+
+    mainloop.run()
+
+def quit(widget, event, mainloop):
+    mainloop.quit()
+
+
 if __name__ == '__main__':
-    demo = GtkDemoApp()
+    main()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]