Package AccessEngine :: Package AEDevice :: Package AEInput :: Module SystemInput
[hide private]
[frames] | no frames]

Source Code for Module AccessEngine.AEDevice.AEInput.SystemInput

  1  ''' 
  2  Defines an abstract base class for all input devices that serve double duty as  
  3  sources of input for SUE and for the rest of the operating system. 
  4   
  5  @author: Peter Parente 
  6  @organization: IBM Corporation 
  7  @copyright: Copyright (c) 2005, 2007 IBM Corporation 
  8  @license: The BSD License 
  9   
 10  @author: Frank Zenker 
 11  @organization: IT Science Center Ruegen gGmbH, Germany 
 12  @copyright: Copyright (c) 2007, 2008 ITSC Ruegen 
 13  @license: The BSD License 
 14   
 15  All rights reserved. This program and the accompanying materials are made  
 16  available under the terms of the BSD license which accompanies 
 17  this distribution, and is available at 
 18  U{http://www.opensource.org/licenses/bsd-license.php} 
 19  ''' 
 20  import Base 
 21  from AccessEngine import AEConstants 
 22   
23 -class SystemInput(Base.AEInput):
24 ''' 25 Abstract base class for input devices that are used by both SUE and the OS. 26 Provides an interface for registering modifier actions that can be used to 27 indicate the start of commands intended for SUE. Also provides an interface 28 for registering filtered L{GestureList}s that indicate which combination of 29 L{Gesture}s should not be passed to other applications. The definition of what 30 constitues a valid L{Gesture} and L{GestureList} is left to a subclass. The 31 decision as to when registered L{Gesture}s are filtered or not is determined 32 by a mode managed in this class via L{getFilterMode} and L{setFilterMode}. 33 34 This class is abstract as some of the methods inherited from 35 L{Base.AEInput} are not overridden and raise NotImplementedError. 36 37 @ivar modifiers: Dictionary of action codes that are considered modifiers 38 @type modifiers: dictionary 39 @ivar filter_mode: Mode that determines which L{Gesture}s are filtered 40 @type filter_mode: integer 41 '''
42 - def __init__(self):
43 ''' 44 Initializes the filters to an empty list, the modifiers to an empty 45 dictionary, and the filtering mode to none. 46 ''' 47 Base.AEInput.__init__(self) 48 self.modifiers = {} 49 self.filter_mode = AEConstants.FILTER_NONE
50
51 - def getCapabilities(self):
52 ''' 53 @return: 'system input' as the only capability of this device. 54 @rtype: list of string 55 ''' 56 return ['system input']
57
58 - def getFilterMode(self):
59 ''' 60 Gets the current filter mode. 61 62 @return: Current filter mode 63 @rtype: integer 64 ''' 65 return self.filter_mode
66
67 - def setFilterMode(self, mode):
68 ''' 69 Stores the current filter mode. 70 71 @param mode: Current filter mode 72 @type mode: integer 73 ''' 74 self.filter_mode = mode
75
76 - def addModifier(self, code):
77 ''' 78 Adds an action code to the modifiers dictionary to identify it as a modifier 79 for other actions. 80 81 @param code: Action code to register as a modifier 82 @type code: integer 83 ''' 84 try: 85 self.modifiers[code] += 1 86 except KeyError: 87 self.modifiers[code] = 1
88
89 - def removeModifier(self, code):
90 ''' 91 Removes an action code from the modifiers dictionary if it is no longer 92 in use. Otherwise, it decrements the reference count. 93 94 @param code: Action code to unregister as a modifier 95 @type code: integer 96 ''' 97 try: 98 self.modifiers[code] -= 1 99 if self.modifiers[code] <= 0: 100 del self.modifiers[code] 101 except KeyError: 102 pass
103
104 - def clearModifiers(self):
105 ''' 106 Removes all modifiers by destroying the modifiers dictionary and recreating 107 it. 108 ''' 109 self.modifiers = {}
110
111 - def addFilter(self, gestures):
112 ''' 113 Abstact method. Adds a L{GestureList} as a filter to this device. A filter 114 typically indicates input that should be consumed and prevented from 115 reaching other applications. Exactly how the filter is stored and used is 116 determined by a subclass. 117 118 @param gestures: L{Gesture}s to possibly filter 119 @type gestures: L{GestureList} 120 @raise NotImplementedError: When this method is not overridden by a 121 subclass 122 ''' 123 raise NotImplementedError
124
125 - def removeFilter(self, gestures):
126 ''' 127 Abstract method. Removes a L{GestureList} as a filter from this device. 128 A filter typically indicates input that should be consumed and prevented 129 from reaching other applications. How the filter is removed is determined 130 by a subclass. 131 132 @param gestures: L{Gesture}s to no longer filter 133 @type gestures: L{GestureList} 134 @raise NotImplementedError: When this method is not overridden by a 135 subclass 136 ''' 137 raise NotImplementedError
138
139 - def clearFilters(self):
140 ''' 141 Abstract method. Removes all L{GestureList} filters from the device. How 142 the filters are removed is determined by a subclass. A filter typically 143 indicates input that should be consumed and prevented from reaching other 144 applications. Exactly How the filter is removed is determined by a 145 subclass. 146 147 @raise NotImplementedError: When this method is not overridden by a 148 subclass 149 ''' 150 raise NotImplementedError
151
152 - def resetState(self):
153 ''' 154 Abstract method. Resets the state of the input device. 155 156 @raise NotImplementedError: When not overridden in a subclass 157 ''' 158 raise NotImplementedError
159