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


Groups > comp.lang.python > #64023

Re: Python declarative

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'example:': 0.03; '16,': 0.03; 'subject:Python': 0.06; 'args': 0.07; 'arguments': 0.09; 'default.': 0.09; 'label,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'def': 0.12; 'gui': 0.12; 'jan': 0.12; '**kwds):': 0.16; 'dictionaries': 0.16; 'icon': 0.16; 'optional': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'world",': 0.16; 'appropriate': 0.16; 'language': 0.16; 'wrote:': 0.18; 'possible,': 0.19; 'thu,': 0.19; 'widget': 0.19; 'work,': 0.20; 'written': 0.21; '>>>': 0.22; 'header:User- Agent:1': 0.23; 'title,': 0.24; 'question': 0.24; 'sort': 0.25; 'extension': 0.26; 'this:': 0.26; 'developing': 0.27; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'skip:p 30': 0.29; 'am,': 0.29; 'label': 0.30; "i'm": 0.30; 'class': 0.32; 'probably': 0.32; 'alone': 0.33; 'skip:_ 10': 0.34; 'problem': 0.35; 'possible.': 0.35; 'something': 0.35; 'but': 0.35; 'keyword': 0.36; 'should': 0.36; 'error.': 0.37; 'button': 0.38; 'easiest': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'called': 0.40; 'received:173': 0.61; 'name': 0.63; 'such': 0.63; 'happen': 0.63; 'more': 0.64; 'size.': 0.65; 'potentially': 0.81; 'bitmap': 0.84; 'button:': 0.84; "it'd": 0.84; 'received:fios.verizon.net': 0.84; 'children.': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Python declarative
Date Wed, 15 Jan 2014 17:58:05 -0500
References <1389805328.32401.6.camel@linux-fetk.site> <CAPTjJmqnMaavYx7HyCKaPkj_Kcwp-gQZPjNm-k=KR_FSgEYysQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-254-207.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
In-Reply-To <CAPTjJmqnMaavYx7HyCKaPkj_Kcwp-gQZPjNm-k=KR_FSgEYysQ@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5549.1389826705.18130.python-list@python.org> (permalink)
Lines 65
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389826705 news.xs4all.nl 2913 [2001:888:2000:d::a6]:46233
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64023

Show key headers only | View raw


On 1/15/2014 12:33 PM, Chris Angelico wrote:
> On Thu, Jan 16, 2014 at 4:02 AM, Sergio Tortosa Benedito
> <sertorbe@gmail.com> wrote:
>> Hi I'm developing a sort of language extension for writing GUI programs
>> called guilang, right now it's written in Lua but I'm considreing Python
>> instead (because it's more tailored to alone applications). My question
>> it's if I can achieve this declarative-thing in python. Here's an
>> example:
>>
>> Window "myWindow" {
>>          title="Hello world";
>>          Button "myButton" {
>>                  label="I'm a button";
>>                  onClick=exit
>>          }
>> }
>> print(myWindow.myButton.label)
>
> Probably the easiest way to do that would be with dictionaries or
> function named arguments. It'd be something like this:
>
> myWindow = Window(
>      title="Hello World",
>      myButton=Button(
>          label="I'm a button",
>          onClick=exit
>      )
> )
> print(myWindow.myButton.label)

This is exactly what I was going to suggest.

> For this to work, you'd need a Window class that recognizes a number
> of keyword arguments (eg for title and other attributes), and then
> takes all other keyword arguments and turns them into its children.

I would make the required args positional-or-keyword, with or without a 
default. Something like (tested)

class Window:
     def __init__(self, title, *kwds)  # or title='Window title'
         self.title = title
         self.__dict__.update(kwds)

class Button:
     def __init__(self, label, **kwds):
         self.label = label
         self.__dict__.update(kwds)

<add Chris' code above>
 >>>
I'm a button

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

-- 
Terry Jan Reedy

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


Thread

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

csiph-web