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 / sizegroup.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2010-05-11  |  4KB  |  97 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """Size Group
  5.  
  6. GtkSizeGroup provides a mechanism for grouping a number of widgets together so
  7. they all request the same amount of space. This is typically useful when you
  8. want a column of widgets to have the same size, but you can't use a GtkTable
  9. widget.
  10.  
  11. Note that size groups only affect the amount of space requested, not the size
  12. that the widgets finally receive. If you want the widgets in a GtkSizeGroup to
  13. actually be the same size, you need to pack them in such a way that they get
  14. the size they request and not more. For example, if you are packing your
  15. widgets into a table, you would not include the GTK_FILL flag."""
  16. import gtk
  17.  
  18. class SizeGroupDemo(gtk.Dialog):
  19.     
  20.     def __init__(self, parent = None):
  21.         gtk.Dialog.__init__(self, 'Size Groups', parent, 0, (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
  22.         
  23.         try:
  24.             self.set_screen(parent.get_screen())
  25.         except AttributeError:
  26.             self.connect('destroy', (lambda : gtk.main_quit()))
  27.  
  28.         self.connect('response', (lambda d, r: d.destroy()))
  29.         self.set_resizable(False)
  30.         vbox = gtk.VBox(False, 5)
  31.         self.vbox.pack_start(vbox, True, True, 0)
  32.         vbox.set_border_width(5)
  33.         self.size_group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
  34.         frame = gtk.Frame('Color options')
  35.         vbox.pack_start(frame, True, True, 0)
  36.         table = gtk.Table(2, 2, False)
  37.         table.set_border_width(5)
  38.         table.set_row_spacings(5)
  39.         table.set_col_spacings(10)
  40.         frame.add(table)
  41.         color_options = ('Red', 'Green', 'Blue')
  42.         self._SizeGroupDemo__add_row(table, 0, '_Foreground', color_options)
  43.         self._SizeGroupDemo__add_row(table, 1, '_Background', color_options)
  44.         frame = gtk.Frame('Line options')
  45.         vbox.pack_start(frame, False, False, 0)
  46.         table = gtk.Table(2, 2, False)
  47.         table.set_border_width(5)
  48.         table.set_row_spacings(5)
  49.         table.set_col_spacings(10)
  50.         frame.add(table)
  51.         dash_options = ('Solid', 'Dashed', 'Dotted')
  52.         end_options = ('Square', 'Round', 'Arrow')
  53.         self._SizeGroupDemo__add_row(table, 0, '_Dashing', dash_options)
  54.         self._SizeGroupDemo__add_row(table, 1, '_Line ends', end_options)
  55.         check_button = gtk.CheckButton('_Enable grouping')
  56.         vbox.pack_start(check_button, False, False, 0)
  57.         check_button.set_active(True)
  58.         check_button.connect('toggled', self.on_toggle_grouping)
  59.         self.show_all()
  60.  
  61.     
  62.     def __create_option_menu(self, options):
  63.         option_menu = gtk.combo_box_new_text()
  64.         for opt in options:
  65.             option_menu.append_text(opt)
  66.         
  67.         option_menu.set_active(0)
  68.         return option_menu
  69.  
  70.     
  71.     def __add_row(self, table, row, label_text, options):
  72.         label = gtk.Label(label_text)
  73.         label.set_use_underline(True)
  74.         label.set_alignment(0, 1)
  75.         table.attach(label, 0, 1, row, row + 1, gtk.EXPAND | gtk.FILL, 0, 0, 0)
  76.         option_menu = self._SizeGroupDemo__create_option_menu(options)
  77.         label.set_mnemonic_widget(option_menu)
  78.         self.size_group.add_widget(option_menu)
  79.         table.attach(option_menu, 1, 2, row, row + 1, 0, 0, 0, 0)
  80.  
  81.     
  82.     def on_toggle_grouping(self, check_button):
  83.         if check_button.get_active():
  84.             self.size_group.set_mode(gtk.SIZE_GROUP_HORIZONTAL)
  85.         else:
  86.             self.size_group.set_mode(gtk.SIZE_GROUP_NONE)
  87.  
  88.  
  89.  
  90. def main():
  91.     SizeGroupDemo()
  92.     gtk.main()
  93.  
  94. if __name__ == '__main__':
  95.     main()
  96.  
  97.