diff options
author | Usmar A Padow <usmpadow@yahoo.com> | 2010-10-16 12:31:24 +1300 |
---|---|---|
committer | John Stowers <john.stowers@gmail.com> | 2010-10-16 12:31:24 +1300 |
commit | 56aa50322dee974298dc0dba61c8182f2495ff58 (patch) | |
tree | 86704f4f8bf65ff8867e41ca3fbf33ab09cb41d9 /examples | |
parent | db1ac530d6596c46c9cdaafbc2beb92697563abe (diff) | |
download | pygtk-56aa50322dee974298dc0dba61c8182f2495ff58.tar.gz |
Add updated gtk.Toolbar example, bug 597784
Diffstat (limited to 'examples')
-rw-r--r-- | 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 00000000..bc678d13 --- /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() + |