]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-03/customEvent.py
3 class TwoButtonEvent(wx
.PyCommandEvent
):
4 def __init__(self
, evtType
, id):
5 wx
.PyCommandEvent
.__init
__(self
, evtType
, id)
8 def GetClickCount(self
):
11 def SetClickCount(self
, count
):
12 self
.clickCount
= count
14 myEVT_TWO_BUTTON
= wx
.NewEventType()
15 EVT_TWO_BUTTON
= wx
.PyEventBinder(myEVT_TWO_BUTTON
, 1)
17 class TwoButtonPanel(wx
.Panel
):
18 def __init__(self
, parent
, id=-1, leftText
="Left",
20 wx
.Panel
.__init
__(self
, parent
, id)
21 self
.leftButton
= wx
.Button(self
, label
=leftText
)
22 self
.rightButton
= wx
.Button(self
, label
=rightText
,
24 self
.leftClick
= False
25 self
.rightClick
= False
27 self
.leftButton
.Bind(wx
.EVT_LEFT_DOWN
, self
.OnLeftClick
)
28 self
.rightButton
.Bind(wx
.EVT_LEFT_DOWN
, self
.OnRightClick
)
30 def OnLeftClick(self
, event
):
35 def OnRightClick(self
, event
):
36 self
.rightClick
= True
42 if self
.leftClick
and self
.rightClick
:
43 self
.leftClick
= False
44 self
.rightClick
= False
45 evt
= TwoButtonEvent(myEVT_TWO_BUTTON
, self
.GetId())
46 evt
.SetClickCount(self
.clickCount
)
47 self
.GetEventHandler().ProcessEvent(evt
)
50 class CustomEventFrame(wx
.Frame
):
51 def __init__(self
, parent
, id):
52 wx
.Frame
.__init
__(self
, parent
, id, 'Click Count: 0',
54 panel
= TwoButtonPanel(self
)
55 self
.Bind(EVT_TWO_BUTTON
, self
.OnTwoClick
, panel
)
57 def OnTwoClick(self
, event
):
58 self
.SetTitle("Click Count: %s" % event
.GetClickCount())
60 if __name__
== '__main__':
61 app
= wx
.PySimpleApp()
62 frame
= CustomEventFrame(parent
=None, id=-1)