wxPython syntax

OKB (not okblacke) BrenBarn at aol.com
Sun Jun 27 14:34:20 EDT 2004


    	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



More information about the Python-list mailing list