wxPython syntax

David Fraser davidf at sjsoft.com
Mon Jun 28 15:28:24 EDT 2004


OKB (not okblacke) wrote:
>     	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:

This is great - it's almost exactly like the syntax I have in mind for 
declaring wx GUIs.
My syntax idea is more like this:

wxMenu File:
     name = "&File"
     menuOption about:
         name = "About"
         statusText = "Information about this program"
     menuOption exit:
         ...

Except note that I've left the code bits out.
This idea follows from the following principles & ideas:

- The best way to define a GUI is with declarative language
- XML is great but not as nice to look at as Python-ish syntax
- Hierarchical definitions are done like they are in Python

I think wx would be easier to use if a syntax like the above were 
available which still required you to do all your programming in 
standard python. So for example the above section could be in a separate 
file or in a string within your code.

The reason I avoided including code is it then means this doesn't become 
a mess when lots of code is added, and the parser doesn't have to 
understand the whole Python syntax. The question is, how to bind to the 
code... I would like an approach like this:

MenuDeclaration = """ ... """ # put the above string in here...
MenuResource = wxResourceParser.Parse(MenuDeclaration)

class FileMenu(MenuResource):
     def OnAbout(self, event):
         # put the code here
     def OnExit(self, event):
         # put the code here

So the actual class derives from the resource generated from parsing the 
declaration.

Then there could be all kinds of debates as to binding names / events 
automatically or doing it manually.

Anyway I might actually get this working ; any comments appreciated

David



More information about the Python-list mailing list