[Chicago] wxpita
Aaron Lav
asl2 at pobox.com
Sat Dec 15 18:44:17 CET 2007
On Sat, Dec 15, 2007 at 10:55:52AM -0600, sheila miguez wrote:
> On Dec 14, 2007 11:33 PM, Feihong Hsu <hsu.feihong at yahoo.com> wrote:
>
> > The fake methods just emulate simple method calls that you can make on the
> > real widgets. For example,
>
> I think Aaron had made a suggestion for forwarding methods you hadn't
> faked out yet to the real widgets. But I couldn't hear the entire
> conversation.
Apparently my message
(http://mail.python.org/pipermail/chicago/2007-December/003124.html)
came out blank: this not being heard seems to cross media boundaries,
sorry.
Anyway, the idea was to use __getattr__ (and __setattr__, if the wx
API requires it) to forward any calls which aren't part of the wxPita
API to a lazily created wx object. So __getattr__ would look something like
def __getattr__(self, attribute):
if not self._wx_obj:
self.create_wx_obj()
return getattr(self._wx_obj, attribute)
(The delegating class needs to be new-style, since __getattr__ for
classic classes gets called for all attributes, not just unknown ones.
__setattr__ would need to check for known "fake class" attributes, and
not delegate them. See http://docs.python.org/ref/attribute-access.html)
If there's a name clash between a fake object method and a wx method,
this delegator won't work, but such clashes seem likely to lead to
confusion anyway, and it'd be better to rename the fake object method.
With a simple delegator like this, it's possible for the abstraction
to leak (for example, if a wx method were to return a bound method,
it'd be bound to _wx_obj, not the fake object).
Also, since many wx objects can't be created without the wxApp object,
you'd also need to create the wxApp object as-needed in create_wx_obj().
There was also a brief discussion of how the arguments to the fake
object should be saved (string vs. dict), but that's orthogonal to
this issue.
Aaron
More information about the Chicago
mailing list