473,785 Members | 2,819 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 #1
33 2297
Gregory Petrosyan wrote:
I have to write _simple_ gui library, for embedding into game. My
first attempt was to use XML
....
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?)


Don't do that :)

Don't listen to recommendations for or against a technology based only
on vague "this is not how we do things around here" reasons. If XML
suits your need, than use it. It seems it will work fine in situations
where you need to edit/extend the GUI by external means. If you do it in
code, you risk that you'll need to change the code every time you want
to reposition a GUI element. It doesn't matter much if you invent your
own file format because eventually you'll have to extend it, or write
support for it, so you could as well use XML from the start.

XML parsing can be a little tedious, but there are many tools that make
it easier (I've even written one: http://ivoras.sharanet.org/xmldict.py.gz).
Feb 13 '06 #2
Thanks for your reply.
But isn't python code more flexible than XML? I think it's not harder
to edit py file than xml file. Also python can give me more speed than
xml, and possibly python code can be integrated better with rest of app
(because of absence of extra layer called "XML"). Has anybody have had
(how many grammar errorrs can you find here? :) some experience in
writing gui systems/formats "from scratch"?

IMO the strength of XML here is that it provides one, almost obvious,
format for gui description. And with Python, I can imagine hundreds of
them :) (but maybe there are real gems, and after finding one I'll be
very happy?)

Feb 13 '06 #3
Gregory Petrosyan wrote:
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>


One could imagine to model this with Python, like this:

class FooDlg(Window):
title = "Hello World!"
size = (400, 300)

class WelcomeImg(Imag e):
filename = "..."
pos = (0, 0)

class Box(Frame):
text = "My Controls"

class NameLbl(Label):
text = "Name:"

class NameField(TextB ox):
length = 100
pos = ...
def onClick(self):
MessageBox(self .text)

class TestList(ListBo x):
items = ['First', 'Second']

_Slight_ misuse of "class" though...

Georg
Feb 13 '06 #4
Nice, thanks!
BTW, maybe decorators could do good job here (something like @expose in
TG?)

Feb 13 '06 #5
Ivan Voras wrote:
Gregory Petrosyan wrote:
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?)


Don't do that :)

Don't listen to recommendations for or against a technology based only
on vague "this is not how we do things around here" reasons.


The reasons given in the blog were fairly precise. I think "only on
vague[...]" is misleading here. The idea of the article was to educate a
Java user how to change his or her frame of reference to better use Python.

The author was not being territorial as you are implying.
Feb 13 '06 #6
Gregory Petrosyan wrote:
Thanks for your reply.
But isn't python code more flexible than XML? I think it's not harder
to edit py file than xml file.


It's all about integration with tools, and while there are various
situations where avoiding tools is often better than extensive use of
tools (Python vs. Java-plus-Eclipse being an example that springs to my
mind, at least), there are some very good tools for certain kinds of
GUI design; it's better in such situations to make use of those tools
rather than eschew them in favour of something "Pythonic" but, in
various respects, less usable.

Once upon a time, it may have been the case that GUI design tools
(typically for forms-based applications) only produced program code - I
think SpecTcl, for example, was admired for its capabilities but
criticised for its Tcl-centric nature, ultimately forcing many to look
elsewhere despite variants such as SpecPython - but most design tools
now seem to produce some kind of XML description of widgets and
dialogues. How usable to other languages would Glade or Qt Designer be
if they respectively produced just C and C++ code? (Actually, unlike
Tcl, consuming C or C++ produced from the same tools would be an
annoyance in itself, I'd imagine.)

Paul

Feb 13 '06 #7
I need format, specialised for manual editing.
(And in this case a) I don't want/need to develop/find GUI forms
editors etc; b) maybe python is better for manual work? XML is pretty
nice for machines, but what about human mind: what is closer to it?)

Anyway, thanks for your help & attention.

Feb 13 '06 #8
Gregory Petrosyan a écrit :
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?)
Well, XML is a bit on the verbose side (but less than Java, which is why
Javaers love XML), and we usually have better ways to express things in
Python. But this doesn't mean that you shouldn't use it when appropriate.
I am currently seeking for pythonic alternative for XML.
A pretty obvious one is dicts and lists. What about (Q&D):

window = {
'title' : 'Hello World!'
'image' : {'text' :"nice picture here",
'pos' : ...,
'src' : .. },
'text_opts' : """
(some text here)
""",
'items' : [
'first-element',
'second-one',
...
]
'button' : {
'action': ...
'text' :"Click Me!"
},
}
well... It sure needs more work, but you get the idea...
One possible
way is to create a class for every (type of?) window, like
(snip ugly code)
Isn't it ugly a bit?
I'd even say 'ugly 16-bits' !-)
These styles of course can be combined... But IMHO looks not very nice
:( Maybe I shall not rely on introspection?
Why not ?
Any suggestions, comments,
thoughts and links are welcome.


You may want to have a look at JSON. It's 'JavaScript Object Notation' -
but Python and javascript are close enough, so the translation process
is a no-brainer - and it's used as a replacement for XML in most
Pythonic AJAX implementations . One of the potential plus of JSON (vs
more python-specific solutions) is that it's language-independant.

Else, there was a quite interesting configuration module by Vinay Sajip
that could fit your needs:

http://www.red-dove.com/python_config.html
http://www.red-dove.com/config/

(BTW, is this module still maintained ?)
Feb 13 '06 #9
DH
Bruno Desthuilliers wrote:
I am currently seeking for pythonic alternative for XML.


A pretty obvious one is dicts and lists. What about (Q&D):

That's like JSON: http://www.json.org/example.html
Feb 14 '06 #10

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

Similar topics

9
13273
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
5050
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
1799
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
1861
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
9645
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
9480
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
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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
10090
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
6739
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
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.