2009-27-09 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / pyatspi / editabletext.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 factory import accessible_factory
17 from text import *
18
19 __all__ = [
20            "EditableText",
21           ]
22
23 #------------------------------------------------------------------------------
24
25 class EditableText(Text):
26         """
27         Derived from interface Text, EditableText provides methods for
28         modifying textual content of components which support editing.
29         EditableText also interacts with the system clipboard via copyText,
30         cutText, and pasteText.
31         """
32
33         def copyText(self, start, end):
34                 """
35                 Copy a range of text into the system clipboard. 
36                 @param : startPos
37                 the character offset of the first character in the range of text
38                 being copied. 
39                 @param : endPos
40                 the offset of the first character past the end of the range of
41                 text being copied.
42                 """
43                 func = self.get_dbus_method("copyText", dbus_interface=ATSPI_EDITABLE_TEXT)
44                 return func(start, end)
45
46         def cutText(self, start, end):
47                 """
48                 Excise a range of text from a Text object, copying it into the
49                 system clipboard. 
50                 @param : startPos
51                 the character offset of the first character in the range of text
52                 being cut. 
53                 @param : endPos
54                 the offset of the first character past the end of the range of
55                 text being cut. 
56                 @return True if the text was successfully cut, False otherwise.
57                 """
58                 func = self.get_dbus_method("cutText", dbus_interface=ATSPI_EDITABLE_TEXT)
59                 return func(start, end)
60
61         def deleteText(self, start, end):
62                 """
63                 Excise a range of text from a Text object without copying it
64                 into the system clipboard. 
65                 @param : startPos
66                 the character offset of the first character in the range of text
67                 being deleted. 
68                 @param : endPos
69                 the offset of the first character past the end of the range of
70                 text being deleted. 
71                 @return True if the text was successfully deleted, False otherwise.
72                 """
73                 func = self.get_dbus_method("deleteText", dbus_interface=ATSPI_EDITABLE_TEXT)
74                 return func(start, end)
75
76         def insertText(self, position, text, length):
77                 """
78                 Insert new text contents into an existing text object at a given
79                 location, while retaining the old contents. 
80                 @param : position
81                 the character offset into the Text implementor's content at which
82                 the new content will be inserted. 
83                 @param : text
84                 a UTF-8 string of which length characters will be inserted into
85                 the text object's text buffer. 
86                 @param : length
87                 the number of characters of text to insert. If the character
88                 count of text is less than or equal to length, the entire contents
89                 of text will be inserted.
90                 @return True if the text content was successfully inserted, False
91                 otherwise.
92                 """
93                 func = self.get_dbus_method("insertText", dbus_interface=ATSPI_EDITABLE_TEXT)
94                 return func(position, text, length)
95
96         def pasteText(self, position):
97                 """
98                 Copy the text contents of the system clipboard, if any, into
99                 a Text object, inserting it at a particular character offset.
100                 @param : position
101                 the character offset before which the text will be inserted.
102                 @return True if the text was successfully pasted into the Text
103                 object, False otherwise.
104                 """
105                 func = self.get_dbus_method("pasteText", dbus_interface=ATSPI_EDITABLE_TEXT)
106                 return func(position)
107
108         def setTextContents(self, contents):
109                 """
110                 Replace the text contents with a new string, discarding the old
111                 contents.
112                 @param : newContents
113                 a UTF-8 string with which the text object's contents will be
114                 replaced. 
115                 @return True if the text content was successfully changed, False
116                 otherwise.
117                 """
118                 func = self.get_dbus_method("setTextContents", dbus_interface=ATSPI_EDITABLE_TEXT)
119                 return func(contents)
120
121 # Register the accessible class with the factory.
122 accessible_factory.register_accessible_class(ATSPI_EDITABLE_TEXT, EditableText)
123
124 #END----------------------------------------------------------------------------