1#Copyright (C) 2008 Codethink Ltd 2#copyright: Copyright (c) 2005, 2007 IBM Corporation 3 4#This library is free software; you can redistribute it and/or 5#modify it under the terms of the GNU Lesser General Public 6#License version 2 as published by the Free Software Foundation. 7 8#This program is distributed in the hope that it will be useful, 9#but WITHOUT ANY WARRANTY; without even the implied warranty of 10#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11#GNU General Public License for more details. 12#You should have received a copy of the GNU Lesser General Public License 13#along with this program; if not, write to the Free Software 14#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 16#Portions of this code originally licensed and copyright (c) 2005, 2007 17#IBM Corporation under the BSD license, available at 18#U{http://www.opensource.org/licenses/bsd-license.php} 19 20#authors: Peter Parente, Mark Doffman 21 22from gi.repository import Atspi 23from gi.repository import GObject 24from pyatspi.atspienum import * 25 26#------------------------------------------------------------------------------ 27 28class StateType(AtspiEnum): 29 _enum_lookup = { 30 0:'STATE_INVALID', 31 1:'STATE_ACTIVE', 32 2:'STATE_ARMED', 33 3:'STATE_BUSY', 34 4:'STATE_CHECKED', 35 5:'STATE_COLLAPSED', 36 6:'STATE_DEFUNCT', 37 7:'STATE_EDITABLE', 38 8:'STATE_ENABLED', 39 9:'STATE_EXPANDABLE', 40 10:'STATE_EXPANDED', 41 11:'STATE_FOCUSABLE', 42 12:'STATE_FOCUSED', 43 13:'STATE_HAS_TOOLTIP', 44 14:'STATE_HORIZONTAL', 45 15:'STATE_ICONIFIED', 46 16:'STATE_MODAL', 47 17:'STATE_MULTI_LINE', 48 18:'STATE_MULTISELECTABLE', 49 19:'STATE_OPAQUE', 50 20:'STATE_PRESSED', 51 21:'STATE_RESIZABLE', 52 22:'STATE_SELECTABLE', 53 23:'STATE_SELECTED', 54 24:'STATE_SENSITIVE', 55 25:'STATE_SHOWING', 56 26:'STATE_SINGLE_LINE', 57 27:'STATE_STALE', 58 28:'STATE_TRANSIENT', 59 29:'STATE_VERTICAL', 60 30:'STATE_VISIBLE', 61 31:'STATE_MANAGES_DESCENDANTS', 62 32:'STATE_INDETERMINATE', 63 33:'STATE_REQUIRED', 64 34:'STATE_TRUNCATED', 65 35:'STATE_ANIMATED', 66 36:'STATE_INVALID_ENTRY', 67 37:'STATE_SUPPORTS_AUTOCOMPLETION', 68 38:'STATE_SELECTABLE_TEXT', 69 39:'STATE_IS_DEFAULT', 70 40:'STATE_VISITED', 71 41:'STATE_CHECKABLE', 72 42:'STATE_HAS_POPUP', 73 43:'STATE_READ_ONLY', 74 44:'STATE_LAST_DEFINED', 75 } 76 77#------------------------------------------------------------------------------ 78 79STATE_ACTIVE = StateType(1) 80STATE_ANIMATED = StateType(35) 81STATE_ARMED = StateType(2) 82STATE_BUSY = StateType(3) 83STATE_CHECKABLE = StateType(41) 84STATE_CHECKED = StateType(4) 85STATE_COLLAPSED = StateType(5) 86STATE_DEFUNCT = StateType(6) 87STATE_EDITABLE = StateType(7) 88STATE_ENABLED = StateType(8) 89STATE_EXPANDABLE = StateType(9) 90STATE_EXPANDED = StateType(10) 91STATE_FOCUSABLE = StateType(11) 92STATE_FOCUSED = StateType(12) 93STATE_HAS_POPUP = StateType(42) 94STATE_HAS_TOOLTIP = StateType(13) 95STATE_HORIZONTAL = StateType(14) 96STATE_ICONIFIED = StateType(15) 97STATE_INDETERMINATE = StateType(32) 98STATE_INVALID = StateType(0) 99STATE_INVALID_ENTRY = StateType(36) 100STATE_IS_DEFAULT = StateType(39) 101STATE_LAST_DEFINED = StateType(44) 102STATE_MANAGES_DESCENDANTS = StateType(31) 103STATE_MODAL = StateType(16) 104STATE_MULTISELECTABLE = StateType(18) 105STATE_MULTI_LINE = StateType(17) 106STATE_OPAQUE = StateType(19) 107STATE_PRESSED = StateType(20) 108STATE_READ_ONLY = StateType(43) 109STATE_REQUIRED = StateType(33) 110STATE_RESIZABLE = StateType(21) 111STATE_SELECTABLE = StateType(22) 112STATE_SELECTABLE_TEXT = StateType(38) 113STATE_SELECTED = StateType(23) 114STATE_SENSITIVE = StateType(24) 115STATE_SHOWING = StateType(25) 116STATE_SINGLE_LINE = StateType(26) 117STATE_STALE = StateType(27) 118STATE_SUPPORTS_AUTOCOMPLETION = StateType(37) 119STATE_TRANSIENT = StateType(28) 120STATE_TRUNCATED = StateType(34) 121STATE_VERTICAL = StateType(29) 122STATE_VISIBLE = StateType(30) 123STATE_VISITED = StateType(40) 124 125#------------------------------------------------------------------------------ 126 127# Build a dictionary mapping state values to names based on the prefix of the enum constants. 128 129STATE_VALUE_TO_NAME = dict(((value, name[6:].lower().replace('_', ' ')) 130 for name, value 131 in globals().items() 132 if name.startswith('STATE_'))) 133 134#------------------------------------------------------------------------------ 135 136def stateset_init(self, *states): 137 GObject.GObject.__init__(self) 138 list(map(self.add, states)) 139 140# TODO: Fix pygobject so that this isn't needed (BGO#646581 may be related) 141def StateSet_getStates(self): 142 ret = [] 143 for i in range(0, 64): 144 if (self.states & (1 << i)): 145 ret.append(Atspi.StateType(i)) 146 return ret 147 148StateSet = Atspi.StateSet 149StateSet.getStates = StateSet_getStates 150StateSet.isEmpty = StateSet.is_empty 151StateSet.raw = lambda x: x 152StateSet.unref = lambda x: None 153StateSet.__init__ = stateset_init 154