1 | ############################################################################ |
---|
2 | # |
---|
3 | # DIM - A Direct Interaction Manager for SAGE |
---|
4 | # Copyright (C) 2007 Electronic Visualization Laboratory, |
---|
5 | # University of Illinois at Chicago |
---|
6 | # |
---|
7 | # All rights reserved. |
---|
8 | # |
---|
9 | # Redistribution and use in source and binary forms, with or without |
---|
10 | # modification, are permitted provided that the following conditions are met: |
---|
11 | # |
---|
12 | # * Redistributions of source code must retain the above copyright |
---|
13 | # notice, this list of conditions and the following disclaimer. |
---|
14 | # * Redistributions in binary form must reproduce the above |
---|
15 | # copyright notice, this list of conditions and the following disclaimer |
---|
16 | # in the documentation and/or other materials provided with the distribution. |
---|
17 | # * Neither the name of the University of Illinois at Chicago nor |
---|
18 | # the names of its contributors may be used to endorse or promote |
---|
19 | # products derived from this software without specific prior written permission. |
---|
20 | # |
---|
21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
22 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
23 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
24 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
25 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
26 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
27 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
28 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
29 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
30 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | # |
---|
33 | # Direct questions, comments etc about SAGE UI to www.evl.uic.edu/cavern/forum |
---|
34 | # |
---|
35 | # Author: Ratko Jagodic |
---|
36 | # |
---|
37 | ############################################################################ |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | from globals import * |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | class Event: |
---|
47 | """ the base class for all the events """ |
---|
48 | |
---|
49 | def __init__(self, eventId, eventType, toEvtHandler=None): |
---|
50 | self.eventType = eventType |
---|
51 | self.eventId = eventId |
---|
52 | self.toEvtHandler = toEvtHandler |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | #----------------------------------------------------- |
---|
57 | # DEVICE EVENTS (position dependent) |
---|
58 | #----------------------------------------------------- |
---|
59 | |
---|
60 | |
---|
61 | class MoveEvent(Event): |
---|
62 | |
---|
63 | def __init__(self, device, newX, newY, dX, dY, toEvtHandler=None): |
---|
64 | if device.specialDevice: |
---|
65 | evtId = EVT_MOVE_SPECIAL |
---|
66 | else: |
---|
67 | evtId = EVT_MOVE |
---|
68 | Event.__init__(self, evtId, DEVICE_EVENT, toEvtHandler) |
---|
69 | self.device = device |
---|
70 | self.x = newX |
---|
71 | self.y = newY |
---|
72 | self.dX = dX |
---|
73 | self.dY = dY |
---|
74 | |
---|
75 | |
---|
76 | class ClickEvent(Event): |
---|
77 | |
---|
78 | def __init__(self, device, x, y, btnId, isDown, forEvt, toEvtHandler=None): |
---|
79 | if device.specialDevice: |
---|
80 | evtId = EVT_CLICK_SPECIAL |
---|
81 | else: |
---|
82 | evtId = EVT_CLICK |
---|
83 | Event.__init__(self, evtId, DEVICE_EVENT, toEvtHandler) |
---|
84 | self.device = device |
---|
85 | self.x = x |
---|
86 | self.y = y |
---|
87 | self.btnId = btnId |
---|
88 | self.isDown = isDown |
---|
89 | self.forEvt = forEvt |
---|
90 | |
---|
91 | |
---|
92 | class Analog1Event(Event): |
---|
93 | |
---|
94 | def __init__(self, device, x, y, dX, dY, dZ, toEvtHandler=None): |
---|
95 | if device.specialDevice: |
---|
96 | evtId = EVT_ANALOG1_SPECIAL |
---|
97 | else: |
---|
98 | evtId = EVT_ANALOG1 |
---|
99 | Event.__init__(self, evtId, DEVICE_EVENT, toEvtHandler) |
---|
100 | self.device = device |
---|
101 | self.x = x |
---|
102 | self.y = y |
---|
103 | self.dX = dX |
---|
104 | self.dY = dY |
---|
105 | self.dZ = dZ |
---|
106 | |
---|
107 | |
---|
108 | class Analog2Event(Event): |
---|
109 | |
---|
110 | def __init__(self, device, x, y, dX, dY, dZ, angle, toEvtHandler=None): |
---|
111 | if device.specialDevice: |
---|
112 | evtId = EVT_ANALOG2_SPECIAL |
---|
113 | else: |
---|
114 | evtId = EVT_ANALOG2 |
---|
115 | Event.__init__(self, evtId, DEVICE_EVENT, toEvtHandler) |
---|
116 | self.device = device |
---|
117 | self.x = x |
---|
118 | self.y = y |
---|
119 | self.dX = dX |
---|
120 | self.dY = dY |
---|
121 | self.dZ = dZ |
---|
122 | self.angle = angle |
---|
123 | |
---|
124 | |
---|
125 | class Analog3Event(Event): |
---|
126 | |
---|
127 | def __init__(self, device, x, y, dX, dY, dZ, toEvtHandler=None): |
---|
128 | if device.specialDevice: |
---|
129 | evtId = EVT_ANALOG3_SPECIAL |
---|
130 | else: |
---|
131 | evtId = EVT_ANALOG3 |
---|
132 | Event.__init__(self, evtId, DEVICE_EVENT, toEvtHandler) |
---|
133 | self.device = device |
---|
134 | self.x = x |
---|
135 | self.y = y |
---|
136 | self.dX = dX |
---|
137 | self.dY = dY |
---|
138 | self.dZ = dZ |
---|
139 | |
---|
140 | |
---|
141 | class ArrowEvent(Event): |
---|
142 | |
---|
143 | def __init__(self, device, arrow, x, y, toEvtHandler=None): |
---|
144 | if device.specialDevice: |
---|
145 | evtId = EVT_ARROW_SPECIAL |
---|
146 | else: |
---|
147 | evtId = EVT_ARROW |
---|
148 | Event.__init__(self, evtId, DEVICE_EVENT, toEvtHandler) |
---|
149 | self.device = device |
---|
150 | self.arrow = arrow |
---|
151 | self.x = x |
---|
152 | self.y = y |
---|
153 | |
---|
154 | |
---|
155 | class KeyEvent(Event): |
---|
156 | |
---|
157 | def __init__(self, device, key, x, y, toEvtHandler=None): |
---|
158 | if device.specialDevice: |
---|
159 | evtId = EVT_KEY_SPECIAL |
---|
160 | else: |
---|
161 | evtId = EVT_KEY |
---|
162 | Event.__init__(self, evtId, DEVICE_EVENT, toEvtHandler) |
---|
163 | self.device = device |
---|
164 | self.key = key |
---|
165 | self.x = x |
---|
166 | self.y = y |
---|
167 | |
---|
168 | |
---|
169 | class CustomEvent(Event): |
---|
170 | |
---|
171 | def __init__(self, device, data, toEvtHandler=None): |
---|
172 | if device.specialDevice: |
---|
173 | evtId = EVT_CUSTOM_SPECIAL |
---|
174 | else: |
---|
175 | evtId = EVT_CUSTOM |
---|
176 | Event.__init__(self, evtId, DEVICE_EVENT, toEvtHandler) |
---|
177 | self.device = device |
---|
178 | self.data = data |
---|
179 | |
---|
180 | |
---|
181 | class WindowEnteredEvent(Event): |
---|
182 | |
---|
183 | def __init__(self, device, toEvtHandler=None): |
---|
184 | if device.specialDevice: |
---|
185 | evtId = EVT_ENTERED_WINDOW_SPECIAL |
---|
186 | else: |
---|
187 | evtId = EVT_ENTERED_WINDOW |
---|
188 | Event.__init__(self, evtId, DEVICE_EVENT, toEvtHandler) |
---|
189 | self.device = device |
---|
190 | |
---|
191 | |
---|
192 | class WindowLeftEvent(Event): |
---|
193 | |
---|
194 | def __init__(self, device, toEvtHandler=None): |
---|
195 | if device.specialDevice: |
---|
196 | evtId = EVT_LEFT_WINDOW_SPECIAL |
---|
197 | else: |
---|
198 | evtId = EVT_LEFT_WINDOW |
---|
199 | Event.__init__(self, evtId, DEVICE_EVENT, toEvtHandler) |
---|
200 | self.device = device |
---|
201 | |
---|
202 | |
---|
203 | |
---|
204 | #---------------------------------------------------------- |
---|
205 | # GENERIC EVENTS (all who register for it receive it) |
---|
206 | #---------------------------------------------------------- |
---|
207 | |
---|
208 | |
---|
209 | class AppInfoEvent(Event): |
---|
210 | |
---|
211 | def __init__(self, sageApp): |
---|
212 | Event.__init__(self, EVT_APP_INFO, GENERIC_EVENT) |
---|
213 | self.app = sageApp |
---|
214 | |
---|
215 | |
---|
216 | class NewAppEvent(Event): |
---|
217 | |
---|
218 | def __init__(self, sageApp): |
---|
219 | Event.__init__(self, EVT_NEW_APP, GENERIC_EVENT) |
---|
220 | self.app = sageApp |
---|
221 | |
---|
222 | |
---|
223 | class PerfInfoEvent(Event): |
---|
224 | |
---|
225 | def __init__(self, data): |
---|
226 | Event.__init__(self, EVT_PERF_INFO, GENERIC_EVENT) |
---|
227 | # tokens = string.split(data) |
---|
228 | # FIX - ie complete |
---|
229 | |
---|
230 | |
---|
231 | class DisplayInfoEvent(Event): |
---|
232 | |
---|
233 | def __init__(self, dispInfo): |
---|
234 | Event.__init__(self, EVT_DISPLAY_INFO, GENERIC_EVENT) |
---|
235 | self.displayInfo = dispInfo |
---|
236 | |
---|
237 | |
---|
238 | class AppKilledEvent(Event): |
---|
239 | |
---|
240 | def __init__(self, sageApp): |
---|
241 | Event.__init__(self, EVT_APP_KILLED, GENERIC_EVENT) |
---|
242 | self.app = sageApp |
---|
243 | |
---|
244 | |
---|
245 | class ZChangeEvent(Event): |
---|
246 | |
---|
247 | def __init__(self, zHash): |
---|
248 | Event.__init__(self, EVT_Z_CHANGE, GENERIC_EVENT) |
---|
249 | self.zHash = zHash # key=appId, value=new z value |
---|
250 | |
---|
251 | |
---|
252 | class ObjectInfoEvent(Event): |
---|
253 | |
---|
254 | def __init__(self, data): |
---|
255 | Event.__init__(self, EVT_OBJECT_INFO, GENERIC_EVENT) |
---|
256 | self.overlayId = data.split()[0] |
---|
257 | self.data = data |
---|
258 | # FIX - ie complete |
---|