[pygtk] Yet another threads problem

Neil Dugan pygtk at butterflystitches.com.au
Tue Feb 19 16:36:14 WST 2008

Mystilleef wrote:
> Calling Dialog's run method in a thread will crash your app. I learned
> the hard way (weeks of debugging). I use Windows instead of Dialogs
> now. Manage showing and hiding the window yourself.
> Cheers
> On Feb 18, 2008 7:26 AM, Steve McClure <smcclure at racemi.com> wrote:

I use this to get a dialog from a thread.  I have a function to 
display the dialog, and call this with an idle_add() in the Thread.

   def displaymessage(self, message) :
     dialog = gtk.MessageDialog(self.window.window, gtk.DIALOG_MODAL, 
         gtk.BUTTONS_CANCEL, message);
     dialog.connect('response', lambda w,d: dialog.destroy())

   gobject.idle_add(self.displaymessage, "My error message")

>>On Feb 18, 2008, at 7:19 AM, Adolfo González Blázquez wrote:
>>>El sáb, 16-02-2008 a las 14:19 +1300, John Stowers escribió:
>>>>On Fri, 2008-02-15 at 14:05 +0100, Adolfo González Blázquez wrote:
>>>>>I'm writing a little app that needs 2 windows, a main window, and
>>>>>another for entering data. I'm writing it using Glade, so both
>>>>>are defined in one glade file. The second one, emulates a entry
>>>>>and is modal.
>>>>>My problem is that i want the second window displayed when i
>>>>>click in a
>>>>>button in the main window, and then, when i press "Close" in the
>>>>>window, get the text and do some things, and update the main window
>>>>>status bar.
>>>>I dont quite understand you here, it doesnt sound like a threads
>>>>more a design issue.
>>>>When I want to return stuff from a dialog I typically create my own
>>>>dialog subclass [1] which returns a tuple of the dialog specific
>>>>information from the (overridden run method). For example (excuse
>>>>class MyDialog(gtk.Dialog)
>>>>     def __init__(self, setting1, setting2, setting3)
>>>>         #call super
>>>>         #save old settings
>>>>         self.oldsetting1 = setting1
>>>>         ...etc
>>>>         #construct dialog
>>>>         self.widget1 = gtk.Entry()
>>>>         self.widget1.set_text(setting1)
>>>>         ...etc
>>>>     def run(self):
>>>>         if gtk.Dialog.run(self) == gtk.RESPONSE_OK:
>>>>              setting1 = self.widget1.get_text()
>>>>              setting2 = self.widget2.get_text()
>>>>              setting3 = self.widget3.get_text()
>>>>              return setting1, setting2, setting3
>>>>         else:
>>>>              return self.oldsetting1, self.oldsettin2,
>>>>then run it with
>>>>dialog = MyDialog(a,b,c)
>>>>a,b,c = dialog.run()
>>>Well, I've subclassed gtk.Dialog as you point, and I'm still having
>>>same issue.
>>>I run the dialog, enter the data and click OK. Then it was supposed to
>>>hide the dialog, and update the statusbar while things are happening,
>>>but in fact the gui freezes till the end.
>>Dialog.run() is the "problem".
>>"The run() method blocks in a recursive main loop until the dialog
>>either emits the "response" signal, or is destroyed"
>>To get the behavior you want, you need to set up a callback for the
>>OK button which fetches the text and performs the desired action.
>>>The related code is here:
>>>And a screencast of what is happening in here:
>>>Any idea?
>>>>[1] http://davyd.livejournal.com/237414.html
>>>>>Here's a screencast of what i'm doing:
>>>>>What it was supposed to do is:
>>>>>- Open the add window
>>>>>- Enter the text and click close
>>>>>- The add window closes
>>>>>- In the main window status bar appears "Conectando..."
>>>>>- The status bar changes to "Conectado!"
>>>>>- A error dialog appers
>>>>>Relevant code here:
>>>>>Thanks in advance for any help
>>>>>-- adolfo
>>>>>pygtk mailing list   pygtk at daa.com.au
>>>>>Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>>>pygtk mailing list   pygtk at daa.com.au
>>>Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>>Steve McClure
>>smcclure at racemi.com

More information about the pygtk mailing list