Pythonic gui format?

bruno at modulix onurb at xiludom.gro
Tue Feb 14 09:28:13 EST 2006


Gregory Petrosyan wrote:
>>>Isn't it ugly a bit?
>>
>>I'd even say 'ugly 16-bits' !-)
> 
> 
> You are right of course. Those  "examples"  are really bad, and, most
> of all, really un-pythonic.
> 
> Thanks for JSON. It's more clean&simple than XML, but my main idea is
> to remove any extra layer between Python and GUI. I want all GUI
> elements/data to be directly accessible from Python (without extra
> libraries).
> 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...)

One possible (but somewhat ugly) solution is to use a list of tuples
instead of a dict:

d = {'k1': 'v1', 'k2': 'v2'}
=>
l = [('k1', 'v1'), ('k2', 'v2')]

where 'values' can of course be any Python data type...


Another solution is to include ordering infos in the dict, either as
1/an entry for each item or as 2/a separate entry:

1/
window = {
  "item" : {'k1': 'v1', 'k2': 'v2', 'order': XXX},
  "otheritem" : {'k1n': 'v1n', 'k2n': 'v2n', 'order': YYY},
}

2/
window = {
  "item" : {'k1': 'v1', 'k2': 'v2'},
  "otheritem" : {'k1n': 'v1n', 'k2n': 'v2n'},
  "order" : ['item', 'otheritem'],
}

NB : I'd rather choose the second solution...


And finally, you could write your own ordered mapping type - but then
you loose the builtin syntax...

My 2 (unordered) cents...
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list