Thanks Marco, Messing with __getattr__... I think I'm going to let that pass. It feels kinda messy. I'm just begining with gtk and I've been browsing through other people's code but I find it difficult to organize my gtk code.
Regards, Leon ________________________________________ From: [email protected] [[email protected]] on behalf of Marco Giusti [[email protected]] Sent: Sunday, December 05, 2010 22:40 To: [email protected] Subject: Re: [pygtk] self from gtk.builder On Sun, Dec 05, 2010 at 08:54:28PM +0000, Leon Bogaert wrote: > Hi all, > > Is it possible to do something like this? > > class ActionsMenu(gtk.Menu): > def __init__(self): > builder = gtk.Builder() > builder.add_from_file("bctimer.xml") > > self = builder.get_object("menuActions") yes but it doesn't do what you think: it rebinds the name `self` to the builder object but the other references point to the `ActionsMenu`. what you can do is something like the following: class BaseWindow(object): def __init__(self, builder, auto_connect=True): self.__builder = builder if auto_connect: builder.connect_signals(self) def __getattr__(self, n): w = self.__builder.get_object(n) if w is not None: return w raise AttributeError, n or even, but not tested: ... def __getattr__(self, n): w = self.__builder.get_object(n) if w is not None: setattr(self, n, w) # here the point return w raise AttributeError, n m. -- Excellentium virorum est improborum negligere contumeliam, a quibus etiam laudari turpe. -- Plutarco _______________________________________________ pygtk mailing list [email protected] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/ _______________________________________________ pygtk mailing list [email protected] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
