Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a custom CommandEvent in wxPython

Tags:

wxpython

My top-level window needs to know when the internal state of a custom control changes so it can update various other parts of the GUI. How do I generate a custom event in the control, so it can propagate and be handled by the top-level window?

like image 220
Vebjorn Ljosa Avatar asked Mar 12 '09 19:03

Vebjorn Ljosa


1 Answers

I know this is an old question, but there is a newer, slightly nicer, way to do this in wxPython. Paraphrased from http://wiki.wxpython.org/CustomEventClasses and the above:

To define the event:

import wx.lib.newevent
QuantityChangedEvent, EVT_QUANTITY_CHANGED = wx.lib.newevent.NewCommandEvent()

To generate an event:

event = QuantityChangedEvent(self.GetId())
self.GetEventHandler().ProcessEvent(event)
# or ...
#wx.PostEvent(self, event)

Binding the event remains the same.

like image 60
Alan Briolat Avatar answered Sep 19 '22 18:09

Alan Briolat