Don't understand wxPython event handling
Robin Dunn
robin at alldunn.NOSPAM.com
Thu Apr 1 17:46:31 EST 2004
Robert wrote:
> Hello list,
>
> could somebody point me to a good reference about wxPython event handling?
> I have seen many examples but which one is the best. Waht are the advantages
> and disadvantages?
http://wiki.wxpython.org/index.cgi/RecipesEvents
http://wxwidgets.org/manuals/2.5.1/wx_eventhandlingoverview.html
The wxPython demo
etc.
>
> Can you also have a short look at the example below and give me some
> comments, please?
>
> Example:
> I have implemented (or copied from somewhere) one event in two flavours.
> Both work, but which one is the best? Or does anybody have a better
> implementation.
>
> EVT_NEXT_PAGE_ID = wxNewId()
wxNewId is meant for window/menuItem/toolbarItem IDs. wxNewEventType
should be used for, uh, new eventTypes ;-)
>
> def EVT_NEXT_PAGE( win, func ):
> """Your documentation here"""
> win.Connect( -1, -1, EVT_NEXT_PAGE_ID, func )
>
> class showNextPageEvent(wxPyEvent):
> def __init__(self, windowID):
> wxPyEvent.__init__(self)
> self.SetEventType(EVT_NEXT_PAGE_ID)
>
This is fine (or deriving from wxPyCommandEvent if you want the event to
propgate to parent windows,) but even better is to use the newevent
module in the wxPython library. It contains functions that generate on
the fly an event class and binder function similar to the above for you,
but it will help your code to be future proof in case things change in
future releases.
import wx.lib.newevent
showNextPageEvent, EVT_NEXT_PAGE = wx.lib.newevent.NewEvent()
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the Python-list
mailing list