473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

wxPython syntax

I've started taking a look at wxPython, and, well, I've noticed
that the syntax needed to code with it is extremely ugly. I am
wondering if there exist any preprocessing tools or clever refactorings
that allow users to write more sane-looking code. In particular, it
seems to me that the structure of the code often does not reflect the
structure of the GUI being designed. For instance, the wxPython wiki
"Getting Started" guide includes this code to set up a file menu with
About and Exit options:

filemenu= wxMenu()
filemenu.Append(ID_ABOUT, "&About","Information about this
program")
filemenu.AppendSeparator()
filemenu.Append(ID_EXIT,"E&xit","Terminate the program")
# Creating the menubar.
menuBar = wxMenuBar()
menuBar.Append(filemenu,"&File")
self.SetMenuBar(menuBar)content.
EVT_MENU(self, ID_ABOUT, self.OnAbout)
EVT_MENU(self, ID_EXIT, self.OnExit)
self.Show(true)
def OnAbout(self,e):
d= wxMessageDialog( self, "A sample editor \n" "in
wxPython","About Sample Editor", wxOK)
d.ShowModal()
d.Destroy()
def OnExit(self,e):
self.Close(true)

Pieces of the code, like "filemenu" and ID_ABOUT and OnAbout, are
confusingly repeated throughout the definition. Doesn't it seem like
there should be some way to structure it so that the interface nesting
"option in menu in frame" is reflected in the code? I want to do
something like this:

menus:
File(wxMenu):
name = "&File"
about(menuOption):
name = "About"
statusText = "Information about this program"
action():
wxMessageDialog(self, "A sample editor. . .")
exit(menuOption):
name = "Exit"
etc. . .

Now, obviously that isn't valid code, but it seems like it might be
possible to get something like by using nested classes and/or functions
(e.g., have it say "class menus:" and then "class file(wxMenu)"). So my
basic questions are:

1) Does anything like this exist (or is anything in development)?
Is there any way to write GUI code in a way that reflects the structure
of the GUI?

2) If not, is it possible?

3) One specific problem is that I can't find a way to get at the
information in nested classes. Does Python provide any way to, say,
take a certain class and loop through all the classes which are defined
as nested classes inside it? Or, more generally, what kind of syntactic
help can be had from Python with regard to creating nested structures
like this?

Any thoughts would be appreciated.

--
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
--author unknown
Jul 18 '05 #1
6 1567
In article <Xn*****************@130.133.1.4>, OKB (not okblacke) wrote:
I've started taking a look at wxPython, and, well, I've
noticed that the syntax needed to code with it is extremely
ugly.
Yup -- we just had this discussion a couple weeks ago.
I am wondering if there exist any preprocessing tools or
clever refactorings that allow users to write more
sane-looking code.


wax is one such attempt to wrap wxPython widgets and provide a
cleaner, simpler syntax.

--
Grant Edwards grante Yow! I had pancake makeup
at for brunch!
visi.com
Jul 18 '05 #2
In article <40***********************@newsreader.visi.com>, Grant Edwards wrote:
I've started taking a look at wxPython, and, well, I've
noticed that the syntax needed to code with it is extremely
ugly.


Yup -- we just had this discussion a couple weeks ago.


Google the group for the subject line "Don't understand wxPython ids".

The bottom line is that un-pythonic syntax of wxPython reflects
the un-pythonic syntax of the underlying C++ library. Two of
the fundamental decisions that makes wxWidgets complex and
difficult to work with compared to most other widget sets are

1) Using the "object-ID/event-ID" scheme to hook handlers to
events rather that making handlers attributes of widgets.
It's a more general/powerful scheme, but for small apps
like I write it's just gratuitous complexity.

2) Making the widget hierarchy separate from the layout
hierarchy. Again, it's a more general and powerful way to
do things, but for the small apps I write it's added work
and complexity with no benefit.

--
Grant Edwards grante Yow! I'd like TRAINED
at SEALS and a CONVERTIBLE on
visi.com my doorstep by NOON!!
Jul 18 '05 #3
Grant Edwards wrote:
The bottom line is that un-pythonic syntax of wxPython reflects
the un-pythonic syntax of the underlying C++ library.


