Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/01/2012, 08:23
nixonmolina18
 
Fecha de Ingreso: noviembre-2011
Mensajes: 12
Antigüedad: 12 años, 5 meses
Puntos: 0
Problemas con las ventanas en gtk

Saludos amigos, hoy tengo el siguiente problema: Al momento de cerrar una ventana aparece un mensaje preguntando si desea salir de la interfaz, si da clic en SI se cancelan los procesos y si da clic en NO debería poder continuar en la interfaz, el problema es que si doy clic en NO se sale de igual forma. Estoy usando el "delete-event" para conectar el mensaje, probé con otros y este es el que mejor me funciona. Aquí mi código de prueba...
Código Python:
Ver original
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import gtk
  5. from subprocess import Popen, PIPE, STDOUT
  6.  
  7. def make_box(homogeneous, spacing, expand, fill, padding):
  8.    
  9.    caja = gtk.HBox(homogeneous, spacing)
  10.    caja.set_border_width(10)
  11.    
  12.    etiqueta = gtk.Label("Nombre")
  13.    caja.pack_start(etiqueta, False, False, 0)
  14.    etiqueta.show()
  15.    
  16.    texto1 = gtk.Entry(10)
  17.    caja.pack_start(texto1, False, False, 16)
  18.    texto1.show()
  19.  
  20.    return caja
  21.  
  22.  
  23. class PackBox1:
  24.    
  25.    def delete_event(self, widget, event, data=None):
  26.        gtk.main_quit()
  27.        return False
  28.        
  29.    def __init__(self):
  30.        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  31.        self.window.connect("delete_event", close)
  32.        self.window.set_border_width(10)
  33.            
  34.        box1 = gtk.VBox(False, 0)
  35.        
  36.        box2 = make_box(False, 0, False, False, 0)
  37.        box1.pack_start(box2, False, False, 0)
  38.        box2.show()
  39.        
  40.        button_box = gtk.HButtonBox()
  41.        button_box.set_layout(gtk.BUTTONBOX_SPREAD)
  42.        
  43.        aceptar = gtk.Button(stock=gtk.STOCK_OK)
  44.        button_box.pack_start(aceptar, False, False)
  45.        box1.pack_start(button_box, False, False, 0)
  46.        aceptar.show()
  47.        button_box.show()
  48.        
  49.        button = gtk.Button("Salir")
  50.        button.connect("clicked", close)
  51.        button_box.pack_start(button, True, False, 0)
  52.        box1.pack_start(button_box, True, False, 0)
  53.        
  54.        self.window.add(box1)
  55.        
  56.        button.show()
  57.        button_box.show()
  58.        
  59.        box1.show()
  60.        self.window.show()
  61.        
  62.  
  63. def close(self, widget=None):
  64.     md=gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format="Al cerrar, todos los procedimientos que ha realizado serán eliminados.\n ¿Desea salir de la aplicación?")
  65.     md.set_title('Cerrar')
  66.     respuesta = md.run()
  67.     md.destroy()
  68.        
  69.     if respuesta == gtk.RESPONSE_YES:
  70.         x2= Popen(["pkill lb"], shell=True, stdout=PIPE)
  71.         x3= Popen(["pkill live-build"], shell=True, stdout=PIPE)
  72.         self.destroy()
  73.         gtk.main_quit()
  74.        
  75.          
  76. def main():
  77.     gtk.main()
  78.     return 0
  79.  
  80. if __name__ =="__main__":
  81.     packbox1 = PackBox1()
  82.     main()