Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64024 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2014-01-16 10:09 +1100 |
| Last post | 2014-01-16 10:09 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Python declarative Chris Angelico <rosuav@gmail.com> - 2014-01-16 10:09 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-01-16 10:09 +1100 |
| Subject | Re: Python declarative |
| Message-ID | <mailman.5550.1389827396.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web