A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-May/053784.html below:

[Python-Dev] PEP 343 - Abstract Block Redux

[Python-Dev] PEP 343 - Abstract Block ReduxJosiah Carlson jcarlson at uci.edu
Mon May 16 02:05:11 CEST 2005
Ka-Ping Yee <python-dev at zesty.ca> 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

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4