Ka-Ping Yee <[EMAIL PROTECTED]> wrote: > > On Sun, 15 May 2005, Shane Hathaway wrote: > > You might add to the PEP the following example, which could really > > improve the process of building GUIs in Python: > > > > class MyFrame(Frame): > > def __init__(self): > > with Panel(): > > with VerticalBoxSizer(): > > self.text = TextEntry() > > self.ok = Button('Ok') > > I don't understand how this would be implemented. Would a widget > function like 'TextEntry' set the parent of the widget according to > some global 'parent' variable? If so, how would 'Panel' know that > its parent is supposed to be the 'MyFrame' object?
It would actually take a bit more to make work properly. If those objects were aware of the resource allocation mechanism, they could add and remove themselves from a context stack as necessary. In the case of things like VerticalBoxSizer, save the current self dictionary on entrance, then check for changes on exit, performing an Add with all the new objects. Or, so that it doesn't change the way wxPython works with other versions of Python, everything could be wrapped, perhaps using something like... class MyFrame(Frame): def __init__(self): with new_context(self): with parented(Panel, self) as panel: with unparented(VerticalBoxSizer, 'Add') as panel.sizer: self.text = TextEntry(panel) self.ok = Button(panel, 'Ok') There would be a little more work involved to generate a reasonable API for this, but it is all possible. - Josiah _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com