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 / panes.py < prev    next >
Text File  |  2010-05-11  |  4KB  |  125 lines

  1. #!/usr/bin/env python
  2. """Paned Widgets
  3.  
  4. The GtkHPaned and GtkVPaned Widgets divide their content area into two panes
  5. with a divider in between that the user can adjust. A separate child is placed
  6. into each pane.
  7. There are a number of options that can be set for each pane. This test contains
  8. both a horizontal(HPaned) and a vertical(VPaned) widget, and allows you to
  9. adjust the options for each side of each widget."""
  10.  
  11. import gtk
  12.  
  13. class PanedWidgetsDemo(gtk.Window):
  14.     def __init__(self, parent=None):
  15.         # Create the toplevel window
  16.         gtk.Window.__init__(self)
  17.         try:
  18.             self.set_screen(parent.get_screen())
  19.         except AttributeError:
  20.             self.connect('destroy', lambda *w: gtk.main_quit())
  21.  
  22.         self.set_title(self.__class__.__name__)
  23.         self.set_border_width(0)
  24.  
  25.         vbox = gtk.VBox(False, 0)
  26.         self.add(vbox)
  27.  
  28.         vpaned = gtk.VPaned()
  29.         vbox.pack_start(vpaned, True, True)
  30.         vpaned.set_border_width(5)
  31.  
  32.         hpaned = gtk.HPaned()
  33.         vpaned.add1(hpaned)
  34.  
  35.         frame = gtk.Frame()
  36.         frame.set_shadow_type(gtk.SHADOW_IN)
  37.         frame.set_size_request(60, 60)
  38.         hpaned.add1(frame)
  39.  
  40.         button = gtk.Button("_Hi there")
  41.         frame.add(button)
  42.  
  43.         frame = gtk.Frame()
  44.         frame.set_shadow_type(gtk.SHADOW_IN)
  45.         frame.set_size_request(80, 60)
  46.         hpaned.add2(frame)
  47.  
  48.         frame = gtk.Frame()
  49.         frame.set_shadow_type(gtk.SHADOW_IN)
  50.         frame.set_size_request(60, 80)
  51.         vpaned.add2(frame)
  52.  
  53.         # Now create toggle buttons to control sizing
  54.  
  55.         vbox.pack_start(
  56.             self.__create_pane_options(hpaned, "Horizontal", "Left", "Right"),
  57.             False, False, 0)
  58.  
  59.         vbox.pack_start(
  60.             self.__create_pane_options(vpaned, "Vertical", "Top", "Bottom"),
  61.             False, False, 0)
  62.  
  63.         self.show_all()
  64.  
  65.     def on_resize_toggled(self, tbutton, child):
  66.         paned = child.parent
  67.  
  68.         if child == paned.get_children()[0]:
  69.             paned.remove(child)
  70.             paned.pack1(child, tbutton.get_active(), 0)
  71.         else:
  72.             paned.remove(child)
  73.             paned.pack2(child, tbutton.get_active(), 0)
  74.  
  75.     def on_shrink_toggled(self, tbutton, child):
  76.         paned = child.parent
  77.  
  78.         if child == paned.get_children()[0]:
  79.             paned.remove(child)
  80.             paned.pack1(child, 0, tbutton.get_active())
  81.         else:
  82.             paned.remove(child)
  83.             paned.pack2(child, 0, tbutton.get_active())
  84.  
  85.     def __create_pane_options(self, paned, frame_label, label1, label2):
  86.         frame = gtk.Frame(frame_label)
  87.         frame.set_border_width(4)
  88.  
  89.         table = gtk.Table(3, 2, True)
  90.         frame.add(table)
  91.  
  92.         label = gtk.Label(label1)
  93.         table.attach(label, 0, 1, 0, 1)
  94.  
  95.         check_button = gtk.CheckButton("_Resize")
  96.         check_button.connect('toggled', self.on_resize_toggled, paned.get_children()[0])
  97.         table.attach(check_button, 0, 1, 1, 2)
  98.  
  99.         check_button = gtk.CheckButton("_Shrink")
  100.         check_button.set_active(True)
  101.         check_button.connect('toggled', self.on_shrink_toggled, paned.get_children()[0])
  102.         table.attach(check_button, 0, 1, 2, 3)
  103.  
  104.         label = gtk.Label(label2)
  105.         table.attach(label, 1, 2, 0, 1)
  106.  
  107.         check_button = gtk.CheckButton("_Resize")
  108.         check_button.set_active(True)
  109.         check_button.connect('toggled', self.on_resize_toggled, paned.get_children()[1])
  110.         table.attach(check_button, 1, 2, 1, 2)
  111.  
  112.         check_button = gtk.CheckButton("_Shrink")
  113.         check_button.set_active(True)
  114.         check_button.connect('toggled', self.on_shrink_toggled, paned.get_children()[1])
  115.         table.attach(check_button, 1, 2, 2, 3)
  116.  
  117.         return frame
  118.  
  119. def main():
  120.     PanedWidgetsDemo()
  121.     gtk.main()
  122.  
  123. if __name__ == '__main__':
  124.     main()
  125.