2008-05-28 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / pyatspi / constants.py
1 '''
2 Defines constants used throughout this wrapper.
3
4 @author: Peter Parente
5 @author: Pete Brunet
6 @organization: IBM Corporation
7 @copyright: Copyright (c) 2005, 2007 IBM Corporation
8 @license: LGPL
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 Library General Public License for more details.
19
20 You should have received a copy of the GNU Library General Public
21 License along with this library; if not, write to the
22 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA.
24
25 Portions of this code originally licensed and copyright (c) 2005, 2007
26 IBM Corporation under the BSD license, available at
27 U{http://www.opensource.org/licenses/bsd-license.php}
28 '''
29 import ORBit
30 import Accessibility
31 import utils
32
33 # pull dictionary of Accessibility module namespace into local var, temporarily
34 acc_dict = vars(Accessibility)
35
36 # run through all objects in the Accessibility module
37 ALL_INTERFACES = []
38 # list of classes that are not queriable interfaces
39 not_interfaces = ['RoleSet', 'StateSet', 'DeviceEventListener', 'LoginHelper',
40                   'ContentStream', 'DeviceEventController', 'Registry'
41                   'DeviceEventListener', 'EventListener', 'Relation', 
42                   'CommandListener', 'Selector']
43 for obj in acc_dict.values():
44   try:
45     # see if the object has a typecode
46     kind = obj.__typecode__.kind
47   except AttributeError:
48     continue
49   # compare the typecode to the one for CORBA objects, and to our list of 
50   # classes that are not queriable interfaces
51   if (kind == ORBit.CORBA.tk_objref and 
52       utils.getInterfaceName(obj) not in not_interfaces):
53     # this is an interface class
54     ALL_INTERFACES.append(obj)
55 # get rid of our temporary vars
56 del not_interfaces, obj, kind
57
58 # constants used in the Component interface to get screen coordinates
59 DESKTOP_COORDS = 0
60 WINDOW_COORDS = 1
61
62 # constants used to synthesize mouse events
63 MOUSE_B1P = 'b1p'
64 MOUSE_B1R = 'b1r'
65 MOUSE_B1C = 'b1c'
66 MOUSE_B1D = 'b1d'
67 MOUSE_B2P = 'b2p'
68 MOUSE_B2R = 'b2r'
69 MOUSE_B2C = 'b2c'
70 MOUSE_B2D = 'b2d'
71 MOUSE_B3P = 'b3p'
72 MOUSE_B3R = 'b3r'
73 MOUSE_B3C = 'b3c'
74 MOUSE_B3D = 'b3d'
75 MOUSE_ABS = 'abs'
76 MOUSE_REL = 'rel'
77
78 # defines levels of caching where if x > y, x caches all of y plus more
79 CACHE_INTERFACES = 0
80 CACHE_PROPERTIES = 1
81
82 # events that clear cached properties
83 CACHE_EVENTS = ['object:property-change:accessible-name',
84                 'object:property-change:accessible-description',
85                 'object:property-change:accessible-role',
86                 'object:property-change:accessible-parent']
87
88 # dictionary used to correct the bug of not being able to register for all the
89 # subevents given only an AT-SPI event class (i.e. first part of the event
90 # name) keys are event names having subevents and values are the subevents
91 # under the key event; handlers *can* be registered for events not in this tree
92 EVENT_TREE = {
93   'terminal':
94     ['terminal:line-changed',
95      'terminal:columncount-changed',
96      'terminal:linecount-changed',
97      'terminal:application-changed',
98      'terminal:charwidth-changed'
99      ],
100   'document':
101     ['document:load-complete',
102      'document:reload',
103      'document:load-stopped',
104      'document:content-changed',
105      'document:attributes-changed'
106      ],
107   'object': 
108     ['object:property-change',
109      'object:bounds-changed',
110      'object:link-selected',
111      'object:state-changed',
112      'object:children-changed',
113      'object:visible-data-changed',
114      'object:selection-changed',
115      'object:model-changed',
116      'object:active-descendant-changed',
117      'object:row-inserted',
118      'object:row-reordered',
119      'object:row-deleted',
120      'object:column-inserted',
121      'object:column-reordered',
122      'object:column-deleted',
123      'object:text-bounds-changed',
124      'object:text-selection-changed',
125      'object:text-changed',
126      'object:text-attributes-changed',
127      'object:text-caret-moved',  
128      'object:attributes-changed'],
129   'object:text-changed' :
130     ['object:text-changed:insert',
131     'object:text-changed:delete'],
132   'object:property-change' :
133     ['object:property-change:accessible-parent', 
134     'object:property-change:accessible-name',
135     'object:property-change:accessible-description',
136     'object:property-change:accessible-value',
137     'object:property-change:accessible-role',
138     'object:property-change:accessible-table-caption',
139     'object:property-change:accessible-table-column-description',
140     'object:property-change:accessible-table-column-header',
141     'object:property-change:accessible-table-row-description',
142     'object:property-change:accessible-table-row-header',
143     'object:property-change:accessible-table-summary'],
144   'object:children-changed' :
145     ['object:children-changed:add',
146     'object:children-changed:remove'],
147   'object:state-changed' :
148     ['object:state-changed:'],
149   'mouse' :
150     ['mouse:abs',
151     'mouse:rel',
152     'mouse:button'],
153   'mouse:button' :
154     ['mouse:button:1p',
155     'mouse:button:1r',
156     'mouse:button:2p',
157     'mouse:button:2r',
158     'mouse:button:3p',
159     'mouse:button:3r'],
160   'window' :
161     ['window:minimize',
162     'window:maximize',
163     'window:restore',
164     'window:close',
165     'window:create',
166     'window:reparent',
167     'window:desktop-create',
168     'window:desktop-destroy',
169     'window:activate',
170     'window:deactivate',
171     'window:raise',
172     'window:lower',
173     'window:move',
174     'window:resize',
175     'window:shade',
176     'window:unshade',
177     'window:restyle'],
178   'focus' :
179     ['focus:']
180 }
181
182 # pull ROLE_*, STATE_*, TEXT_*, MODIFIER_*, LOCALE_*, and RELATION_*, etc. 
183 # constants into the local namespace for convenient access
184 # grab all the variable names and their values from the Accessibility module
185
186 # get the dictionary for the local namespace
187 loc_dict = locals()
188 # these are the prefixes for the variable names we want to pull out of the 
189 # Accessibility module
190 prefixes = ['ROLE_', 'STATE_', 'TEXT_', 'MODIFIER_', 'LOCALE_', 'RELATION_',
191             'KEY_', 'MATCH_', 'SORT_', 'LAYER_']
192 # for each variable name in the Accessibility namespace, check if it starts
193 # with at least one of the prefixes above; if it does, add a 2-tuple of 
194 # variable name and value to the values list
195 values = ((name, value) for name, value in acc_dict.items()
196           if len([p for p in prefixes if name.startswith(p)]))
197 # create a new dictionary from the list of tuples and then update the local
198 # namespace dictionary with that dictionary
199 loc_dict.update(dict(values))
200
201 # build a dictionary mapping state values to names based on the prefix of the
202 # constant name imported from Accessibility
203 STATE_VALUE_TO_NAME = dict(((value, name[6:].lower().replace('_', ' ')) 
204                             for name, value 
205                             in acc_dict.items()
206                             if name.startswith('STATE_')))
207
208 # build a dictionary mapping relation values to names based on the prefix of 
209 # the constant name imported from Accessibility
210 RELATION_VALUE_TO_NAME = dict(((value, name[9:].lower().replace('_', ' ')) 
211                                for name, value 
212                                in acc_dict.items()
213                                if name.startswith('RELATION_')))
214
215 # throw away any temporary variables so they don't hang around in this module
216 del acc_dict, loc_dict, prefixes, values