Robin Dunn wrote:
> DanSV@aol.com wrote: ...
>> It takes significantly longer to start up than pyGtk, and has a
>> larger memory footprint. How can I get around this?
>> I thought importing only those parts of the wxwindows modules that I
>> need to use would help, but I do not know how to do this. Any ideas?
> There really isn't a good solution for this yet, other than custom
> building and leaving out lots of stuff in wxWindows and wxPython. I
> do have some ideas though that I'll try out in the 2.5 timeframe.
I have an idea (which may be neither new nor correct).
The standard advice in wxPython (and similarly for other GUI toolkits)
is to use "from wxPython.wx import *". This of necessity adds almost
3000 symbols to the symbol table. In some of my attempts to learn
wxPython, this has frustrated me. If for no other reason, each dir()
returns a disgustingly long set of symbols. Even if I am not trying
to look at wx stuff, I have so many symbols that I am afraid to do a
dir(). I attempted to solve this, at least for the purposes of
learning wxPython, and this is what I wound up with:
I have a module (wxx.py), which simply imports wxPython.wx and
tries to classify each symbol into a "place it belongs".
One of the things I've noticed is that wxPython recapitulates each
symbol's prevenance in its name. I (strongly) suspect this has a
lot to do with the SWIG wrapping of the wxWindow code. Since one
of my goals was to enable simple translation from existing wxPython
code, here's what I came up with:
instead of:
from wxPython.wx import *
use:
from wxx import * # Or wxPython.wxx or whatever
Then in subsequent text:
For: Substitute:
WXK_NUMPAD_NAME WXK_NUMPAD.NAME
WXK_NAME WXK.NAME
IDM_NAME IDM.NAME
EVT_COMMAND_NAME EVT_COMMAND.NAME
EVT_LIST_NAME EVT_LIST.NAME
EVT_SCROLLWIN_NAME EVT_SCROLLWIN.NAME
EVT_SCROLL_NAME EVT_SCROLL.NAME
EVT_NAME EVT.NAME
wxALL_CAPS_NAME WX.ALL_CAPS_NAME
wxOtherName wx.OtherName
cvar Misc.cvar
NewId Misc.NewId
localedir Misc.localedir
RegisterId Misc.RegisterId
We will have code that copies in 11 symbols, rather than 2746 symbols.
The core of the problem that I see here is that SWIG uses a flat
namespace as the model of providing symbols, rather than allowing
structured names. Since Python is particularly good at namespaces,
Python is particularly penalized by this mapping.
The code for wxx.py is rather simple and boring if you agree about
the causes, and it is irrelevant if you don't find my arguments about
importing many symbols persuasive. If this is the way to go, lots
of wxPython modules should be recoded to use this scheme.
Very roughly, the code of wxx.py looks like:
import wxPython.wx
<define a class Identifier(prefix)>
_prefixed = [(n, Identifier(n[:-1])) for n in ('IDM_ WXK_NUMPAD_ WXK_ '
'EVT_LIST_ EVT_COMMAND_ EVT_SCROLLWIN_ EVT_SCROLL_ EVT_').split()]
IDM, WXK_NUMPAD, WXK, EVT_LIST, EVT_COMMAND, EVT_SCROLLWIN, \
\ EVT_SCROLL, EVT_ = [obj for name, obj in _prefixed]
WX = Identifier('wx')
wx = Identifier('wx')
Misc = Identifier('')
wxPwx = wxPython.wx
for name in dir(wxPwx):
for prefix, obj in _prefixed:
if name.startswith(prefix):
setattr(obj, name[len(prefix):], getattr(wxPwx, name))
break
else:
if name.startswith('wx'):
if name[2:] == name[2:].upper():
setattr(WX, name[2:], getattr(wxPwx, name))
else:
setattr(wx, name[2:], getattr(wxPwx, name))
else:
setattr(Misc, name, getattr(wxPwx, name))
Reactions? Does this sound useful or a waste? The idea came from
seeing a many-module wxPython app where every module begins with
"from wxPython.wx import *".
-Scott David Daniels
Scott.Daniels@Acm.Org