Mercurial > fife-parpg
annotate engine/extensions/pychan/events.py @ 220:6d09d310943b
Pass mouseWheelMovedUp and mouseWheelMovedDown events to pychan.
Fixed(?) dragging, mouse events are proceessed by the GUI if the last move was inside the gui.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 19 Mar 2009 18:23:00 +0000 |
parents | e281223a03a6 |
children | f10a35efebc0 |
rev | line source |
---|---|
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
1 # -*- coding: utf-8 -*- |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 #coding: utf-8 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 """ |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 PyChan event handling |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 ===================== |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 Users shouldn't need to use this module directly. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 L{widgets.Widget.capture} and L{widgets.Widget.mapEvents} provide |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 a convenient API to capture events. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 Nevertheless to understand how its supposed to work |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 take a look at L{EventMapper} and L{EventListener} |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
15 Event callbacks |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
16 --------------- |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
17 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
18 You can either write callbacks yourself or |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
19 use L{tools.callBackWithArguments} or L{tools.attrSetCallback} |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
20 to generate suitable callbacks. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
21 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
22 Here's an example callback:: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
23 def dumpEventInfo(event=0,widget=0): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
24 print widget, " received the event ", event |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
25 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
26 Note the signature - C{event} and C{widget} are keyword |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
27 arguments passed to the callback. If doesn't accept either |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
28 C{event} or C{widget} as argument, these are not passed. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
29 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
30 This way a simple function which ignores C{event} or C{widget} |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
31 can be used, while they are available if needed. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
32 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
33 Currently only one callback can be set per event. In case |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
34 you don't want to write your own callback that dispatches |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
35 to different callbacks you can use L{tools.chainCallbacks}. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
36 |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 Available Events |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 ---------------- |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 """ |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
42 from compat import guichan |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
43 |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 import exceptions |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
45 from internal import get_manager |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 import tools |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
47 import traceback |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 EVENTS = [ |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 "mouseEntered", |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 "mouseExited", |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 "mousePressed", |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 "mouseReleased", |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 "mouseClicked", |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 "mouseMoved", |
220
6d09d310943b
Pass mouseWheelMovedUp and mouseWheelMovedDown events to pychan.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
208
diff
changeset
|
56 "mouseWheelMovedUp", |
6d09d310943b
Pass mouseWheelMovedUp and mouseWheelMovedDown events to pychan.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
208
diff
changeset
|
57 "mouseWheelMovedDown", |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 "mouseDragged", |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 "action", |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 "keyPressed", |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 "keyReleased", |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 ] |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 # Add the EVENTS to the docs. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 __doc__ += "".join([" - %s\n" % event for event in EVENTS]) |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
67 # The line before seems to leak the variable event into the global namespace ... remove that! |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
68 # This is a python problem, addressed in python3 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
69 try: del event |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
70 except:pass |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
71 |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 MOUSE_EVENT, KEY_EVENT, ACTION_EVENT = range(3) |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 def getEventType(name): |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 if "mouse" in name: |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 return MOUSE_EVENT |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 if "key" in name: |
164 | 77 return KEY_EVENT |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 return ACTION_EVENT |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 CALLBACK_NONE_MESSAGE = """\ |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 You passed None as parameter to %s.capture, which would normally remove a mapped event. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 But there was no event mapped. Did you accidently call a function instead of passing it? |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 """ |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
85 class EventListenerBase(object): |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 """ |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 Redirector for event callbacks. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 Use *only* from L{EventMapper}. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 This class uses the SWIG director feature - overriden |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
91 virtual methods are called from C++ to - listen to |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 Guichan events. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
94 """ |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
95 def __init__(self): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
96 super(EventListenerBase,self).__init__() |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 self.events = {} |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 self.indent = 0 |
208
e281223a03a6
Rejoice. PyChan debug messages removed.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
205
diff
changeset
|
99 self.debug = get_manager().debug |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
100 self.is_attached = False |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
101 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
102 def attach(self,widget): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
103 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
104 Start receiving events. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
105 No need to call this manually. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
106 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
107 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
108 if self.is_attached: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
109 return |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
110 if not self.events: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
111 return |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
112 if self.debug: print "Attach:",self |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
113 self.doAttach(widget.real_widget) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
114 self.widget = widget |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
115 self.is_attached = True |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
116 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
117 def detach(self): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
118 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
119 Stop receiving events. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
120 No need to call this manually. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
121 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
122 if not self.is_attached: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
123 return |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
124 if self.debug: print "Detach:",self |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
125 self.doDetach(self.widget.real_widget) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
126 self.widget = None |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
127 self.is_attached = False |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
128 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
129 def _redirectEvent(self,name,event): |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
130 self.indent += 4 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
131 try: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
132 event = self.translateEvent(getEventType(name), event) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
133 if name in self.events: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
134 if self.debug: print "-"*self.indent, name |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
135 for f in self.events[name].itervalues(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
136 f( event ) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
137 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
138 except: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
139 print name, event |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
140 traceback.print_exc() |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
141 raise |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
142 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
143 finally: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
144 self.indent -= 4 |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
145 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
146 def translateEvent(self,event_type,event): |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
147 if event_type == MOUSE_EVENT: |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
148 return get_manager().hook.translate_mouse_event(event) |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
149 if event_type == KEY_EVENT: |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
150 return get_manager().hook.translate_key_event(event) |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
151 return event |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
152 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
153 class _ActionEventListener(EventListenerBase,guichan.ActionListener): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
154 def __init__(self):super(_ActionEventListener,self).__init__() |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
155 def doAttach(self,real_widget): real_widget.addActionListener(self) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
156 def doDetach(self,real_widget): real_widget.removeActionListener(self) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
157 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
158 def action(self,e): self._redirectEvent("action",e) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
159 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
160 class _MouseEventListener(EventListenerBase,guichan.MouseListener): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
161 def __init__(self):super(_MouseEventListener,self).__init__() |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
162 def doAttach(self,real_widget): real_widget.addMouseListener(self) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
163 def doDetach(self,real_widget): real_widget.removeMouseListener(self) |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
164 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
165 def mouseEntered(self,e): self._redirectEvent("mouseEntered",e) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
166 def mouseExited(self,e): self._redirectEvent("mouseExited",e) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
167 def mousePressed(self,e): self._redirectEvent("mousePressed",e) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
168 def mouseReleased(self,e): self._redirectEvent("mouseReleased",e) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
169 def mouseClicked(self,e): self._redirectEvent("mouseClicked",e) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
170 def mouseMoved(self,e): self._redirectEvent("mouseMoved",e) |
220
6d09d310943b
Pass mouseWheelMovedUp and mouseWheelMovedDown events to pychan.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
208
diff
changeset
|
171 def mouseWheelMovedUp(self,e): self._redirectEvent("mouseWheelMovedUp",e) |
6d09d310943b
Pass mouseWheelMovedUp and mouseWheelMovedDown events to pychan.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
208
diff
changeset
|
172 def mouseWheelMovedDown(self,e): self._redirectEvent("mouseWheelMovedDown",e) |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
173 def mouseDragged(self,e): self._redirectEvent("mouseDragged",e) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
174 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
175 class _KeyEventListener(EventListenerBase,guichan.KeyListener): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
176 def __init__(self):super(_KeyEventListener,self).__init__() |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
177 def doAttach(self,real_widget): real_widget.addKeyListener(self) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
178 def doDetach(self,real_widget): real_widget.removeKeyListener(self) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
179 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
180 def keyPressed(self,e): self._redirectEvent("keyPressed",e) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
181 def keyReleased(self,e): self._redirectEvent("keyReleased",e) |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
182 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
183 class EventMapper(object): |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
184 """ |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
185 Handles events and callbacks for L{widgets.Widget} |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
186 and derived classes. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
187 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
188 Every PyChan widget has an L{EventMapper} instance |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
189 as attribute B{event_mapper}. |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
190 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
191 This instance handles all necessary house-keeping. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
192 Such an event mapper can be either *attached* or |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
193 *detached*. In its attached state an L{EventListener} |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
194 is added to the Guichan widget and will redirect |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
195 the events to the callbacks. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
196 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
197 In its detached state no events are received from the |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
198 real Guichan widget. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
199 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
200 The event mapper starts in the detached state. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
201 When a new event is captured the mapper attaches itself |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
202 automatically. The widget doesn't need to handle that. |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
203 """ |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
204 def __init__(self,widget): |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
205 super(EventMapper,self).__init__() |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
206 self.widget = widget |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
207 self.listener = { |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
208 KEY_EVENT : _KeyEventListener(), |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
209 ACTION_EVENT : _ActionEventListener(), |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
210 MOUSE_EVENT : _MouseEventListener(), |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
211 } |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
212 self.is_attached = False |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
213 self.debug = get_manager().debug |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
214 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
215 def __repr__(self): |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
216 return "EventMapper(%s)" % repr(self.widget) |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
217 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
218 |
164 | 219 def capture(self,event_name,callback,group_name): |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
220 if event_name not in EVENTS: |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
221 raise exceptions.RuntimeError("Unknown eventname: " + event_name) |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
222 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
223 if callback is None: |
166
81a222e7bd25
Fixes for event handling.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
164
diff
changeset
|
224 if self.isCaptured(event_name,group_name): |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
225 self.removeEvent(event_name,group_name) |
164 | 226 elif self.debug: |
188
06dddc96ce54
* Fixed some space and tab mixing
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
166
diff
changeset
|
227 print CALLBACK_NONE_MESSAGE % str(self.widget) |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
228 return |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
229 self.addEvent(event_name,callback,group_name) |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
230 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
231 def isCaptured(self,event_name,group_name="default"): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
232 return ("%s/%s" % (event_name,group_name)) in self.getCapturedEvents() |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
233 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
234 def getCapturedEvents(self): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
235 events = [] |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
236 for event_type, listener in self.listener.items(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
237 for event_name, group in listener.events.items(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
238 for group_name in group.keys(): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
239 events.append( "%s/%s" % (event_name, group_name) ) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
240 return events |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
241 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
242 def getListener(self,event_name): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
243 return self.listener[getEventType(event_name)] |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
244 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
245 def removeEvent(self,event_name,group_name): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
246 listener = self.getListener(event_name) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
247 del listener.events[event_name][group_name] |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
248 if not listener.events[event_name]: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
249 del listener.events[event_name] |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
250 if not listener.events: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
251 listener.detach() |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
252 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
253 def addEvent(self,event_name,callback,group_name): |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
254 if not callable(callback): |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
255 raise RuntimeError("An event callback must be either a callable or None - not %s" % repr(callback)) |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
256 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
257 def captured_f(event): |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
258 tools.applyOnlySuitable(callback,event=event,widget=self.widget) |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
259 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
260 listener = self.getListener(event_name) |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
261 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
262 if event_name not in listener.events: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
263 listener.events[event_name] = {group_name : captured_f} |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
264 else: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
265 listener.events[event_name][group_name] = captured_f |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
266 listener.attach(self.widget) |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
267 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
268 |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
269 def splitEventDescriptor(name): |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
270 """ Utility function to split "widgetName/eventName" descriptions into tuples. """ |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
271 L = name.split("/") |
164 | 272 if len(L) not in (1,2,3): |
273 raise exceptions.RuntimeError("Invalid widgetname / eventname combination: " + name) | |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
274 if len(L) == 1: |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
275 L = L[0],"action" |
164 | 276 elif L[1] not in EVENTS: |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
277 raise exceptions.RuntimeError("Unknown event name: " + name) |
164 | 278 if len(L) == 2: |
279 L = L[0],L[1],"default" | |
157
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
280 return L |
bb9902910067
input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
281 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
188
diff
changeset
|
282 |