Connecting Control Widgets and Events In Your Parcel
Once you have an XRC file, you need to connect the widgets in the XRC file to event handlers. In your subclass of wxViewerParcel (e.g. wxFooViewer on the
HookingIntoChandler page), you need to create an
event table in the
OnInit method.
Event tables are sets of commands that use event macros. They connect an XRC widget -- via its name -- to a method that handles the event. The following event table is an example of how you might wire the widgets from the
XRC examples, with the XRC name highlighted in red:
EVT_BUTTON(self, XRCID('FooButton'), self.OnFooButton)
EVT_RADIOBOX(self, XRCID('FooRadioBox'), self.OnFooRadioBox)
EVT_TEXT_ENTER(self, XRCID('FooTextEntry'), self.OnFooTextEntry)
(Note that the
FooText wxStaticText example item doesn't appear in the event table above because text doesn't register events.)
The final parameter in each event table line is the method that will handle the event. For example, you could have a method in wxFooViewer:
def OnFooButton(self, event):
wxMessageBox(_("You pushed the Foo Button"))
For menus, the corresponding event table example is:
EVT_MENU(self, XRCID('FooMenu'), self.OnFooMenu)
The best documentation for controls is in the
wxWindows manual (search down for
wxControl to get to the Controls section). Unfortunately, these pages document
wxWindows controls, not
wxPython controls, so you will have to do some mental translation from C to Python.
--
DuckySherwood - 09 Apr 2003