473,805 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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","Infor mation about this
program")
filemenu.Append Separator()
filemenu.Append (ID_EXIT,"E&xit ","Terminat e the program")
# Creating the menubar.
menuBar = wxMenuBar()
menuBar.Append( filemenu,"&File ")
self.SetMenuBar (menuBar)conten t.
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","Abou t 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(menuOptio n):
name = "About"
statusText = "Informatio n 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 1585
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************ ***********@new sreader.visi.co m>, 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
1816
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 xxx which imports params File "C:\Python23\Lib\site-packages\wxPython\tools\XRCed\tree.py", line 1174 ^ SyntaxError: invalid syntax ---
5
4199
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++ syntax in the main wxWindows documentation. It also says that the samples will help, but I can't seem to make sense of them. Should I just use a not-as-good GUI like Tkinter or a not-as-common one like Anygui or PyUI if I want to have documentation?...
15
2914
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 to be more low-level than the other GUI toolkits I've used (Tk, GTK, and Trestle), and there are all sorts exposed details in wxWindows/wxPython that I find weird.
25
3363
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 Python GUI toolkit is that Tkinter was there first." - Guido van Rossum Guess, that answers my question, but isn't "Tkinter was there first" a very bad answer? :) It is kinda ugly too, so I wonder why it can't be replaced? Or maybe another GUI...
25
4288
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 on Windows "(...) > can i use pyGTK under > Windows???
2
2499
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 latest wxPython version but I could not really find anything. Any suggestions?
1
3598
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 ftp=FTPHost("ftp.someserver.com","user","password") # LIST ALL FILES/FOLDERS ON SERVER
4
2824
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 assuming that simple_server is class I want to build from for a local web server) -OR- 2. wxPython based GUI
16
2419
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 in particular, but I am curious to know why some people find it "ugly" or "bad" or whatever. It has its own bugs and missing features, of course, but it is one of the major GUI player in the arena, together with PyQt and PyGTK.
0
9716
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
10360
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
10366
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
10105
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...
0
9185
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7646
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
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4323
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
3
3007
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.