[pygtk] sharing data between windows

Doug Brewer dbrewer at insightpd.com
Tue Sep 15 06:25:49 WST 2009


Hello all,

I am a beginner both in python and pygtk. I have an application I am
developing as a learning experience. It has multiple windows. Let's say it's
a main window and a selection window with a list of items in it, each with
their own ID. The code started getting big so I split it into two classes,
one for each window. Each window has its own glade file as well. This seemed
nice and clean but I am having problems understanding how these separate
classes interact.

When the user selects the menu item, the main window class loads the pref
window and shows it. The user selects an item, and the window closes. But
here is where I got stuck. I could not figure out how to return the selected
value from the "child" window. The window has access to the methods in the
preferences class, but not the main class. The main class can access the
preference class functions, but doesn't know when the item has been selected
or the window closed.

The only way I could figure this out was to pass the main window object
itself to the preferences class, so that the pref class could set properties
(or access methods) to transfer the data.

(in preferences class):

def set_parent(self, object)
    self.parent = object

def close_window(self)
    self.parent.data = self.data

It works, but I'm wondering if I'm missing something really obvious that
would make this simpler.

Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20090914/a1fd6439/attachment.htm 


More information about the pygtk mailing list