Creating custom event in WxPython
Sion Arrowsmith
siona at chiark.greenend.org.uk
Thu Sep 1 09:31:22 EDT 2005
<NutJob at gmx.net> wrote:
>Now when my socket thread detects an incoming message, I need my main
>thread to interpret the message and react to it by updating the GUI.
>IMO the best way to achieve this is by having my socket thread send a
>custom event to my application's event loop for the main thread to
>process. However, I'm at a total loss as far as creating custom events
>is concerned. The WxWindows documentation isn't very helpful on this
>either.
>I think I need to derive my own event class from the wxEvent class, but
>I have no idea HOW (i.e. what methods do I need to override, etc.) Can
>anyone help me?
(a) Consider whether you can do what you want with CallAfter().
(b) If you do have to go with a custom event, the idiom I've got here
is:
EVT_CUSTOM_WITH_DATA_ID = wxNewId()
def EVT_CUSTOM_WITH_DATA(win, func):
win.Connect(-1, -1, EVT_CUSTOM_WITH_DATA_ID, func)
class CustomWithDataEvent(wxPyEvent):
def __init__(self, data=None):
wxPyEvent.__init__(self)
self.data = data
self.SetEventType(EVT_CUSTOM_WITH_DATA_ID)
def Clone(self):
return CustomWithDataEvent(self.data)
but do note that this is for wxPython2.4 -- amongst other differences,
EVT_CUSTOM_WITH_DATA() should be unnecessary in 2.6 (used Bind()
instead).
--
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
More information about the Python-list
mailing list