[pygtk] PyGTK and multithreading
regis
r.floret at laposte.net
Thu Apr 13 18:07:09 WST 2006
You should call gtk.gdk.threads_init() before gtk.main() to enable
threads in your Gtk+ application.
Regards
Régis
Le jeudi 13 avril 2006 à 11:40 +0200, remi.sassolas at gmail.com a écrit :
> Hi,
>
> I'm currently working on an graphical application designed with PyGTK
> (with the invaluable help of Glade).
> I would like to launch multiple instances of my application in
> threads, but I've got a problem.
> I only manage to have one instance running, the last one (the other
> ones freeze).
>
> I've found different tips on the net about this problem, but none of
> these solutions seem to meet my needs.
> Here is an smal example of what I'm trying to do :
>
> # file Example.py :
> import threading
> import gobject
> import gtk
> from gtk import glade
>
> class MyThread(threading.Thread):
>
> def __init__(self, button):
> super(MyThread, self).__init__()
> self.quit = False
> self.button = button
>
> def run(self):
> gobject.idle_add(self.button.create)
>
>
> class button:
>
> def __init__(self):
> pass
>
> def create(self):
> gl = glade.XML('button.glade')
> signals = {'on_button1_clicked':self.test,}
> gl.signal_autoconnect(signals)
>
> def test(self, event):
> print "test"
>
>
> gobject.threads_init()
>
> b = button()
> t = MyThread(b)
> t.start()
>
> b2 = button()
> t2 = MyThread(b2)
> t2.start()
>
> gtk.main()
> # End of file
>
> If you try it, you should become two windows, each one with a button
> but only one is running.
> Any idea of what's going wrong ?
>
> Thanks in advance for any help provided !
> --
> Remi
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
More information about the pygtk
mailing list