[pygtk] Add updated gtk.Toolbar example, bug 597784



commit 56aa50322dee974298dc0dba61c8182f2495ff58
Author: Usmar A Padow <usmpadow yahoo com>
Date:   Sat Oct 16 12:31:24 2010 +1300

    Add updated gtk.Toolbar example, bug 597784

 examples/gtk/toolbar.py |   55 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/examples/gtk/toolbar.py b/examples/gtk/toolbar.py
new file mode 100644
index 0000000..bc678d1
--- /dev/null
+++ b/examples/gtk/toolbar.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+# example toolbar.py by Usmar A Padow
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+
+class ToolbarExample:
+
+    def __init__(self):
+        dialog = gtk.Dialog()
+        dialog.connect("delete-event", gtk.main_quit)
+        dialog.set_size_request(450, -1)
+        dialog.set_resizable(True)
+
+        # to make it nice we'll put the toolbar into the handle box, 
+        # so that it can be detached from the main window
+        handlebox = gtk.HandleBox()
+        dialog.vbox.pack_start(handlebox, False, False, 5)
+
+        # toolbar will be horizontal, with both icons and text, and
+        # with 5pxl spaces between items and finally, 
+        # we'll also put it into our handlebox
+        toolbar = gtk.Toolbar()
+        toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL)
+        toolbar.set_style(gtk.TOOLBAR_BOTH)
+        toolbar.set_border_width(5)
+        handlebox.add(toolbar)
+
+        self.buttons=[]
+        for a in range(0,5):
+            if a == 0:
+                #first button with none group
+                widget = None
+            else:
+                #additional buttons with belong to the group of the first button
+                widget = but
+            but = gtk.RadioToolButton(group=widget, stock_id=gtk.STOCK_APPLY)
+            but.set_label("button %d" % a)
+            but.connect("clicked", self.radio_event, a)
+
+            toolbar.insert(but,a)
+            self.buttons.append(but)
+
+        dialog.show_all()
+
+    def radio_event(self, widget, btn_num):
+        if widget.get_active():
+            print "button %d toggled on" % btn_num
+
+
+if __name__ == "__main__":
+    ToolbarExample()
+    gtk.main()
+



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