On 1/15/2014 6:09 PM, Chris Angelico wrote:
On Thu, Jan 16, 2014 at 9:58 AM, Terry Reedy <tjre...@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?

I must have changed to **kwds after copying.

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".

One could say so in the message

InterfaceError("The icon object must be a bitmap or else the non-bitmap object 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.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to