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

  1. #!/usr/bin/env python
  2. """Dialog and Message Boxes
  3.  
  4. Dialog widgets are used to pop up a transient window for user feedback."""
  5.  
  6. import gtk
  7.  
  8. class DialogAndMessageBoxesDemo(gtk.Window):
  9.     counter = 1
  10.     def __init__(self, parent=None):
  11.         # Create the toplevel window
  12.         gtk.Window.__init__(self)
  13.         try:
  14.             self.set_screen(parent.get_screen())
  15.         except AttributeError:
  16.             self.connect('destroy', lambda *w: gtk.main_quit())
  17.  
  18.         self.set_title(self.__class__.__name__)
  19.         self.set_border_width(8)
  20.  
  21.         frame = gtk.Frame("Dialogs")
  22.         self.add(frame)
  23.  
  24.         vbox = gtk.VBox(False, 8)
  25.         vbox.set_border_width(8)
  26.         frame.add(vbox)
  27.  
  28.         # Standard message dialog
  29.         hbox = gtk.HBox(False, 8)
  30.         vbox.pack_start(hbox)
  31.         button = gtk.Button("_Message Dialog")
  32.         button.connect('clicked', self.on_message_dialog_clicked)
  33.         hbox.pack_start(button, False, False, 0)
  34.         vbox.pack_start(gtk.HSeparator(), False, False, 0)
  35.  
  36.         # Interactive dialog
  37.         hbox = gtk.HBox(False, 8)
  38.         vbox.pack_start(hbox, False, False, 0)
  39.         vbox2 = gtk.VBox()
  40.  
  41.         button = gtk.Button("_Interactive Dialog")
  42.         button.connect('clicked', self.on_interactive_dialog_clicked)
  43.         hbox.pack_start(vbox2, False, False, 0)
  44.         vbox2.pack_start(button, False, False, 0)
  45.  
  46.         table = gtk.Table(2, 2)
  47.         table.set_row_spacings(4)
  48.         table.set_col_spacings(4)
  49.         hbox.pack_start(table, False, False, 0)
  50.  
  51.         label = gtk.Label("Entry _1")
  52.         label.set_use_underline(True)
  53.         table.attach(label, 0, 1, 0, 1)
  54.  
  55.         self.entry1 = gtk.Entry()
  56.         table.attach(self.entry1, 1, 2, 0, 1)
  57.         label.set_mnemonic_widget(self.entry1)
  58.  
  59.         label = gtk.Label("Entry _2")
  60.         label.set_use_underline(True)
  61.         table.attach(label, 0, 1, 1, 2)
  62.  
  63.         self.entry2 = gtk.Entry()
  64.         table.attach(self.entry2, 1, 2, 1, 2)
  65.         label.set_mnemonic_widget(self.entry2)
  66.  
  67.         self.show_all()
  68.  
  69.     def on_message_dialog_clicked(self, button):
  70.         dialog = gtk.MessageDialog(self,
  71.                 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
  72.                 gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
  73.                 "This message box has been popped up %d time%s." %
  74.                         (self.counter, self.counter > 1 and 's' or ''))
  75.         dialog.run()
  76.         dialog.destroy()
  77.         self.counter += 1
  78.  
  79.     def on_interactive_dialog_clicked(self, button):
  80.  
  81.         dialog = gtk.Dialog("Interactive Dialog", self, 0,
  82.                 (gtk.STOCK_OK, gtk.RESPONSE_OK,
  83.                 "_Non-stock button", gtk.RESPONSE_CANCEL))
  84.  
  85.         hbox = gtk.HBox(False, 8)
  86.         hbox.set_border_width(8)
  87.         dialog.vbox.pack_start(hbox, False, False, 0)
  88.  
  89.         stock = gtk.image_new_from_stock(
  90.                 gtk.STOCK_DIALOG_QUESTION,
  91.                 gtk.ICON_SIZE_DIALOG)
  92.         hbox.pack_start(stock, False, False, 0)
  93.  
  94.         table = gtk.Table(2, 2)
  95.         table.set_row_spacings(4)
  96.         table.set_col_spacings(4)
  97.         hbox.pack_start(table, True, True, 0)
  98.  
  99.         label = gtk.Label("Entry _1")
  100.         label.set_use_underline(True)
  101.         table.attach(label, 0, 1, 0, 1)
  102.         local_entry1 = gtk.Entry()
  103.         local_entry1.set_text(self.entry1.get_text())
  104.         table.attach(local_entry1, 1, 2, 0, 1)
  105.         label.set_mnemonic_widget(local_entry1)
  106.  
  107.         label = gtk.Label("Entry _2")
  108.         label.set_use_underline(True)
  109.         table.attach(label, 0, 1, 1, 2)
  110.         local_entry2 = gtk.Entry()
  111.         local_entry2.set_text(self.entry2.get_text())
  112.         table.attach(local_entry2, 1, 2, 1, 2)
  113.         label.set_mnemonic_widget(local_entry2)
  114.  
  115.         dialog.show_all()
  116.  
  117.         response = dialog.run()
  118.  
  119.         if response == gtk.RESPONSE_OK:
  120.             self.entry1.set_text(local_entry1.get_text())
  121.             self.entry2.set_text(local_entry2.get_text())
  122.  
  123.         dialog.destroy()
  124.  
  125. def main():
  126.     DialogAndMessageBoxesDemo()
  127.     gtk.main()
  128.  
  129. if __name__ == '__main__':
  130.     main()
  131.