[pygtk] Problem communicating two class
Guillaume Bouchard
guillaume.bouchard at insa-lyon.fr
Fri May 29 23:46:54 WST 2009
Hello,
On Fri, May 29, 2009 at 05:23:50PM +0200, Alexandre González wrote:
> Hi! Perhaps this could be a stupid question, but I'm trying to do it and I
> can't.
>
> I did a skeleton of a pygtk application to learn about use it, but i have a
> problem... I create a parent class [1] to procedure the events (it create
> the events connections with instrospection and it works very well ;) but I
> load the glade file here, and the events handlers are in the child class
> [2]. So when I click on the about button in the application, I can't show
> the about dialog loaded at parent class because I can't access it.
As I told you on IRC (but you look away when my response come), You only
need to set the "parent" class in the "child class"
def __init__(self,parent):
self.parent = parent
And when you init your Event class, do it like that :
events = Events(self)
Then you can access the parent in every event method with self.parent.
> I tried with super but it doesn't work, and I tried to send from parent to
> child the parent object doing this on the parent code: child = Child(self)
> but it doesn't work too.
Super does work when you inherit, it's not the case here.
But I'm wondering how you really did your "child = Child(self)" because
it's the way to go.
By the way, did you know that pygtk and glade/builder have a very handy
way to connect signal to methods with introspection ?
you can use the glade or builder method signal_autoconnect()
http://www.pygtk.org/pygtk2reference/class-gtkbuilder.html#method-gtkbuilder--connect-signals
You only need to name the signal handler in glade and it will
automatically connect it to the right method (and you can use the
optional data argument if you really need an events object which is
unbound from the "parent class")
Good luck.
--
Guillaume
More information about the pygtk
mailing list