Package Tools :: Module Atk
[hide private]
[frames] | no frames]

Source Code for Module Tools.Atk

 1  ''' 
 2  Defines convenience methods for using Gnome ATK/GAIL accessibility platform, 
 3  using the atk.py bindings.  Allows Python developers to easily write accessible 
 4  applications without knowledge of arcane ATK programming patterns and syntax. 
 5   
 6  @author: Brett Clippingdale 
 7  @author: Pete Parente 
 8  @organization: IBM Corporation 
 9  @copyright: Copyright (c) 2005, 2007 IBM Corporation 
10  @license: The BSD License 
11   
12  All rights reserved. This program and the accompanying materials are made 
13  available under the terms of the BSD license which accompanies 
14  this distribution, and is available at 
15  U{http://www.opensource.org/licenses/bsd-license.php} 
16  ''' 
17  import atk 
18   
19 -def setNameDesc(widget, name=None, description=None, row=None, col=0):
20 ''' 21 Sets the name, and description (optional), of a GTK+ widget. Example code:: 22 23 import pyatk 24 pyatk.setNameDesc(apply_button, 'Apply') 25 pyatk.setNameDesc(up_button, 'Up', 'Move the selected item up") 26 pyatk.setNameDesc(my_table, 'Y5Q3', 'Year Five, Quarter Three", 4, 2) 27 28 @param widget: Some GTK+ widget 29 @type widget: gtk.Object 30 @param name: Accessible name to set 31 @type name: string 32 @param description: Accessible description to set 33 @type description: string 34 @param row: row, if in a table/tree 35 @type row: integer 36 @param col: column, if in a table/tree 37 @type col: integer 38 ''' 39 acc = widget.get_accessible() 40 if row is not None: # it's a table/tree 41 model = widget.get_model() 42 numCols = model.get_n_columns() # each column has a header row 43 # skip the table headers 44 acc = acc.ref_accessible_child( numCols + (row * numCols) + col) 45 if name is not None: 46 acc.set_name(name) # widget.set_name() is not sufficient 47 if description is not None: 48 acc.set_description(description)
49
50 -def setRelation(source, atk_relation, *targets):
51 ''' 52 Sets the relation between a GTK+ source widget and one or more GTK+ target 53 widgets. Example code:: 54 55 import atk, pyatk 56 pyatk.setRelation(item, atk.RELATION_LABELLED_BY, item_label) 57 pyatk.setRelation(group_label, atk.RELATION_LABEL_FOR, member1, member2) 58 pyatk.setRelation(spinner_button, atk.RELATION_CONTROLLER_FOR, spinner) 59 60 For a list and definition of ATK relationships, see: 61 U{http://developer.gnome.org/doc/API/2.0/atk/AtkRelation.html} 62 63 @param source: Source accessible on which the relation will be set 64 @type source: atk.Object 65 @param atk_relation: Relation to set 66 @type atk_relation: atk.Relation 67 @param targets: Target accessibles of the relation 68 @type targets: list of atk.Object 69 ''' 70 acc_targets = [] # list of accessible widgets to apply relation attribute 71 acc_src = source.get_accessible() 72 relation_set = acc_src.ref_relation_set() 73 # get a reference to each widget and add to the accessible target list 74 for target in targets: 75 acc_targ = target.get_accessible() 76 acc_targets.append(acc_targ) 77 relation = atk.Relation(acc_targets, 1) # create the relation 78 relation.set_property('relation-type', atk_relation) 79 relation_set.add(relation) # apply the relation to the target widget(s)
80