Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64024

Re: Python declarative

References <1389805328.32401.6.camel@linux-fetk.site> <CAPTjJmqnMaavYx7HyCKaPkj_Kcwp-gQZPjNm-k=KR_FSgEYysQ@mail.gmail.com> <lb73pm$78v$1@ger.gmane.org>
Date 2014-01-16 10:09 +1100
Subject Re: Python declarative
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5550.1389827396.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Jan 16, 2014 at 9:58 AM, Terry Reedy <tjreedy@udel.edu> wrote:
> class Window:
>     def __init__(self, title, *kwds)  # or title='Window title'
>         self.title = title
>         self.__dict__.update(kwds)

Does that want a second asterisk, matching the Button definition?

>> Possible, but potentially messy; if you happen to name your button
>> "icon", it might be misinterpreted as an attempt to set the window's
>> icon, and cause a very strange and incomprehensible error.
>
> Puns are always a problem with such interfaces. Validate the args as much as
> possible. An icon should be a bitmap of appropriate size. Optional args
> should perhaps all be widgets (instances of a Widget baseclass).

Yeah, but you'd still get back an error saying "icon should be a
bitmap" where the real problem is "icon should be called something
else". It might be worth explicitly adorning properties, or separating
them into two categories. Since the keyword-named-children system has
the other problem of being hard to lay out (how do you specify the
order?), I'd look at keyword args for properties and something
separate for children - either the layout I used above with .add(),
which allows extra args as necessary, or something like this:

myWindow = Window(
     title="Hello World",
     children=[Button(
         label="I'm a button",
         onClick=exit
     )]
)

Or maybe allow "child=" as a shortcut, since a lot of widgets will
have exactly one child.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python declarative Chris Angelico <rosuav@gmail.com> - 2014-01-16 10:09 +1100

csiph-web