Changeset 448 for trunk/avango-display/python/avango/display/_device.py
- Timestamp:
- 05/14/10 11:31:00 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/avango-display/python/avango/display/_device.py
r430 r448 45 45 self.super(Device).__init__() 46 46 self.Active.value = True 47 48 47 48 49 49 class KeyboardDevice(avango.script.Script): 50 50 51 51 KeysPressed = avango.MFInt() 52 52 … … 81 81 KeyF11 = avango.SFBool() 82 82 KeyF12 = avango.SFBool() 83 83 84 84 Key0 = avango.SFBool() 85 85 Key1 = avango.SFBool() … … 92 92 Key8 = avango.SFBool() 93 93 Key9 = avango.SFBool() 94 94 95 95 KeyX = avango.SFBool() 96 96 KeyZ = avango.SFBool() 97 97 98 98 KeyBackslash = avango.SFBool() 99 99 KeyCloseBracket = avango.SFBool() 100 100 101 101 def __init__(self): 102 102 self.super(KeyboardDevice).__init__() 103 103 104 104 self.__prev_keys_pressed = [] 105 105 106 106 self.__keymap = {} 107 107 108 108 self.__keymap[48] = self.Key1 109 109 self.__keymap[49] = self.Key1 … … 116 116 self.__keymap[56] = self.Key8 117 117 self.__keymap[57] = self.Key9 118 118 119 119 self.__keymap[120] = self.KeyX 120 120 self.__keymap[122] = self.KeyZ 121 121 122 122 self.__keymap[92] = self.KeyBackslash 123 123 self.__keymap[41] = self.KeyCloseBracket 124 124 125 125 def add_key(self,name,id): 126 126 """ 127 127 Add a SFBool, which will be connected to the key press with the given id 128 The naming convention says that you should pass Key<Name> as name parameter. 128 The naming convention says that you should pass Key<Name> as name parameter. 129 129 E.g.: If you want to add the key <1> call add_key("Key1",48) 130 130 """ 131 131 132 132 #if a field with the given name is already known, no new field will be added 133 133 field = self._get_field(name) 134 134 if field: 135 135 return False 136 136 137 137 self.add_and_init_field(avango.SFBool(), name, id) 138 138 self.__keymap[id] = getattr(self, name) 139 139 self.__keymap[id].value = False 140 140 141 141 return True 142 142 143 143 def evaluate(self): 144 144 145 145 pressed_keys = [] 146 146 for k in self.KeysPressed.value: 147 147 pressed_keys.append(k) 148 148 149 149 #pressed keys 150 150 for key in pressed_keys: … … 157 157 if key in self.__keymap: 158 158 self.__keymap[key].value = False 159 159 160 160 self.__prev_keys_pressed = pressed_keys 161 162 161 162 163 163 def connect(self, eventfields): 164 164 165 165 self.KeysPressed.connect_from(eventfields.KeysPressed) 166 166 167 167 self.KeyRight.connect_from(eventfields.KeyRight) 168 168 self.KeyLeft.connect_from(eventfields.KeyLeft) … … 172 172 self.PageDown.connect_from(eventfields.KeyPageDown) 173 173 self.Shift.connect_from(eventfields.KeyShift) 174 self.Ctrl.connect_from(eventfields.KeyCtrl) 174 self.Ctrl.connect_from(eventfields.KeyCtrl) 175 175 self.KeyAlt.connect_from(eventfields.KeyAlt) 176 176 self.Insert.connect_from(eventfields.KeyInsert) … … 194 194 self.KeyF11.connect_from(eventfields.KeyF11) 195 195 self.KeyF12.connect_from(eventfields.KeyF12) 196 196 197 197 198 198 class MouseDevice(avango.script.Script): … … 205 205 MouseButtonMiddle = avango.SFBool() 206 206 MouseScrollUp = avango.SFBool() 207 MouseScrollDown = avango.SFBool() 207 MouseScrollDown = avango.SFBool() 208 208 MouseLeftDoubleClick = avango.SFBool() 209 209 MouseLeftAndRight = avango.SFBool() 210 210 211 211 def __init__(self): 212 212 self.super(MouseDevice).__init__() 213 213 214 214 def connect(self, eventfields, camera, window): 215 215 self.Matrix.connect_from(camera.MouseNearTransform) 216 216 217 217 self.MousePosNorm.connect_from(window.MousePositionNorm) 218 218 self.MousePos.connect_from(window.MousePosition) 219 219 self.MouseMovementNorm.connect_from(window.MouseMovementNorm) 220 220 221 221 self.MouseButtonLeft.connect_from(eventfields.MouseButtonLeft) 222 222 self.MouseButtonRight.connect_from(eventfields.MouseButtonRight) … … 226 226 self.MouseLeftDoubleClick.connect_from(eventfields.MouseButtonLeftDoubleClick) 227 227 self.MouseLeftAndRight.connect_from(eventfields.MouseButtons_LeftAndRight) 228 229 230 def make_wiimote_device(wiimote_station, dtrack_station, device_service, receiver_offset, transmitter_offset): 228 229 230 def make_wiimote_device(wiimote_station, dtrack_station, device_service, receiver_offset, transmitter_offset): 231 231 device = WiimoteDevice() 232 232 device._setup(wiimote_station, dtrack_station, device_service, receiver_offset, transmitter_offset) 233 233 return device 234 234 235 235 236 236 class WiimoteDevice(avango.script.Script): 237 237 238 238 Button0 = avango.SFBool() 239 239 Button1 = avango.SFBool() … … 247 247 Button9 = avango.SFBool() 248 248 Button10 = avango.SFBool() 249 249 250 250 LED0 = avango.SFBool() 251 251 LED1 = avango.SFBool() 252 252 LED2 = avango.SFBool() 253 253 LED3 = avango.SFBool() 254 254 255 255 Matrix = avango.osg.SFMatrix() 256 256 257 257 def __init__(self): 258 258 self.super(WiimoteDevice).__init__() 259 259 260 260 self.Button0.value = False 261 261 self.Button1.value = False … … 269 269 self.Button9.value = False 270 270 self.Button10.value = False 271 271 272 272 self.LED0.value = False 273 273 self.LED1.value = False 274 274 self.LED2.value = False 275 275 self.LED3.value = False 276 276 277 277 #will be initialized by the init function 278 278 self.dtrack_sensor = None … … 280 280 self.wiimote_actuator = None 281 281 self.device_service = None 282 283 282 283 284 284 def _setup(self, wiimote_station, dtrack_station, device_service, receiver_offset, transmitter_offset): 285 285 self.device_service = device_service … … 292 292 self.wiimote_actuator = avango.daemon.nodes.WiimoteActuator(DeviceService = device_service, 293 293 Station = wiimote_station) 294 294 295 295 self.Button0.connect_from(self.wiimote_sensor.Button0) 296 296 self.Button1.connect_from(self.wiimote_sensor.Button1) … … 304 304 self.Button9.connect_from(self.wiimote_sensor.Button9) 305 305 self.Button10.connect_from(self.wiimote_sensor.Button10) 306 306 307 307 self.wiimote_actuator.LED0.connect_from(self.LED0) 308 308 self.wiimote_actuator.LED1.connect_from(self.LED1) 309 309 self.wiimote_actuator.LED2.connect_from(self.LED2) 310 310 self.wiimote_actuator.LED3.connect_from(self.LED3) 311 311 312 312 self.Matrix.connect_from(self.dtrack_sensor.Matrix) 313
Note: See TracChangeset
for help on using the changeset viewer.
