wxPython and macros (was: Why don't people like lisp?

Brian Kelley bkelley at wi.mit.edu
Mon Oct 27 13:27:22 CET 2003

Tayss wrote:
> Ok, now being sober...  
> mike420 at ziplip.com wrote:
>>Why do you need a macro for that? Why don't you just write
>>def start_window(name) :               # 1
>>    app = wxPySimpleApp()              # 2
>>    frame = MainWindow(None, -1, name) # 3
>>    frame.Show(True)                   # 4
>>    app.MainLoop()                     # 5
>>    return (app, frame)                # 6
> Remember that we lose this game if lines #2-5 are executed out of
> order.  The system crashes.
> Your example above is sensible, because we don't have the power to do
> anything more meaningful.  So we're stuck with some trivial function
> that does nothing really important.  Boa Constructor, the great Python
> IDE, pops up three windows of different kinds and names on startup,
> but /we/ are stuck with the trivial ability to customize one window's
> name.

This isn't really the case I think, we just have a different idiom for 
doing something more meaningful.  The solutions in the wxPython world 
that I have seen do something like this:

class Application:
     def __init__(self, name):
         app = wxPySimpleApp()
         self.name = name
         except Exception:
            # report on applicatino failure
            #  and close down properly

     def createApplication(self):
         """create your application here"""
         # note, the window name is name
         raise NotImplementedError

So know the usage is

class MyApp(Application):
     def createApplication(self):
         frame = self.frame = wxFrame(None, -1, self.name)

app = MyApp("test")

So there are non-macro solutions to these issues that are equally 
expressive in some cases.  This is just more verbose than the 
corresponding macro solution, I still think that it is quite readable 

app.app = application
app.frame = main window


More information about the Python-list mailing list