473,795 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pythonic gui format?

Buenos dias, amigos!
I have to write _simple_ gui library, for embedding into game. My
first attempt was to use XML: isn't it cute to describe ui in such a
way:

<window>
<title>Hello World!</title>
<image text="nice picture here" pos=... src=... />
<text opts=...>
(some text here)
</text>
<list>
<item>first element</item>
<item>second one...</item>
</list>
<button action=... text="Click Me!" />
</window>

(or something similar)

But after reading "Python Is Not Java"
http://dirtsimple.org/2004/12/python-is-not-java.html (BTW I'm not a
Java programmer) I realised that it is actually not cute at all :) (am
I wrong here?)
I am currently seeking for pythonic alternative for XML. One possible
way is to create a class for every (type of?) window, like

class SomeDlg(Window) :
def __init__(self, dict?):
self.setdict(di ct)
self.add_text(" $friend would like to speak to you. $question")
self.add_button (action=self.on click,
text="Yeah, I'd like to $action !")
...

def onclick(self):
# process data here, send some messages etc.
Isn't it ugly a bit? Another variant is

dlg = Window(dict, [opts])
dlg.text("text here", [opts])
dlg.image(src, pos, text [etc])
.....

or possibly

dlg = Window(...)
dlg.text = Text(...)
dlg.button = Button(...)
....
dlg.display(sur face)
These styles of course can be combined... But IMHO looks not very nice
:( Maybe I shall not rely on introspection? Any suggestions, comments,
thoughts and links are welcome.
Thanks.

Feb 13 '06
33 2299

bruno at modulix wrote:
Fuzzyman wrote:
(snip)
You say you don't want an 'extra layer' between your GUI and Python -
but your approach of using XML has the same drawback. Storing your 'GUI
configuration' in a text based format is a nice idea, but you will need
*something* to do the translation.
Well, if the conf is valid Python, you've already get most of the
'something to do the translation' for free !-)


Except he can't use ordinary dictionaries because they don't preserve
order, which is one of his requirements...

Your trivial example below redone with ConfigObj syntax :

[window]

widgets = , # empty list

Code to read it :

from configobj import ConfigObj
gui_object = ConfigObj(filen ame)

All thebest,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml


--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"


Feb 15 '06 #31
Fuzzyman wrote:
bruno at modulix wrote:
Fuzzyman wrote:
(snip)

You say you don't want an 'extra layer' between your GUI and Python -
but your approach of using XML has the same drawback. Storing your 'GUI
configuratio n' in a text based format is a nice idea, but you will need
*something * to do the translation.


Well, if the conf is valid Python, you've already get most of the
'something to do the translation' for free !-)

Except he can't use ordinary dictionaries because they don't preserve
order, which is one of his requirements...


Except that dict ordering (or lack of) is not a problem here, cf my
other posts about this !-)

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Feb 15 '06 #32
In <t9************ ********@comcas t.com>, DH wrote:
And what about true vs True and false vs False ?-)


The syntax is the same, except for, as I said, JSON's multiline comments.
The semantics do differ, but that has nothing to do with the user's
question, about an alternative to XML for data representation. You
can use "true" or True or "null" or None or whatever semantic values
you want.


You can't use `True`, `False` and `None` in JSON documents. And strings
are delimited by `"` and not `'`. The `\x??` escape is forbidden in
strings and it's not allowed to leave out a leading zero in numbers, nor
is it allowed to start a number with a unary `+`.

Ciao,
Marc 'BlackJack' Rintsch
Feb 15 '06 #33
Sorry for the late reply, I have some ideas about a possible GUI
toolkit design (that works with one already done like GTK), I'll
probably show them here. In the meantime I can show this one:
http://thinlet.sourceforge.net/home.html

I like it because the way GUIs are defined is quite short.

bye,
Bearophile

Feb 23 '06 #34

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
13274
by: Tom Evans | last post by:
My basic question: If I have a specific interface which I know is going to be implemented by a number of classes, but there is no implementation commonality between them, what is the preferred form for this in Python? In a staticly typed language like c++ or java, I'd describe the interface first, then create the classes eithered derived from that ABC or implementing that interface (same thing really). This was the first thing I...
1
1471
by: asdf sdf | last post by:
i need some advice. i'm a back end programmer historically, but have been exploring python for webapps and enjoying it. i need to build some simple Win client-server or standalone apps. the result needs to look professional and attractive, and i need something i can get working fairly quickly with a modest learning curve. i'm looking at wxPython, because that is a pythonic solution. but i'm concerned about the scarcity of gentle...
12
1535
by: Nickolay Kolev | last post by:
Hi all, I would like to find a more pythonic way of solving the following: Having a string consisting of letters only, find out the total sound score of the string. The sound score is calculated as the sum of the transition scores between the characters in that string. The transition scores are stored in a 26 x 26 matrix. I.e. the transition A -> F would have the score soundScoreMatrix.
3
5606
by: R.Marquez | last post by:
Does any one know of a way to convert PDF documents into a raster format, such as TIFF or JPEG? Of course to do it in Python would be my preference, but if you know of another way to do this programatically I would also be interested. Thanks. -Ruben
5
1342
by: Ramon Felciano | last post by:
Hi -- I have a list of integers that I'd like to convert to a bitflag or 1D matrix format: a = b = # a 1 for each position in the a list The specifics of the resulting representation is irrelevant; it could be ' ' and 'X' characters. Eventually this will be printed in a grid
11
5052
by: Charles Krug | last post by:
I've a function that needs to maintain an ordered sequence between calls. In C or C++, I'd declare the pointer (or collection object) static at the function scope. What's the Pythonic way to do this? Is there a better solution than putting the sequence at module scope?
4
1800
by: Carl J. Van Arsdall | last post by:
It seems the more I come to learn about Python as a langauge and the way its used I've come across several discussions where people discuss how to do things using an OO model and then how to design software in a more "Pythonic" way. My question is, should we as python developers be trying to write code that follows more of a python standard or should we try to spend our efforts to stick to a more traditional OO model? For example, in...
3
1314
by: jnair | last post by:
My Tead Lead my object counter code seen below is not pythonic class E(object): _count = 0 def __init__(self): E._count += 1 count = property(lambda self: E._count ) def test(): if __name__ == "__main__":
26
1862
by: Frank Samuelson | last post by:
I love Python, and it is one of my 2 favorite languages. I would suggest that Python steal some aspects of the S language. ------------------------------------------------------- 1. Currently in Python def foo(x,y): ... assigns the name foo to a function object. Is this pythonic? Why not use the = operator like most other assignments?
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.