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


Groups > comp.lang.python > #64043 > unrolled thread

Re: Python declarative

Started byTerry Reedy <tjreedy@udel.edu>
First post2014-01-15 22:35 -0500
Last post2014-01-15 22:35 -0500
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.


Contents

  Re: Python declarative Terry Reedy <tjreedy@udel.edu> - 2014-01-15 22:35 -0500

#64043 — Re: Python declarative

FromTerry Reedy <tjreedy@udel.edu>
Date2014-01-15 22:35 -0500
SubjectRe: Python declarative
Message-ID<mailman.5564.1389843360.18130.python-list@python.org>
On 1/15/2014 6:09 PM, Chris Angelico wrote:
> 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?

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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web