]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_event_ex.py
3 #---------------------------------------------------------------------------
5 class PyEventBinder(object):
7 Instances of this class are used to bind specific events to event
10 def __init__(self
, evtType
, expectedIDs
=0):
11 if expectedIDs
not in [0, 1, 2]:
12 raise ValueError, "Invalid number of expectedIDs"
13 self
.expectedIDs
= expectedIDs
15 if type(evtType
) == list or type(evtType
) == tuple:
16 self
.evtType
= evtType
18 self
.evtType
= [evtType
]
21 def Bind(self
, target
, id1
, id2
, function
):
22 """Bind this set of event types to target."""
23 for et
in self
.evtType
:
24 target
.Connect(id1
, id2
, et
, function
)
27 def Unbind(self
, target
, id1
, id2
):
28 """Remove an event binding."""
30 for et
in self
.evtType
:
31 success
+= target
.Disconnect(id1
, id2
, et
)
34 def _getEvtType(self
):
36 Make it easy to get to the default wxEventType typeID for this
39 return self
.evtType
[0]
41 typeId
= property(_getEvtType
)
44 def __call__(self
, *args
):
46 For backwards compatibility with the old EVT_* functions.
47 Should be called with either (window, func), (window, ID,
48 func) or (window, ID1, ID2, func) parameters depending on the
51 assert len(args
) == 2 + self
.expectedIDs
55 if self
.expectedIDs
== 0:
57 elif self
.expectedIDs
== 1:
60 elif self
.expectedIDs
== 2:
65 raise ValueError, "Unexpected number of IDs"
67 self
.Bind(target
, id1
, id2
, func
)
70 # These two are square pegs that don't fit the PyEventBinder hole...
71 def EVT_COMMAND(win
, id, cmd
, func
):
72 win
.Connect(id, -1, cmd
, func
)
73 def EVT_COMMAND_RANGE(win
, id1
, id2
, cmd
, func
):
74 win
.Connect(id1
, id2
, cmd
, func
)
77 #---------------------------------------------------------------------------