[pygtk] Yet another threads problem
Steve McClure
smcclure at racemi.com
Mon Feb 18 21:26:46 WST 2008
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:
>>> Hello,
>>>
>>> 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
>>> windows
>>> are defined in one glade file. The second one, emulates a entry
>>> dialog,
>>> 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
>>> second
>>> 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
>> issue,
>> 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
>> broken
>> pseudocode)
>>
>> 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,
>> self.oldsetting3
>>
>> then run it with
>> dialog = MyDialog(a,b,c)
>> a,b,c = dialog.run()
>> dialog.distroy()
>
> Well, I've subclassed gtk.Dialog as you point, and I'm still having
> the
> 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".
From
http://www.pygtk.org/pygtk2reference/class-gtkdialog.html#method-
gtkdialog--run
"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:
> http://pastebin.com/mb2ea398
>
> And a screencast of what is happening in here:
> http://www.infinicode.org/code/out.ogg
>
> Any idea?
>
>>
>> Regards,
>>
>> John
>>
>> [1] http://davyd.livejournal.com/237414.html
>>
>>>
>>> Here's a screencast of what i'm doing:
>>> http://www.infinicode.org/code/out.ogg
>>>
>>> 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:
>>> http://pastebin.com/f6bf4e71b
>>>
>>>
>>> Thanks in advance for any help
>>>
>>> -- adolfo
>>> _______________________________________________
>>> 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/
>>
> _______________________________________________
> 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/
--
Steve McClure
smcclure at racemi.com
More information about the pygtk
mailing list