Pythonic gui format?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Tue Feb 14 21:12:37 EST 2006


Gregory Petrosyan a écrit :
(snip)
> Your dicts example is nice, but this  approach (and some others) lacks
> one important feature: ordering of GUI elements. In XML, the order of
> all elements is specified, and with dicts (or with very clean Georg's
> model) it is not. (BTW remember topics about ordered dicts...)

(rereading this thread...)

Err... Wait a minute. Are you actually *sure* that there's a problem 
with ordering here ? I mean (please stop me if I missed the point): a 
Window is an object, right ? It has attributes (which are named, and 
definitively *not* ordered - remember, object attributes are actually 
stored in a dict). Now *some* of these attributes may well be 
collections of other objects (ie: widgets...). And these collections 
*can* be ordered.

window = {
   '__class__' : 'Window',
   'id' : 'dummy',
   'title' : 'My Dummy Window',
   'w' : 640,
   'h' : 480
   'widgets': [
      {'__class__' : 'Widget',
       'id : 'dummy1',
       'handlers' : {
         'on_click' : # damn...,
        },
      },
      {'__class__' : 'Widget',
       'id : 'dummy2',
       'handlers' : {
         'on_clock' : # dring...,
        },
      },
   ],
}

Braindead Stupid Simple, Isn't it ? (DH was *somehow* right: this is not 
JSON, but this is exactly what JSON is to javascript).

As you see, what needs to be ordered is ordered. Now what we'd need 
would be a way to represent callback (handlers) functions. The simplest 
would probably be to forbid anonymous functions for callbacks, so we 
could just store the fully.qualified.name.to.callback as string...

My 2 cents



More information about the Python-list mailing list