| Trees | Indices | Help |
|
|---|
|
|
1 '''
2 Defines the abstract base class for all L{AEInput} subclasses.
3
4 @author: Peter Parente
5 @author: Scott Haeger
6 @organization: IBM Corporation
7 @copyright: Copyright (c) 2005, 2007 IBM Corporation
8 @license: The BSD License
9
10 All rights reserved. This program and the accompanying materials are made
11 available under the terms of the BSD license which accompanies
12 this distribution, and is available at
13 U{http://www.opensource.org/licenses/bsd-license.php}
14 '''
15 import logging
16 from AccessEngine import AEUserInterface
17 from AccessEngine import AEConstants
18
19 log = logging.getLogger('Input')
20
22 '''
23 Suggests the default L{AEOutput}s events to be monitored.
24
25 @return: Empty list, don't monitor by default
26 @rtype: list of string
27 '''
28 return []
29
31 '''
32 Gets the names of all the L{AEInput} command types.
33
34 @return: List of all known L{AEInput} command names
35 @rtype: list of string
36 '''
37 names = AEConstants.INPUT_COMMAND_NAMES.values()
38 names.sort()
39 return names
40
42 '''
43 Most abstract base class for all L{AEInput} devices. Maintains a collection of
44 L{Gesture} listeners that can be notified using L{_notifyInputListeners}.
45 Defines simple L{init} and L{close} methods that change the state of the
46 L{ready} flag.
47
48 This class is abstract as most of its methods raise NotImplementedError and
49 need to be overriden with input device specific code in subclasses.
50
51 @ivar listeners: Collection of listeners that are notified about L{Gesture}s
52 on an input device
53 @type listeners: list of callable
54 @ivar ready: Is the input device initialized?
55 @type ready: boolean
56 '''
58 '''
59 Initializes the listeners list to empty and sets the ready flag to False.
60 '''
61 self.listeners = []
62
64 '''
65 Called after the instance is created to initialize the device.
66
67 If called when already initialized, this will restore the device to it's
68 initialized state. May also be called to re-initialize the device after
69 a call to L{close}.
70
71 @raise NotImplementedError: When not overridden in a subclass
72 @raise Error.InitError: When a communication or state problem exists for
73 the specific device
74 '''
75 raise NotImplementedError
76
78 '''
79 Gets a list of strings representing the capabilities of this device.
80 Typical output capabilities include "system input," "braille," "switch,"
81 etc. though others are certainly possible.
82
83 The L{AEDeviceManager} will only load a device if another device doesn't
84 already provide all of its capabilities.
85
86 @return: Lowercase names of output capabilities
87 @rtype: list of string
88 '''
89 raise NotImplementedError
90
92 '''
93 Closes an initialized input device.
94
95 @raise NotImplementedError: When not overridden in a subclass
96 '''
97 raise NotImplementedError
98
100 '''
101 Adds a listener to be notified whenever a L{Gesture} occurs on an input
102 device. Listeners are called in the order they are added and are given the
103 L{Gesture} detected.
104
105 @param listener: Object to call when a L{Gesture} occurs
106 @type listener: callable
107 '''
108 self.listeners.append(listener)
109
111 '''
112 Removes an existing listener for L{Gesture}s.
113
114 @param listener: Object to remove from the listener list
115 @type listener: callable
116 @raise ValueError: When removing a listener that is not registered
117 '''
118 self.listeners.remove(listener)
119
121 '''
122 Gets if there are any registered L{Gesture} listeners for this device.
123
124 @return: Is there at least one listener registered?
125 @rtype: boolean
126 '''
127 return len(self.listeners) > 0
128
130 '''
131 Notifies registered listeners about a L{Gesture} seen on the input device.
132 Catches all exceptions from the callback and logs them.
133
134 @param gesture: L{Gesture} to send to listeners
135 @type gesture: L{Gesture}
136 @param timestamp: Time at which at the gesture happened
137 @type timestamp: float
138 @param kwargs: Additional data to include in the notification
139 @type kwargs: dictionary
140 '''
141 for listener in self.listeners:
142 try:
143 listener(gesture, timestamp, **kwargs)
144 except Exception:
145 log.exception('AEInput exception')
146
148 '''
149 Sorts the actions in the given L{AEInput.Gesture} and returns them as a list
150 of integers. The sort is done on a copy so the action codes held by the
151 provided L{AEInput.Gesture} are not touched.
152
153 @param gesture: L{AEInput.Gesture} to sort
154 @type gesture: L{AEInput.Gesture}
155 @return: Sorted list of action codes that may be wrapped in a new
156 L{AEInput.Gesture}
157 @rtype: list of integer
158 '''
159 codes = gesture.getActionCodes()
160 codes.sort()
161 return codes
162
164 '''
165 Abstract method. Gets the maximum number of actions that can be in a
166 L{Gesture} on this input device.
167
168 @return: Maximum number of actions per L{Gesture} supported by this device
169 @rtype: integer
170 @raise NotImplementedError: When this method is not overridden by a subclass
171 '''
172 raise NotImplementedError
173
175 '''
176 Abstract method. Gets a human readable representation of the given
177 L{Gesture}.
178
179 @param gesture: L{Gesture} object to render as text
180 @type gesture: L{Gesture}
181 @return: Text representation of the L{Gesture}
182 @rtype: string
183 @raise NotImplementedError: When this method is not overridden by a subclass
184 '''
185 raise NotImplementedError
186
196
206
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Mon Jun 30 13:06:13 2008 | http://epydoc.sourceforge.net |