[pygtk] sharing data between windows
Jeffrey Barish
jeff_barish at earthlink.net
Tue Sep 15 10:24:32 WST 2009
Doug Brewer wrote:
> 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.
When you create separate classes for different parts of your GUI, you are
essentially creating widgets. Subclass gobject. gobject provides means for
sending signals from one widget to another (connect). There was a tutorial
for this technique at:
http://www.sicem.biz/personal/lgs/docs/gobject-python/gobject-
tutorial.html#d0e570
I'm getting an error message when I try to connect now, but maybe it will
come back. Also check the pygtk FAQ:
http://faq.pygtk.org/index.py?req=index
You should also understand the MVC pattern. The easiest way to learn it is
to use a framework that supports it. I recommend pygtkmvc:
http://pygtkmvc.sourceforge.net/pub/docs/tutorial/tutorial.html
I use MVC mostly. I create widgets only when I have an element that I want
to reuse in several places in the GUI.
--
Jeffrey Barish
More information about the pygtk
mailing list