home *** CD-ROM | disk | FTP | other *** search
/ tusportal.tus.k12.pa.us / tusportal.tus.k12.pa.us.tar / tusportal.tus.k12.pa.us / Wyse / latest-image.raw / 0.img / usr / lib / pygtk / 2.0 / demos / ui_manager.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2010-05-11  |  6KB  |  82 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''UI Manager
  5.  
  6. The GtkUIManager object allows the easy creation of menus
  7. from an array of actions and a description of the menu hierarchy.
  8. '''
  9. import gobject
  10. import gtk
  11.  
  12. def activate_action(action):
  13.     print 'Action "%s" activated' % action.get_name()
  14.  
  15.  
  16. def activate_radio_action(action, current):
  17.     print 'Radio action "%s" selected' % current.get_name()
  18.  
  19. entries = (('FileMenu', None, '_File'), ('PreferencesMenu', None, '_Preferences'), ('ColorMenu', None, '_Color'), ('ShapeMenu', None, '_Shape'), ('HelpMenu', None, '_Help'), ('New', gtk.STOCK_NEW, '_New', '<control>N', 'Create a new file', activate_action), ('Open', gtk.STOCK_OPEN, '_Open', '<control>O', 'Open a file', activate_action), ('Save', gtk.STOCK_SAVE, '_Save', '<control>S', 'Save current file', activate_action), ('SaveAs', gtk.STOCK_SAVE, 'Save _As...', None, 'Save to a file', activate_action), ('Quit', gtk.STOCK_QUIT, '_Quit', '<control>Q', 'Quit', activate_action), ('About', None, '_About', '<control>A', 'About', activate_action), ('Logo', 'demo-gtk-logo', None, None, 'GTK+', activate_action))
  20. toggle_entries = (('Bold', gtk.STOCK_BOLD, '_Bold', '<control>B', 'Bold', activate_action, True),)
  21. (COLOR_RED, COLOR_GREEN, COLOR_BLUE) = range(3)
  22. color_entries = (('Red', None, '_Red', '<control>R', 'Blood', COLOR_RED), ('Green', None, '_Green', '<control>G', 'Grass', COLOR_GREEN), ('Blue', None, '_Blue', '<control>B', 'Sky', COLOR_BLUE))
  23. (SHAPE_SQUARE, SHAPE_RECTANGLE, SHAPE_OVAL) = range(3)
  24. shape_entries = (('Square', None, '_Square', '<control>S', 'Square', SHAPE_SQUARE), ('Rectangle', None, '_Rectangle', '<control>R', 'Rectangle', SHAPE_RECTANGLE), ('Oval', None, '_Oval', '<control>O', 'Egg', SHAPE_OVAL))
  25. ui_info = "<ui>\n  <menubar name='MenuBar'>\n    <menu action='FileMenu'>\n      <menuitem action='New'/>\n      <menuitem action='Open'/>\n      <menuitem action='Save'/>\n      <menuitem action='SaveAs'/>\n      <separator/>\n      <menuitem action='Quit'/>\n    </menu>\n    <menu action='PreferencesMenu'>\n      <menu action='ColorMenu'>\n        <menuitem action='Red'/>\n        <menuitem action='Green'/>\n        <menuitem action='Blue'/>\n      </menu>\n      <menu action='ShapeMenu'>\n        <menuitem action='Square'/>\n        <menuitem action='Rectangle'/>\n        <menuitem action='Oval'/>\n      </menu>\n      <menuitem action='Bold'/>\n    </menu>\n    <menu action='HelpMenu'>\n      <menuitem action='About'/>\n    </menu>\n  </menubar>\n  <toolbar  name='ToolBar'>\n    <toolitem action='Open'/>\n    <toolitem action='Quit'/>\n    <separator action='Sep1'/>\n    <toolitem action='Logo'/>\n  </toolbar>\n</ui>"
  26.  
  27. class UIManagerDemo(gtk.Window):
  28.     
  29.     def __init__(self, parent = None):
  30.         gtk.Window.__init__(self)
  31.         
  32.         try:
  33.             self.set_screen(parent.get_screen())
  34.         except AttributeError:
  35.             self.connect('destroy', (lambda : gtk.main_quit()))
  36.  
  37.         self.set_title(self.__class__.__name__)
  38.         self.set_border_width(0)
  39.         actions = gtk.ActionGroup('Actions')
  40.         actions.add_actions(entries)
  41.         actions.add_toggle_actions(toggle_entries)
  42.         actions.add_radio_actions(color_entries, COLOR_RED, activate_radio_action)
  43.         actions.add_radio_actions(shape_entries, SHAPE_OVAL, activate_radio_action)
  44.         ui = gtk.UIManager()
  45.         ui.insert_action_group(actions, 0)
  46.         self.add_accel_group(ui.get_accel_group())
  47.         
  48.         try:
  49.             mergeid = ui.add_ui_from_string(ui_info)
  50.         except gobject.GError:
  51.             msg = None
  52.             print 'building menus failed: %s' % msg
  53.  
  54.         box1 = gtk.VBox(False, 0)
  55.         self.add(box1)
  56.         box1.pack_start(ui.get_widget('/MenuBar'), False, False, 0)
  57.         label = gtk.Label('Type\n<alt>\nto start')
  58.         label.set_size_request(200, 200)
  59.         label.set_alignment(0.5, 0.5)
  60.         box1.pack_start(label, True, True, 0)
  61.         separator = gtk.HSeparator()
  62.         box1.pack_start(separator, False, True, 0)
  63.         box2 = gtk.VBox(False, 10)
  64.         box2.set_border_width(10)
  65.         box1.pack_start(box2, False, True, 0)
  66.         button = gtk.Button('close')
  67.         button.connect('clicked', (lambda b, w = self: w.destroy()))
  68.         box2.pack_start(button, True, True, 0)
  69.         button.set_flags(gtk.CAN_DEFAULT)
  70.         button.grab_default()
  71.         self.show_all()
  72.  
  73.  
  74.  
  75. def main():
  76.     UIManagerDemo()
  77.     gtk.main()
  78.  
  79. if __name__ == '__main__':
  80.     main()
  81.  
  82.