r4 - 08 Jul 2003 - 10:31:25 - KaitlinDuckSherwoodYou are here: OSAF >  Projects Web  >  ChandlerHome > DeveloperDocumentation > HowToWriteAParcelTutorial > HookingUpEvents

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

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r4 < r3 < r2 < r1 | More topic actions
 
Open Source Applications Foundation
Except where otherwise noted, this site and its content are licensed by OSAF under an Creative Commons License, Attribution Only 3.0.
See list of page contributors for attributions.