Package pyLinAcc :: Module Constants
[hide private]
[frames] | no frames]

Source Code for Module pyLinAcc.Constants

  1  ''' 
  2  Defines constants used throughout pyLinAcc. 
  3   
  4  @author: Peter Parente 
  5  @author: Pete Brunet 
  6  @organization: IBM Corporation 
  7  @copyright: Copyright (c) 2005, 2007 IBM Corporation 
  8  @license: The BSD License 
  9   
 10  All rights reserved. This program and the accompanying materials are made  
 11  available under the terms of the BSD license which accompanies 
 12  this distribution, and is available at 
 13  U{http://www.opensource.org/licenses/bsd-license.php} 
 14  ''' 
 15  import Accessibility, ORBit 
 16   
 17  # interface name strings for ease of reference 
 18  DEVICEEVENT_LISTENER_IDL = 'IDL:Accessibility/DeviceEventListener:1.0' 
 19  EVENT_LISTENER_IDL = 'IDL:Accessibility/EventListener:1.0' 
 20  ACTION_IDL = 'IDL:Accessibility/Action:1.0' 
 21  ACCESSIBLE_IDL = 'IDL:Accessibility/Accessible:1.0' 
 22  APPLICATION_IDL = 'IDL:Accessibility/Application:1.0' 
 23  COLLECTION_IDL = 'IDL:Accessibility/Collection:1.0' 
 24  COMPONENT_IDL = 'IDL:Accessibility/Component:1.0' 
 25  DESKTOP_IDL = 'IDL:Accessibility/Desktop:1.0' 
 26  DOCUMENT_IDL = 'IDL:Accessibility/Document:1.0' 
 27  EDITABLE_TEXT_IDL = 'IDL:Accessibility/EditableText:1.0' 
 28  HYPERLINK_IDL = 'IDL:Accessibility/Hyperlink:1.0' 
 29  HYPERTEXT_IDL = 'IDL:Accessibility/Hypertext:1.0' 
 30  IMAGE_IDL = 'IDL:Accessibility/Image:1.0' 
 31  LOGIN_HELPER_IDL = 'IDL:Accessibility/LoginHelper:1.0' 
 32  STREAMABLE_CONTENT_IDL = 'IDL:Accessibility/StreamableContent:1.0' 
 33  TABLE_IDL = 'IDL:Accessibility/Table:1.0' 
 34  TEXT_IDL = 'IDL:Accessibility/Text:1.0' 
 35  VALUE_IDL = 'IDL:Accessibility/Value:1.0' 
 36  SELECTION_IDL = 'IDL:Accessibility/Selection:1.0' 
 37   
 38  # constants used in the Component interface to get screen coordinates 
 39  DESKTOP_COORDS = 0 
 40  WINDOW_COORDS = 1 
 41   
 42  # provides pretty names for keyboard device events 
 43  name_to_device_type = {'keyboard:release' : Accessibility.KEY_RELEASED_EVENT, 
 44                         'keyboard:press' : Accessibility.KEY_PRESSED_EVENT} 
 45  device_type_to_name = {Accessibility.KEY_RELEASED : 'keyboard:release', 
 46                         Accessibility.KEY_PRESSED : 'keyboard:press'} 
 47                          
 48  # pull important exceptions into the local namespace so other modules don't have 
 49  # to reference CORBA directly 
 50  CORBAException = ORBit.CORBA.Exception 
 51  SystemException = ORBit.CORBA.SystemException 
 52  UserException = ORBit.CORBA.UserException 
 53  NotImplemented = ORBit.CORBA.NO_IMPLEMENT 
 54  CommFailure = ORBit.CORBA.COMM_FAILURE 
 55  NotExist = ORBit.CORBA.OBJECT_NOT_EXIST 
 56   
 57  # dictionary used to correct the bug of not being able to register for all the 
 58  # subevents given only an AT-SPI event class (i.e. first part of the event name) 
 59  # keys are event names having subevents and values are the subevents under the 
 60  # key event 
 61  event_tree = { 
 62    'terminal': 
 63      ['terminal:line-changed', 
 64       'terminal:columncount-changed', 
 65       'terminal:linecount-changed', 
 66       'terminal:application-changed', 
 67       'terminal:charwidth-changed' 
 68       ], 
 69    'document': 
 70      ['document:load-complete', 
 71       'document:reload', 
 72       'document:load-stopped', 
 73       'document:content-changed', 
 74       'document:attributes-changed' 
 75       ], 
 76    'object':  
 77      ['object:property-change', 
 78       'object:bounds-changed', 
 79       'object:link-selected', 
 80       'object:state-changed', 
 81       'object:children-changed', 
 82       'object:visible-data-changed', 
 83       'object:selection-changed', 
 84       'object:model-changed', 
 85       'object:active-descendant-changed', 
 86       'object:row-inserted', 
 87       'object:row-reordered', 
 88       'object:row-deleted', 
 89       'object:column-inserted', 
 90       'object:column-reordered', 
 91       'object:column-deleted', 
 92       'object:text-bounds-changed', 
 93       'object:text-selection-changed', 
 94       'object:text-changed', 
 95       'object:text-attributes-changed', 
 96       'object:text-caret-moved',   
 97       'object:attributes-changed'], 
 98    'object:text-changed' : 
 99      ['object:text-changed:insert', 
100      'object:text-changed:delete'], 
101    'object:property-change' : 
102      ['object:property-change:accessible-parent',  
103      'object:property-change:accessible-name', 
104      'object:property-change:accessible-description', 
105      'object:property-change:accessible-value', 
106      'object:property-change:accessible-role', 
107      'object:property-change:accessible-table-caption', 
108      'object:property-change:accessible-table-column-description', 
109      'object:property-change:accessible-table-column-header', 
110      'object:property-change:accessible-table-row-description', 
111      'object:property-change:accessible-table-row-header', 
112      'object:property-change:accessible-table-summary'], 
113    'object:children-changed' : 
114      ['object:children-changed:add', 
115      'object:children-changed:remove'], 
116    # PP: do we really want to list these? then we have to keep them in sync with 
117    # the states actually defined by AT-SPI 
118    'object:state-changed' : 
119      ['object:state-changed:active', 
120      'object:state-changed:armed', 
121      'object:state-changed:busy', 
122      'object:state-changed:checked', 
123      'object:state-changed:collapsed', 
124      'object:state-changed:defunct', 
125      'object:state-changed:editable', 
126      'object:state-changed:enabled', 
127      'object:state-changed:expandable', 
128      'object:state-changed:expanded', 
129      'object:state-changed:focusable', 
130      'object:state-changed:focused', 
131      'object:state-changed:has-tooltip', 
132      'object:state-changed:horizontal', 
133      'object:state-changed:iconified', 
134      'object:state-changed:indeterminate', 
135      'object:state-changed:invalid', 
136      'object:state-changed:last-defined', 
137      'object:state-changed:manages-descendants', 
138      'object:state-changed:modal', 
139      'object:state-changed:multi-line', 
140      'object:state-changed:multiselectable', 
141      'object:state-changed:opaque', 
142      'object:state-changed:pressed', 
143      'object:state-changed:resizable', 
144      'object:state-changed:selectable', 
145      'object:state-changed:selected', 
146      'object:state-changed:sensitive', 
147      'object:state-changed:showing', 
148      'object:state-changed:single-line', 
149      'object:state-changed:stale', 
150      'object:state-changed:transient', 
151      'object:state-changed:vertical', 
152      'object:state-changed:visible'], 
153    'mouse' : 
154      ['mouse:abs', 
155      'mouse:rel', 
156      'mouse:button'], 
157    'mouse:button' : 
158      ['mouse:button:1p', 
159      'mouse:button:1r', 
160      'mouse:button:2p', 
161      'mouse:button:2r', 
162      'mouse:button:3p', 
163      'mouse:button:3r'], 
164    'window' : 
165      ['window:minimize', 
166      'window:maximize', 
167      'window:restore', 
168      'window:close', 
169      'window:create', 
170      'window:reparent', 
171      'window:desktop-create', 
172      'window:desktop-destroy', 
173      'window:activate', 
174      'window:deactivate', 
175      'window:raise', 
176      'window:lower', 
177      'window:move', 
178      'window:resize', 
179      'window:shade', 
180      'window:unshade', 
181      'window:restyle'], 
182    'keyboard' : 
183      ['keyboard:press', 
184      'keyboard:release'], 
185    'focus' : 
186      ['focus:'] 
187  } 
188   
189  # recommendation for which tasks should be displayed by default by EventMonitor 
190  default_types = ['window', 'focus', 'object:active-descendant-changed'] 
191  # all registered Task types; used to build display menu in EventMonitor 
192  all_types = ['window', 'focus', 'mouse', 'keyboard'] 
193  all_types.extend(event_tree['object']) 
194   
195  # pull ROLE_*, STATE_*, TEXT_*, MODIFIER_*, LOCALE_*, and RELATION_*, etc.  
196  # constants into the local namespace for convenient access 
197  # grab all the variable names and their values from the Accessibility module 
198  acc_dict = vars(Accessibility) 
199  # get the dictionary for the local namespace 
200  loc_dict = locals() 
201  # these are the prefixes for the variable names we want to pull out of the  
202  # Accessibility module 
203  prefixes = ['ROLE_', 'STATE_', 'TEXT_', 'MODIFIER_', 'LOCALE_', 'RELATION_', 
204              'KEY_', 'MATCH_', 'SORT_', 'LAYER_'] 
205   
206  # build a dictionary mapping state values to names based on the prefix of the 
207  # constant name imported from Accessibility 
208  state_val_to_name = dict(((value, name[6:].lower().replace('_', ' '))  
209                            for name, value  
210                            in acc_dict.items() 
211                            if name.startswith('STATE_'))) 
212   
213  # build a dictionary mapping relation values to names based on the prefix of  
214  # the constant name imported from Accessibility 
215  rel_val_to_name = dict(((value, name[9:].lower().replace('_', ' '))  
216                            for name, value  
217                            in acc_dict.items() 
218                            if name.startswith('RELATION_'))) 
219   
220  # build a dictionary mapping modifier values to names based on the prefix of  
221  # the constant name imported from Accessibility 
222  mod_val_to_name = dict(((value, name[9:].lower().replace('_', ' '))  
223                            for name, value  
224                            in acc_dict.items() 
225                            if name.startswith('MODIFIER_'))) 
226   
227  # for each variable name in the Accessibility namespace, check if it starts with 
228  # at least one of the prefixes above; if it does, add a 2-tuple of variable name 
229  # and value to the values list 
230  values = ((name, value) for name, value in acc_dict.items() 
231            if len([p for p in prefixes if name.startswith(p)])) 
232  # create a new dictionary from the list of tuples and then update the local 
233  # namespace dictionary with that dictionary 
234  loc_dict.update(dict(values)) 
235  # throw away any temporary variables so they don't hang around in this module 
236  del acc_dict, loc_dict, prefixes, values 
237