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 / colorsel.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2010-05-11  |  3KB  |  67 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. '''Color Selector
  5.  
  6. GtkColorSelection lets the user choose a color. GtkColorSelectionDialog is a
  7. prebuilt dialog containing a GtkColorSelection.'''
  8. import gtk
  9.  
  10. class ColorSelectorDemo(gtk.Window):
  11.     color = gtk.gdk.color_parse('blue')
  12.     
  13.     def __init__(self, parent = None):
  14.         gtk.Window.__init__(self)
  15.         
  16.         try:
  17.             self.set_screen(parent.get_screen())
  18.         except AttributeError:
  19.             self.connect('destroy', (lambda : gtk.main_quit()))
  20.  
  21.         self.set_title(self.__class__.__name__)
  22.         self.set_border_width(8)
  23.         vbox = gtk.VBox()
  24.         vbox.set_border_width(8)
  25.         self.add(vbox)
  26.         frame = gtk.Frame()
  27.         frame.set_shadow_type(gtk.SHADOW_IN)
  28.         vbox.pack_start(frame, True, True, 8)
  29.         self.d_area = gtk.DrawingArea()
  30.         self.d_area.set_size_request(200, 200)
  31.         self.d_area.modify_bg(gtk.STATE_NORMAL, self.color)
  32.         frame.add(self.d_area)
  33.         alignment = gtk.Alignment(1, 0.5, 0, 0)
  34.         button = gtk.Button('_Change the above color')
  35.         alignment.add(button)
  36.         vbox.pack_start(alignment, True, True)
  37.         button.connect('clicked', self.on_change_color_clicked)
  38.         button.set_flags(gtk.CAN_DEFAULT)
  39.         button.grab_default()
  40.         self.show_all()
  41.  
  42.     
  43.     def on_change_color_clicked(self, button):
  44.         dialog = gtk.ColorSelectionDialog('Changing color')
  45.         dialog.set_transient_for(self)
  46.         colorsel = dialog.colorsel
  47.         colorsel.set_previous_color(self.color)
  48.         colorsel.set_current_color(self.color)
  49.         colorsel.set_has_palette(True)
  50.         response = dialog.run()
  51.         if response == gtk.RESPONSE_OK:
  52.             self.color = colorsel.get_current_color()
  53.             self.d_area.modify_bg(gtk.STATE_NORMAL, self.color)
  54.         
  55.         dialog.destroy()
  56.         return True
  57.  
  58.  
  59.  
  60. def main():
  61.     ColorSelectorDemo()
  62.     gtk.main()
  63.  
  64. if __name__ == '__main__':
  65.     main()
  66.  
  67.