[pygtk] Yet another threads problem

John Stowers john.stowers.lists at gmail.com
Sat Feb 16 10:19:17 WST 2008


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()

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/



More information about the pygtk mailing list