1 '''
2 Wraps the Gnome Assistive Technology Service Provider Interface for use in
3 Python. Imports the bonobo and ORBit modules. Initializes the ORBit ORB.
4 Activates the bonobo Accessibility Registry. Loads the Accessibility typelib and
5 imports the classes implementing the AT-SPI interfaces.
6
7 @var Registry: Reference to the AT-SPI registry daemon intialized on successful
8 import
9 @type Registry: Accessibility.Registry
10
11 @author: Peter Parente
12 @organization: IBM Corporation
13 @copyright: Copyright (c) 2005, 2007 IBM Corporation
14 @license: The BSD License
15
16 All rights reserved. This program and the accompanying materials are made
17 available under the terms of the BSD license which accompanies
18 this distribution, and is available at
19 U{http://www.opensource.org/licenses/bsd-license.php}
20 '''
21
22 REGISTRY_IID = "OAFIID:Accessibility_Registry:1.0"
23 TYPELIB_NAME = "Accessibility"
24
25
26 import ORBit, bonobo
27
28 orb = ORBit.CORBA.ORB_init()
29
30 data = bonobo.activation.activate_from_id(REGISTRY_IID)
31 if data is None:
32 raise RuntimeError('Could not activate:', REGISTRY_IID)
33 else:
34 try:
35 Registry = data[0]
36 except IndexError:
37 raise ValueError('Activation received unexpected object: '+str(data))
38
39 ORBit.load_typelib(TYPELIB_NAME)
40
41
42 import Accessibility
43
44 import Accessible, Event, Constants, Interfaces, Atk
45
47 '''
48 Suggests the default AT-SPI events to be monitored.
49
50 @return: Names of defaults to monitor
51 @rtype: list of string
52 '''
53 return Constants.default_types
54
56 '''
57 Gets the names of all the top-level (klass) AT-SPI events.
58
59 @return: List of all names
60 @rtype: list of string
61 '''
62 names = Constants.all_types
63 names.sort()
64 return names
65
67 '''
68 Maps a string name to an LSR constant. The rules for the mapping are as
69 follows:
70 - The prefix is captalized and has an _ appended to it.
71 - All spaces in the suffix are mapped to the _ character.
72 - All alpha characters in the suffix are mapped to their uppercase.
73
74 The resulting name is used with getattr to look up a constant with that name
75 in the L{pyLinAcc.Constants} module. If such a constant does not exist, the
76 string suffix is returned instead.
77
78 This method allows strings to be used to refer to roles, relations, etc.
79 without direct access to the constants. It also supports the future expansion
80 of roles, relations, etc. by allowing arbitrary strings which may or may not
81 map to the current standard set of roles, relations, etc., but may still match
82 some non-standard role, relation, etc. being reported by an application.
83
84 @param prefix: Prefix of the constant name such as role, relation, state,
85 text, modifier, key
86 @type prefix: string
87 @param suffix: Name of the role, relation, etc. to use to lookup the constant
88 @type suffix: string
89 @return: The matching constant value
90 @rtype: object
91 '''
92 name = prefix.upper()+'_'+suffix.upper().replace(' ', '_')
93 return getattr(Constants, name, suffix)
94
96 '''
97 Converts a state value to a string based on the name of the state constant in
98 the L{Constants} module that has the given value.
99
100 @param value: An AT-SPI state
101 @type value: Accessibility.StateType
102 @return: Human readable, untranslated name of the state
103 @rtype: string
104 '''
105 return Constants.state_val_to_name.get(value)
106
108 '''
109 Converts a relation value to a string based on the name of the state constant
110 in the L{Constants} module that has the given value.
111
112 @param value: An AT-SPI relation
113 @type value: Accessibility.RelationType
114 @return: Human readable, untranslated name of the relation
115 @rtype: string
116 '''
117 return Constants.rel_val_to_name.get(value)
118
120 '''
121 Decorates the given function with a try/except that catches all pyLinAcc
122 CORBA exceptions and re-raises them as standard Python lookup errors. This
123 decorator is useful for reducing the number of imports of the pyLinAcc
124 package across LSR.
125
126 @param func: Function to decorate
127 @type func: function
128 '''
129 def _inner(self, *args, **kwargs):
130
131 try:
132
133 return func(self, *args, **kwargs)
134 except Constants.CORBAException:
135
136 raise LookupError
137
138 _inner.__doc__ = func.__doc__
139 _inner.__name__ = func.__name__
140 _inner.__dict__.update(func.__dict__)
141 return _inner
142