I've noticed this, and I must say it irks me. It seems as though
wxPython is simply providing a way to drop C++ code into a Python
program, which is, needless to say, undesirable. (I mean, Python is
NICE. I use it so I DON'T have to learn ugly C++ stuff.) I don't want
to sound harsh, but why is it like this? I suppose the obvious answer
is "it's easier to do it that way", but it still seems like it would be
nice if there were a real PYTHON GUI library.

--
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
--author unknown
Jul 18 '05 #4
David Fraser <da****@sjsoft.com> wrote in message
One of the main things that would need to be addressed is how sizers and
layout could be defined using this approach

David


The easiest (and therefore best, imho) way that I have ever seen to
manage widget layout is in Java's RelativeLayout. See
http://www.onjava.com/pub/a/onjava/2...ivelayout.html
Within this, layout is controlled by a xml file.

Does anyone know if any of the python gui toolkits have something
similar to this?
Not the xml file, but the methodology itself.

-John
Jul 18 '05 #5
John Taylor wrote:
David Fraser <da****@sjsoft.com> wrote in message
One of the main things that would need to be addressed is how sizers and
layout could be defined using this approach

David

The easiest (and therefore best, imho) way that I have ever seen to
manage widget layout is in Java's RelativeLayout. See
http://www.onjava.com/pub/a/onjava/2...ivelayout.html
Within this, layout is controlled by a xml file.


Thanks for the link, interesting article.
Does anyone know if any of the python gui toolkits have something
similar to this?
Not the xml file, but the methodology itself.


Not sure. I'm sure you could create a similar methodology layout class
for wxPython though...

David
Jul 18 '05 #6
David Fraser <da****@sjsoft.com> wrote in message news:<cb**********@ctb-nnrp2.saix.net>...
John Taylor wrote:
David Fraser <da****@sjsoft.com> wrote in message
One of the main things that would need to be addressed is how sizers and
layout could be defined using this approach

David

The easiest (and therefore best, imho) way that I have ever seen to
manage widget layout is in Java's RelativeLayout. See
http://www.onjava.com/pub/a/onjava/2...ivelayout.html
Within this, layout is controlled by a xml file.


Thanks for the link, interesting article.
Does anyone know if any of the python gui toolkits have something
similar to this?
Not the xml file, but the methodology itself.


Not sure. I'm sure you could create a similar methodology layout class
for wxPython though...

David


I forgot to mention that I got this up & running in Jython without too
much trouble. Jython can't use CPython's external libraries (on at
least Windows platforms). So if I wanted to use ldap and/or mysql, I
would have to code those sections in Java. By this point, it kind of
defeated the whole point as it would have been better to have coded
the whole thing in Java instead.

I could have used a client/server model and ran the GUI in Java which
would communicate to a python based server. I never did get around to
trying this approach, however.

-John
Jul 18 '05 #7

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

Similar topics

1
by: Mark Carter | last post by:
Running xrced.py produced: Traceback (most recent call last): File "C:\Python23\Lib\site-packages\wxPython\tools\XRCed\xrced.py", line 28, in ? from tree import * # imports...
5
by: Daniel Ehrenberg | last post by:
I'm trying to learn wxPython, but I can't seem to find much documentation. The wxPython website says that all advanced (and even some basic) documentation for wxPython is only available in C++...
15
by: Grant Edwards | last post by:
Can anybody recommend a good book on wxPython? Are there any books on wxPython? I've been trying to learn wxPython and/or wax for a few weeks, and I'm just not getting it. wxWindows seems...
25
by: BJörn Lindqvist | last post by:
See: http://www.wxpython.org/quotes.php. especially: "wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard...
25
by: TPJ | last post by:
GUI's etc: PyGtk on Windows "(...) So if someone develops mainly for X and just wants to make sure that it is not impossible to run on Windows, you can use PyGTK. (...)", July 2nd, 1999 pyGTK...
2
by: Eric von Horst | last post by:
Hi, I am looking for wx widget that has the ability to show text, edit the text (like a TextCtrl) but also does syntax highlighting (if the text is e.g. XML or HTML). I have been looking in the...
1
by: vedrandekovic | last post by:
Hello, How can I Insert image with string in ListCtrl with this example: # Import ftputil module - like ftplib from ftputil import FTPHost # Create connection...
4
by: python | last post by:
I'm looking at rewriting some legacy VB applications and am pondering which of the following techniques to use: 1. Browser based GUI with local web server (Browser + wsgiref.simple_server) (I'm...
16
by: Andrea Gavana | last post by:
Hi Diez & All, Do you mind explaining "why" you find it *buttugly*? I am asking just out of curiosity, obviously. I am so biased towards wxPython that I won't make any comment on this thread...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.