[pygtk] Problem communicating two class
Alexandre González
alex at rianxosencabos.com
Sat May 30 00:01:54 WST 2009
Thanks for the reply and lot of thanks for the autoconnection doc, I didn't
know about it.
About the __init__ it doesn't work:
Traceback (most recent call last):
File "/home/alex/Escritorio/pymoc/stuff/events.py", line 21, in
on_about_activate
self.parent['aboutdialog'].show()
NameError: global name 'self' is not defined
I'm new at class programming in python, os perhaps be a stupid question as I
said before.
Thanks again Guillaume
2009/5/29 Guillaume Bouchard <guillaume.bouchard at insa-lyon.fr>
> 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
>
--
Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
and/or .pptx
http://mirblu.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20090529/1eea510e/attachment.htm
More information about the pygtk
mailing list