cb2353adbc31e3794386ee0d9700b3df4c419da1
[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 list
56 del not_interfaces
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-parent']
86
87 # dictionary used to correct the bug of not being able to register for all the
88 # subevents given only an AT-SPI event class (i.e. first part of the event
89 # name) keys are event names having subevents and values are the subevents
90 # under the key event; handlers *can* be registered for events not in this tree
91 EVENT_TREE = {
92   'terminal':
93     ['terminal:line-changed',
94      'terminal:columncount-changed',
95      'terminal:linecount-changed',
96      'terminal:application-changed',
97      'terminal:charwidth-changed'
98      ],
99   'document':
100     ['document:load-complete',
101      'document:reload',
102      'document:load-stopped',
103      'document:content-changed',
104      'document:attributes-changed'
105      ],
106   'object': 
107     ['object:property-change',
108      'object:bounds-changed',
109      'object:link-selected',
110      'object:state-changed',
111      'object:children-changed',
112      'object:visible-data-changed',
113      'object:selection-changed',
114      'object:model-changed',
115      'object:active-descendant-changed',
116      'object:row-inserted',
117      'object:row-reordered',
118      'object:row-deleted',
119      'object:column-inserted',
120      'object:column-reordered',
121      'object:column-deleted',
122      'object:text-bounds-changed',
123      'object:text-selection-changed',
124      'object:text-changed',
125      'object:text-attributes-changed',
126      'object:text-caret-moved',  
127      'object:attributes-changed'],
128   'object:text-changed' :
129     ['object:text-changed:insert',
130     'object:text-changed:delete'],
131   'object:property-change' :
132     ['object:property-change:accessible-parent', 
133     'object:property-change:accessible-name',
134     'object:property-change:accessible-description',
135     'object:property-change:accessible-value',
136     'object:property-change:accessible-role',
137     'object:property-change:accessible-table-caption',
138     'object:property-change:accessible-table-column-description',
139     'object:property-change:accessible-table-column-header',
140     'object:property-change:accessible-table-row-description',
141     'object:property-change:accessible-table-row-header',
142     'object:property-change:accessible-table-summary'],
143   'object:children-changed' :
144     ['object:children-changed:add',
145     'object:children-changed:remove'],
146   'object:state-changed' :
147     ['object:state-changed:'],
148   'mouse' :
149     ['mouse:abs',
150     'mouse:rel',
151     'mouse:button'],
152   'mouse:button' :
153     ['mouse:button:1p',
154     'mouse:button:1r',
155     'mouse:button:2p',
156     'mouse:button:2r',
157     'mouse:button:3p',
158     'mouse:button:3r'],
159   'window' :
160     ['window:minimize',
161     'window:maximize',
162     'window:restore',
163     'window:close',
164     'window:create',
165     'window:reparent',
166     'window:desktop-create',
167     'window:desktop-destroy',
168     'window:activate',
169     'window:deactivate',
170     'window:raise',
171     'window:lower',
172     'window:move',
173     'window:resize',
174     'window:shade',
175     'window:unshade',
176     'window:restyle'],
177   'focus' :
178     ['focus:']
179 }
180
181 # pull ROLE_*, STATE_*, TEXT_*, MODIFIER_*, LOCALE_*, and RELATION_*, etc. 
182 # constants into the local namespace for convenient access
183 # grab all the variable names and their values from the Accessibility module
184
185 # get the dictionary for the local namespace
186 loc_dict = locals()
187 # these are the prefixes for the variable names we want to pull out of the 
188 # Accessibility module
189 prefixes = ['ROLE_', 'STATE_', 'TEXT_', 'MODIFIER_', 'LOCALE_', 'RELATION_',
190             'KEY_', 'MATCH_', 'SORT_', 'LAYER_']
191 # for each variable name in the Accessibility namespace, check if it starts
192 # with at least one of the prefixes above; if it does, add a 2-tuple of 
193 # variable name and value to the values list
194 values = ((name, value) for name, value in acc_dict.items()
195           if len([p for p in prefixes if name.startswith(p)]))
196 # create a new dictionary from the list of tuples and then update the local
197 # namespace dictionary with that dictionary
198 loc_dict.update(dict(values))
199
200 # build a dictionary mapping state values to names based on the prefix of the
201 # constant name imported from Accessibility
202 STATE_VALUE_TO_NAME = dict(((value, name[6:].lower().replace('_', ' ')) 
203                             for name, value 
204                             in acc_dict.items()
205                             if name.startswith('STATE_')))
206
207 # build a dictionary mapping relation values to names based on the prefix of 
208 # the constant name imported from Accessibility
209 RELATION_VALUE_TO_NAME = dict(((value, name[9:].lower().replace('_', ' ')) 
210                                for name, value 
211                                in acc_dict.items()
212                                if name.startswith('RELATION_')))
213
214 # throw away any temporary variables so they don't hang around in this module
215 del acc_dict, loc_dict, prefixes, values