9e7b36f0c6e5fa71394d5264cabdd9fcec8bb510
[platform/core/uifw/at-spi2-atk.git] / pyatspi / component.py
1 #Copyright (C) 2008 Codethink Ltd
2
3 #This library is free software; you can redistribute it and/or
4 #modify it under the terms of the GNU Lesser General Public
5 #License version 2 as published by the Free Software Foundation.
6
7 #This program is distributed in the hope that it will be useful,
8 #but WITHOUT ANY WARRANTY; without even the implied warranty of
9 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 #GNU General Public License for more details.
11 #You should have received a copy of the GNU Lesser General Public License
12 #along with this program; if not, write to the Free Software
13 #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14
15 from interfaces import *
16 from base import Enum
17 from factory import accessible_factory
18 from accessible import BoundingBox, Accessible
19
20 from dbus.types import UInt32
21
22 __all__ = [
23            "CoordType",
24            "XY_SCREEN",
25            "XY_WINDOW",
26            "ComponentLayer",
27            "Component",
28            "LAYER_BACKGROUND",
29            "LAYER_CANVAS",
30            "LAYER_INVALID",
31            "LAYER_LAST_DEFINED",
32            "LAYER_MDI",
33            "LAYER_OVERLAY",
34            "LAYER_POPUP",
35            "LAYER_WIDGET",
36            "LAYER_WINDOW",
37           ]
38
39 #------------------------------------------------------------------------------
40
41 class CoordType(Enum):
42         _enum_lookup = {
43                 0:'XY_SCREEN',
44                 1:'XY_WINDOW',
45         }
46
47 XY_SCREEN = CoordType(0)
48 XY_WINDOW = CoordType(1)
49
50 #------------------------------------------------------------------------------
51
52 class ComponentLayer(Enum):
53         _enum_lookup = {
54                 0:'LAYER_INVALID',
55                 1:'LAYER_BACKGROUND',
56                 2:'LAYER_CANVAS',
57                 3:'LAYER_WIDGET',
58                 4:'LAYER_MDI',
59                 5:'LAYER_POPUP',
60                 6:'LAYER_OVERLAY',
61                 7:'LAYER_WINDOW',
62                 8:'LAYER_LAST_DEFINED',
63         }
64
65 LAYER_BACKGROUND = ComponentLayer(1)
66 LAYER_CANVAS = ComponentLayer(2)
67 LAYER_INVALID = ComponentLayer(0)
68 LAYER_LAST_DEFINED = ComponentLayer(8)
69 LAYER_MDI = ComponentLayer(4)
70 LAYER_OVERLAY = ComponentLayer(6)
71 LAYER_POPUP = ComponentLayer(5)
72 LAYER_WIDGET = ComponentLayer(3)
73 LAYER_WINDOW = ComponentLayer(7)
74
75 #------------------------------------------------------------------------------
76
77 class Component(Accessible):
78         """
79         The Component interface is implemented by objects which occupy
80         on-screen space, e.g. objects which have onscreen visual representations.
81         The methods in Component allow clients to identify where the
82         objects lie in the onscreen coordinate system, their relative
83         size, stacking order, and position. It also provides a mechanism
84         whereby keyboard focus may be transferred to specific user interface
85         elements programmatically. This is a 2D API, coordinates of 3D
86         objects are projected into the 2-dimensional screen view for
87         purposes of this interface.
88         """
89
90         def contains(self, x, y, coord_type):
91                 """
92                 @return True if the specified point lies within the Component's
93                 bounding box, False otherwise.
94                 """
95                 func = self.get_dbus_method("contains", dbus_interface=ATSPI_COMPONENT)
96                 return func(x, y, UInt32(coord_type))
97
98         def getAccessibleAtPoint(self, x, y, coord_type):
99                 """
100                 @return the Accessible child whose bounding box contains the
101                 specified point.
102                 """
103                 func = self.get_dbus_method("getAccessibleAtPoint", dbus_interface=ATSPI_COMPONENT)
104                 return self._cache.create_accessible(self._app_name,
105                                                      func(x, y, UInt32(coord_type)),
106                                                      interfaces.ATSPI_COMPONENT)
107
108         def getAlpha(self):
109                 """
110                 Obtain the alpha value of the component. An alpha value of 1.0
111                 or greater indicates that the object is fully opaque, and an
112                 alpha value of 0.0 indicates that the object is fully transparent.
113                 Negative alpha values have no defined meaning at this time.
114                 """
115                 func = self.get_dbus_method("getAlpha", dbus_interface=ATSPI_COMPONENT)
116                 return func()
117
118         def getExtents(self, coord_type):
119                 """
120                 Obtain the Component's bounding box, in pixels, relative to the
121                 specified coordinate system. 
122                 @param coord_type
123                 @return a BoundingBox which entirely contains the object's onscreen
124                 visual representation.
125                 """
126                 func = self.get_dbus_method("getExtents", dbus_interface=ATSPI_COMPONENT)
127                 extents = func(UInt32(coord_type))
128                 return BoundingBox(*extents)
129
130         def getLayer(self):
131                 """
132                 @return the ComponentLayer in which this object resides.
133                 """
134                 func = self.get_dbus_method("getLayer", dbus_interface=ATSPI_COMPONENT)
135                 return ComponentLayer(func())
136
137         def getMDIZOrder(self):
138                 """
139                 Obtain the relative stacking order (i.e. 'Z' order) of an object.
140                 Larger values indicate that an object is on "top" of the stack,
141                 therefore objects with smaller MDIZOrder may be obscured by objects
142                 with a larger MDIZOrder, but not vice-versa. 
143                 @return an integer indicating the object's place in the stacking
144                 order.
145                 """
146                 func = self.get_dbus_method("getMDIZOrder", dbus_interface=ATSPI_COMPONENT)
147                 return func()
148
149         def getPosition(self, coord_type):
150                 """
151                 Obtain the position of the current component in the coordinate
152                 system specified by coord_type. 
153                 @param : coord_type
154                 @param : x
155                 an out parameter which will be back-filled with the returned
156                 x coordinate. 
157                 @param : y
158                 an out parameter which will be back-filled with the returned
159                 y coordinate.
160                 """
161                 func = self.get_dbus_method("getPosition", dbus_interface=ATSPI_COMPONENT)
162                 return func(UInt32(coord_type))
163
164         def getSize(self):
165                 """
166                 Obtain the size, in the coordinate system specified by coord_type,
167                 of the rectangular area which fully contains the object's visual
168                 representation, without accounting for viewport clipping. 
169                 @param : width
170                 the object's horizontal extents in the specified coordinate system.
171                 @param : height
172                 the object's vertical extents in the specified coordinate system.
173                 """
174                 func = self.get_dbus_method("getSize", dbus_interface=ATSPI_COMPONENT)
175                 return func()
176
177         def grabFocus(self):
178                 """
179                 Request that the object obtain keyboard focus.
180                 @return True if keyboard focus was successfully transferred to
181                 the Component.
182                 """
183                 func = self.get_dbus_method("grabFocus", dbus_interface=ATSPI_COMPONENT)
184                 return func()
185
186 # Register the accessible class with the factory.
187 accessible_factory.register_accessible_class(ATSPI_COMPONENT, Component)
188
189 #END----------------------------------------------------------------------------