###################################################################### # Copyright (c) 2007, Petteri Aimonen # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # * Redistributions of source code must retain the above copyright # notice and this list of conditions. # * Redistributions in binary form must reproduce the above copyright # notice and this list of conditions in the documentation and/or other # materials provided with the distribution. '''Custom events''' import wx import wx.lib.newevent def NewPropagatingEvent(): evttype = wx.NewEventType() evtbinder = wx.PyEventBinder(evttype, 1) # 1 is just a dummy id evtcreator = lambda t = evttype: wx.PyCommandEvent(t, 1) return evtcreator, evtbinder # Timeframe selection has changed - emitted by TimePanel (TimeframeEvent, EVT_TIMEFRAME) = NewPropagatingEvent() # Graph should be updated - emitted by Navigator # Note: won't propagate because Navigator has no parent (GraphUpdateEvent, EVT_GRAPHUPDATE) = NewPropagatingEvent() # Data reload has been requested - emitted from toolbar (DataReloadEvent, EVT_DATARELOAD) = NewPropagatingEvent() # User has clicked graph or log link to change node # Event.userdata is the node userdata, like ('animal', 1234) # Causes goto and also switches to graph page (NodeSelectEvent, EVT_NODESELECT) = NewPropagatingEvent() # Tree structure has changed - emitted by AnimalView # currently if animal is moved (TreeChangeEvent, EVT_TREECHANGE) = NewPropagatingEvent() if __name__ == '__main__': print "Unit testing" (EventA, EVT_A) = NewPropagatingEvent() (EventB, EVT_B) = NewPropagatingEvent() class MyWindow(wx.Frame): def __init__(self): wx.Frame.__init__(self, None) self.count = 0 self.b = wx.Button(self) self.b.Bind(wx.EVT_BUTTON, self.sendevent) def sendevent(self, evt = None): self.count += 1 print "Sent event no.", self.count if self.count % 2: evt = EventA() else: evt = EventB() wx.PostEvent(self, evt) class MyApp(wx.App): def OnInit(self): w = MyWindow() w.Show() self.Bind(EVT_A, self.oneventA) self.Bind(EVT_B, self.oneventB) return True def oneventA(self, evt = None): print "Got eventA:", repr(evt) def oneventB(self, evt = None): print "Got eventB:", repr(evt) app = MyApp(0) app.MainLoop()