Hi all,
I've got an app that runs the MainApp, builds the MainFrame, and
instantiates a wxSplitterWindow all inside one script (say "one.py").
I then build additional scripts ("two.py") that have a two.Panel,
two.Menubar, two.Toolbar and two.EventHandler in each.
I've written a method in my MainFrame class called "Swap" that has the
function of reading in the new classes, setting the menubar and toolbar,
calling wxSplitterWindow.ReplaceWindow (to swap out the panel being
displayed), and finally calling PopEventHandler and PushEventHandler. The
code for this method is at the end of the post.
Everything is pretty-much working so far, except for a couple of little
quirks. The real problem, though, is that I don't think importing the module
inside a method of MainFrame is making the event IDs (i.e.
ID_Whatever=wxNewId() ) available for processing. So, everything displays -
but nothing responds. I can't put all the id's inside the main script
because I'm shooting for add-on modules - so I won't know which modules the
user has installed or even which ones I might decide to make in the future.
Any guidance on how to read in those id's from the called script, into a
method (i.e. "local") and still make the event handler work?
Code for the swap method (don't laugh, Robin, I'm just a beginner). Import
statements are replicated in multiple locations because of the possibility
of calling swap to only replace a single item - the menu for instance - and
leaving all the others alone. Only Pop&PushEventHandler is always executed.
def Swap(self, package='package', pmod='module', pclass='class',
menubar='menubar', toolbar='toolbar', events='events'):
global PANEL, REVERT
global frame_1, window_1, pane_2
if package != 'package':
REVERT['package'], PANEL['package'] = PANEL['package'], package
if pmod != 'module':
REVERT['module'], PANEL['module'] = PANEL['module'], pmod
if pclass != 'class':
self.oldpanel, REVERT['class'], PANEL['class'] =
PANEL['oldpanel'], PANEL['class'], pclass
exec 'import ' + PANEL['package'] + "." + PANEL['module']
self.newtarget = eval(PANEL['package'] + "." + PANEL['module'] +
"." + PANEL['class'])
self.newpanel = self.newtarget(PANEL, window_1, -1)
PANEL['oldpanel']= self.newpanel
window_1.ReplaceWindow(self.oldpanel, self.newpanel)
self.oldpanel.Destroy()
if menubar != 'menubar':
REVERT['menubar'], PANEL['menubar'] = PANEL['menubar'], menubar
exec 'import ' + PANEL['package'] + "." + PANEL['module']
self.newmenutarget = eval(PANEL['package'] + "." +
PANEL['module'] + "." + PANEL['menubar'])
self.SetMenuBar(self.newmenutarget())
if toolbar != 'toolbar':
REVERT['toolbar'], PANEL['toolbar'] = PANEL['toolbar'], toolbar
exec 'import ' + PANEL['package'] + "." + PANEL['module']
self.newtooltarget = eval(PANEL['package'] + "." +
PANEL['module'] + "." + PANEL['toolbar'])
self.SetToolBar(self.newtooltarget(self, -1))
if events != 'events':
REVERT['events'], PANEL['events'] = PANEL['events'], events
frame_1.PopEventHandler()
try:
frame_1.PushEventHandler(PANEL['events'](frame_1, window_1,
pane_2, PANEL['menubar'], PANEL['toolbar']))
except:
frame_1.PushEventHandler(REVERT['events'](frame_1, window_1,
pane_2, PANEL['menubar'], PANEL['toolbar']))
self.Layout()