[pygtk] UI will be blocked if creating a message dialog by emitting a signal

Todong Ma gbstack08 at gmail.com
Thu Jul 25 22:56:02 WST 2013


Hi, everyone

I met a problem that UI will be blocked forever if I emit a signal from 
a thread to create a message dialog.
Following code will reproduce the issue, please let me give a short 
explanation: AThread thread defines a custom signal named "ASignal", and 
the signal handler is aSignal() function of MainWindow class. The 
aSignal() function is used to display a message dialog. Emitting 
"ASignal" signal will display the message dialog successfully but the UI 
is blocked forever.

    import gtk
    import gobject
    import threading

    class AThread(threading.Thread, gobject.GObject):
         __gsignals__ = {
             'ASignal': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
         }
         def __init__(self):
             threading.Thread.__init__(self)
             gobject.GObject.__init__(self)

         def run(self):
             self.emit('ASignal')

    class MainWindow(gtk.Window):
         def aSignal(self, obj):
             dialog = gtk.MessageDialog(self,
    gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
    'asdfasf')
             dialog.run()
             dialog.destroy()

    gobject.threads_init()

    w = MainWindow()

    t = AThread()
    t.connect('ASignal', w.aSignal)
    t.start()

    gtk.main()


Any suggestion is appreciated.

Thanks,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.daa.com.au/pipermail/pygtk/attachments/20130725/ea34ab2d/attachment.html>


More information about the pygtk mailing list