[wxPython-users] Adding GUI to already existing CLI framework

Mike Rooney mxr at qvii.com
Fri Aug 3 06:52:27 PDT 2007


Stani's Python Editor wrote:
> Probably you need wx.lib.pubsub which is independent of wx. You can just
> copy the file pubsub.py to your application in case you want to drop wx.
> Stani
>   

Yes, this is how I usually do it, and you can see it at 
http://wiki.wxpython.org/ModelViewController as Andrea mentioned. Scroll 
down for an example. If you want your model/controller to be 
non-dependent on wx, you can either copy in the pubsub.py as Stani 
mentioned, or what I usually do is something like:

try:
    import wx.lib.pubsub as pubsub
    PUBSUB = True
except:
    PUBSUB = False


Then wherever you would use pubsub to send a message, just check 'if 
PUBSUB: ' first. This to me seems like an elegant solution because if 
you can't import wx you have no gui and therefore no need to send 
messages to one (not that it hurts to send messages if no one is 
listening). I also feel a little hackish copying a file from wx into my 
local space like that because if wx gets upgraded, you never know what 
could change. Maybe an important bug fix or security vulnerability, or 
maybe your file will be left incompatible?

Anyway just my $0.02,
- Mike





More information about the wxpython-users mailing list