2009-27-09 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / pyatspi / hyperlink.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 accessible import Accessible
17 from factory import accessible_factory
18
19 import dbus
20
21 __all__ = [
22            "Hyperlink",
23           ]
24
25 #------------------------------------------------------------------------------
26
27 class Hyperlink(Accessible):
28         """
29         Instances of Hyperlink are returned by Hypertext objects, and
30         are the means by which end users and clients interact with linked,
31         and in some cases embedded, content. Hyperlinks may have multiple
32         "anchors", where an anchor corresponds to a reference to a particular
33         resource with a corresponding resource identified (URI). Hyperlinks
34         may be queried for their URIs, or queried for the objects corresponding
35         to their anchors. The objects thus obtained are instances of
36         Accessible, and may be queried, and manipulated via the Action
37         interface.
38         """
39
40         def getObject(self, index):
41                 """
42                 Gets the i'th object, (where i is an integer between 0 and Hyperlink::numAnchors
43                 - 1, inclusive) associated with a Hyperlink. The objects returned
44                 are usually actionable (i.e. they should implement Accessibility::Action),
45                 and the available actions often include "open", "bookmark", "save
46                 link as", etc. They may also implement Accessibility::StreamableContent,
47                 although clients can normally use getURI to obtain a resource
48                 locator via which the object's data may be accessed.
49                 @return an Accessible object instance representing the Hyperlink's
50                 ith anchor, or through which the content associated with the
51                 ith anchor can be accessed.
52                 """
53                 func = self.get_dbus_method("getObject", dbus_interface=ATSPI_HYPERLINK)
54                 return self._cache.create_accessible(self._app_name, func(index),
55                                                      interfaces.ATSPI_HYPERLINK)
56
57         def getURI(self, index):
58                 """
59                 Obtain a resource locator ('URI') which can be used to access
60                 the content to which this link "points" or is connected. 
61                 @return a string corresponding to the URI of the Hyperlink's
62                 'ith' anchor, if one exists, or a NIL string otherwise.
63                 """
64                 func = self.get_dbus_method("getURI", dbus_interface=ATSPI_HYPERLINK)
65                 return func(index)
66
67         def isValid(self):
68                 """
69                 Check the hyperlink to see if a connection to its backing content
70                 can be established, or if its URI is valid. 
71                 @return True if the object's content is available, or False if
72                 the hyperlink's URI is invalid, or a connection to the resource
73                 can not be established.
74                 """
75                 func = self.get_dbus_method("isValid", dbus_interface=ATSPI_HYPERLINK)
76                 return func()
77
78         def get_endIndex(self):
79                 return dbus.Int32(self._pgetter(self._dbus_interface, "endIndex"))
80         _endIndexDoc = \
81                 """
82                 the ending offset within the containing Hypertext content with
83                 which this Hyperlink is associated; that is, the offset of the
84                 first element past the range within the Hypertext associated
85                 with this Hyperlink.
86                 """
87         endIndex = property(fget=get_endIndex, doc=_endIndexDoc)
88
89         def get_nAnchors(self):
90                 return dbus.Int16(self._pgetter(self._dbus_interface, "nAnchors"))
91         _nAnchorsDoc = \
92                 """
93                 the number of separate anchors associated with this Hyperlink
94                 """
95         nAnchors = property(fget=get_nAnchors, doc=_nAnchorsDoc)
96
97         def get_startIndex(self):
98                 return dbus.Int32(self._pgetter(self._dbus_interface, "startIndex"))
99         _startIndexDoc = \
100                 """
101                 the starting offset within the containing Hypertext content with
102                 which this Hyperlink is associated
103                 """
104         startIndex = property(fget=get_startIndex, doc=_startIndexDoc)
105
106 # Register the accessible class with the factory.
107 accessible_factory.register_accessible_class(ATSPI_HYPERLINK, Hyperlink)
108
109 #END----------------------------------------------------------------------------