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