]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/PythonEvents.py
2 from wxPython
.wx
import *
5 #----------------------------------------------------------------------
7 myEVT_BUTTON_CLICKPOS
= wxNewEventType()
9 def EVT_BUTTON_CLICKPOS(win
, id, func
):
10 win
.Connect(id, -1, myEVT_BUTTON_CLICKPOS
, func
)
14 class MyEvent(wxPyCommandEvent
):
15 def __init__(self
, evtType
, id):
16 wxPyCommandEvent
.__init
__(self
, evtType
, id)
21 # wxPyCommandEvent.__del__(self)
23 def SetMyVal(self
, val
):
31 class 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
)
36 def OnLeftDown(self
, event
):
37 pt
= event
.GetPosition()
38 evt
= MyEvent(myEVT_BUTTON_CLICKPOS
, self
.GetId())
40 #print id(evt), sys.getrefcount(evt)
41 self
.GetEventHandler().ProcessEvent(evt
)
42 #print id(evt), sys.getrefcount(evt)
47 class TestPanel(wxPanel
):
48 def __init__(self
, parent
, log
):
49 wxPanel
.__init
__(self
, parent
, -1)
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
)
56 wxStaticText(self
, -1, "Please see the Overview and Demo Code for details...",
60 def OnClick(self
, event
):
61 self
.log
.WriteText("OnClick\n")
63 def OnMyEvent(self
, event
):
64 #print id(event), sys.getrefcount(event)
65 self
.log
.WriteText("MyEvent: %s\n" % (event
.GetMyVal(), ) )
68 #----------------------------------------------------------------------
70 def runTest(frame
, nb
, log
):
71 win
= TestPanel(nb
, log
)
74 #----------------------------------------------------------------------
80 This demo is a contrived example of defining an event class in wxPython and sending it up the containment heirachy for processing.
88 if __name__
== '__main__':
91 run
.main(['', os
.path
.basename(sys
.argv
[0])])