Ver Mensaje Individual
  #3 (permalink)  
Antiguo 28/12/2010, 08:39
abcdefg
 
Fecha de Ingreso: marzo-2009
Mensajes: 79
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Consulta diálogo de confirmación

Exacto. Pero quería preguntarte porque el siguiente programa requiere la línea 34(gtk.main_quit()) para que la aplicación se cierre al responder Sí en el díalogo. ¿Si ya hemos devuelto False no tendría que llamar a destroy y cerrarse?.

Código Python:
Ver original
  1. import pygtk
  2. pygtk.require("2.0")
  3. import gtk
  4.  
  5. class UI(object):
  6.     def __init__(self):
  7.         self.label = gtk.Label("Hello world!")
  8.         self.window = self.make_window()
  9.         self.window.show_all()
  10.  
  11.     def make_window(self):
  12.         window = gtk.Window()
  13.         window.set_title("Hi!")
  14.         window.set_default_size(200, 100)
  15.  
  16.         window.connect("delete-event", self.win_close, None)
  17.  
  18.         window.add(self.label)
  19.  
  20.         return window
  21.  
  22.     def start(self):
  23.         gtk.main()
  24.  
  25.     def win_close(self, widget, event, data):
  26.         dialog = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,
  27.                                    gtk.MESSAGE_INFO, gtk.BUTTONS_YES_NO,
  28.                                    "Quit?")
  29.         dialog.set_title(":(")
  30.  
  31.         response = dialog.run()
  32.         dialog.destroy()
  33.         if response == gtk.RESPONSE_YES:
  34.             gtk.main_quit()
  35.             return False # returning False makes "destroy-event" be signalled
  36.                          # for the window.
  37.         else:
  38.             return True # returning True avoids it to signal "destroy-event"
  39.        
  40. def main():
  41.     myUI = UI()
  42.     myUI.start()
  43.  
  44.     print "Now we're outside the UI, but still in the program"
  45.  
  46. main()