IBM Corporation under the BSD license, available at
U{http://www.opensource.org/licenses/bsd-license.php}
'''
+import Accessibility__POA
+
def getInterfaceIID(cls):
'''
Gets the ID of an interface class in string format for use in queryInterface.
- All alpha characters in the suffix are mapped to their uppercase.
The resulting name is used with getattr to look up a constant with that name
- in the L{pyLinAcc.Constants} module. If such a constant does not exist, the
- string suffix is returned instead.
+ in the L{constants} module. If such a constant does not exist, the string
+ suffix is returned instead.
This method allows strings to be used to refer to roles, relations, etc.
without direct access to the constants. It also supports the future expansion
def stateToString(value):
'''
Converts a state value to a string based on the name of the state constant in
- the L{Constants} module that has the given value.
+ the L{constants} module that has the given value.
@param value: An AT-SPI state
@type value: Accessibility.StateType
def relationToString(value):
'''
Converts a relation value to a string based on the name of the state constant
- in the L{Constants} module that has the given value.
+ in the L{constants} module that has the given value.
@param value: An AT-SPI relation
@type value: Accessibility.RelationType
def allModifiers():
'''
Generates all possible keyboard modifiers for use with
- L{Registry.Registry.registerKeystrokeListener}.
+ L{registry.Registry.registerKeystrokeListener}.
'''
mask = 0
while mask <= (1 << constants.MODIFIER_NUMLOCK):
if ret is not None: return ret
def _findDescendantBreadth(acc, pred):
- '''
- Internal function for locating one descendant. Called by
- L{AccessibleMixin.findDescendant} to start the search.
+ '''
+ Internal function for locating one descendant. Called by L{findDescendant} to
+ start the search.
@param acc: Root accessible of the search
@type acc: Accessibility.Accessible
def _findDescendantDepth(acc, pred):
'''
- Internal function for locating one descendant. Called by
- L{AccessibleMixin.findDescendant} to start the search.
+ Internal function for locating one descendant. Called by L{findDescendant} to
+ start the search.
@param acc: Root accessible of the search
@type acc: Accessibility.Accessible
except Exception:
raise LookupError
acc = acc.parent
+
+class StateSet(Accessibility__POA.StateSet):
+ '''
+ Convenience implementation of AT-SPI StateSet, for future use with Collection
+ interface.
+
+ @param states: Set of states
+ @type states: set
+ '''
+ def __init__(self, *states):
+ '''Initializes the state set with the given states.'''
+ self.states = set(states)
+
+ def contains(self, state):
+ '''
+ Checks if this L{StateSet} contains the given state.
+
+ @param state: State to check
+ @type state: Accessibility.StateType
+ @return: True if the set contains the given state
+ @rtype: boolean
+ '''
+ return state in self.states
+
+ def add(self, *state):
+ '''
+ Adds one or more states to this set.
+
+ @param state: State(s) to add
+ @type state: Accessibility.StateType
+ '''
+ self.states.add(state)
+
+ def remove(self, *state):
+ '''
+ Removes one or more states from this set.
+
+ @param state: State(s) to remove
+ @type state: Accessibility.StateType
+ '''
+ self.states.remove(state)
+
+ def equals(self, state_set):
+ '''
+ Checks if this L{StateSet} contains exactly the same members as the given
+ L{StateSet}.
+
+ @param state_set: Another set
+ @type state_set: L{StateSet}
+ @return: Are the sets equivalent in terms of their contents?
+ @rtype: boolean
+ '''
+ return self.state_set == self.states
+
+ def compare(self, state_set):
+ '''
+ Computes the symmetric differences of this L{StateSet} and the given
+ L{StateSet}.
+
+ @param state_set: Another set
+ @type state_set: L{StateSet}
+ @return: Elements in only one of the two sets
+ @rtype: L{StateSet}
+ '''
+ diff = self.states.symmetric_difference(state_set.states)
+ return StateSet(*diff)
+
+ def isEmpty(self):
+ '''
+ Checks if this L{StateSet} is empty.
+
+ @return: Is it empty?
+ @rtype: boolean
+ '''
+ return len(self.states) == 0
+
+ def getStates(self):
+ '''
+ Gets the sequence of all states in this set.
+
+ @return: List of states
+ @rtype: list
+ '''
+ return list(self.states)
\ No newline at end of file