]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/PythonEvents.py
added missing methods/removed duplicated base methods
[wxWidgets.git] / wxPython / demo / PythonEvents.py
CommitLineData
65dd82cb
RD
1
2from wxPython.wx import *
3import sys
4
5#----------------------------------------------------------------------
6
d56cebe7 7myEVT_BUTTON_CLICKPOS = wxNewEventType()
65dd82cb
RD
8
9def EVT_BUTTON_CLICKPOS(win, id, func):
10 win.Connect(id, -1, myEVT_BUTTON_CLICKPOS, func)
11
12
13
14class MyEvent(wxPyCommandEvent):
15 def __init__(self, evtType, id):
16 wxPyCommandEvent.__init__(self, evtType, id)
17 self.myVal = None
18
19 #def __del__(self):
20 # print '__del__'
21 # wxPyCommandEvent.__del__(self)
22
23 def SetMyVal(self, val):
24 self.myVal = val
25
26 def GetMyVal(self):
27 return self.myVal
28
29
30
31class MyButton(wxButton):
32 def __init__(self, parent, id, txt, pos):
33 wxButton.__init__(self, parent, id, txt, pos)
34 EVT_LEFT_DOWN(self, self.OnLeftDown)
35
36 def OnLeftDown(self, event):
37 pt = event.GetPosition()
38 evt = MyEvent(myEVT_BUTTON_CLICKPOS, self.GetId())
39 evt.SetMyVal(pt)
40 #print id(evt), sys.getrefcount(evt)
41 self.GetEventHandler().ProcessEvent(evt)
42 #print id(evt), sys.getrefcount(evt)
43 event.Skip()
44
45
46
47class TestPanel(wxPanel):
48 def __init__(self, parent, log):
49 wxPanel.__init__(self, parent, -1)
50 self.log = log
51
52 b = MyButton(self, -1, " Click me ", wxPoint(30,30))
53 EVT_BUTTON(self, b.GetId(), self.OnClick)
54 EVT_BUTTON_CLICKPOS(self, b.GetId(), self.OnMyEvent)
55
56 wxStaticText(self, -1, "Please see the Overview and Demo Code for details...",
57 wxPoint(30, 80))
58
59
60 def OnClick(self, event):
61 self.log.WriteText("OnClick\n")
62
63 def OnMyEvent(self, event):
64 #print id(event), sys.getrefcount(event)
65 self.log.WriteText("MyEvent: %s\n" % (event.GetMyVal(), ) )
66
67
68#----------------------------------------------------------------------
69
70def runTest(frame, nb, log):
71 win = TestPanel(nb, log)
72 return win
73
74#----------------------------------------------------------------------
75
76
77
78
79overview = """\
80This demo is a contrived example of defining an event class in wxPython and sending it up the containment heirachy for processing.
81"""
82
83
84
85