Hi, you have to put all the gtk calls running in a different thread,
between a gtk.gdk.threads_enter() and a gtk.gdk.threads_leave(). I've
a attached a modifed test.py that works in my system.
Good look!
On Mon, 14 Mar 2005 13:23:45 +0100, Le Boulanger Yann
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've a problem when I use gtk.Dialog.run() funtion in a thread
> I attached a small example that shows the problem.
> If you run test.py, it works (in this case threads are not used).
> But now if you run core.py (which launch a thread that does exactly the
> same thing) when I press a key in the dialog window, the dialog is not
> destroyed and the application freezes.
> I don't understand why this happens and what can I do to have it working
> with threads.
> My intention is from the thread to run() the dialog and wait for the
> user to give the password and then use it. run() would normally do this,
> but it freezes with threads. I saw a workaround in FAQ 10.17 (about
> dialog.run running in the mainloop), but that won't block in a mainloop
> so it doesn't suit me.
>
> does someone has an idea ?
>
>
> _______________________________________________
> pygtk mailing list [email protected]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>
>
>
>
#!/usr/bin/env python
import gtk
import gtk.glade
import gobject
GTKGUI_GLADE='test.glade'
class window:
def __init__(self):
window_xml = gtk.glade.XML(GTKGUI_GLADE, 'window1')
window_xml.signal_autoconnect(self)
def on_window1_destroy(self, widget):
gtk.main_quit()
class diag:
def __init__(self, labeltext, checkbuttontext):
#gtk.gdk.threads_enter()
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'passphrase_dialog')
self.dialog = self.xml.get_widget('passphrase_dialog')
self.passphrase_entry = self.xml.get_widget('passpharse_entry')
self.xml.get_widget('message_label').set_text(labeltext)
self.xml.get_widget('save_passphrase_checkbutton').set_label(checkbuttontext)
self.xml.signal_autoconnect(self)
#gtk.gdk.threads_leave()
def run(self):
"""Wait for OK button to be pressed and return passphrase/password"""
gtk.gdk.threads_enter()
rep = self.dialog.run()
if rep == gtk.RESPONSE_OK:
passphrase = self.passphrase_entry.get_text()
else:
passphrase = -1
save_passphrase_checkbutton = self.xml.\
get_widget('save_passphrase_checkbutton')
self.dialog.destroy()
active = save_passphrase_checkbutton.get_active()
gtk.gdk.threads_leave()
return passphrase, active
class plugin:
def autoconnect(self):
d = diag('somethink', 'save')
print d.run()
return False
def __init__(self):
gtk.gdk.threads_init()
window()
gobject.timeout_add(100, self.autoconnect)
gtk.gdk.threads_enter()
gtk.main()
gtk.gdk.threads_leave()
def autoconnect():
d = diag('somethink', 'save')
print d.run()
return False
if __name__ == "__main__":
window()
gobject.timeout_add(100, autoconnect)
gtk.main()
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/