[pyatspi2] Refactor EditableText so that Text methods can be called from it



commit e8a5dd837f3106f4c0720db2a2ce7530ce1ceb99
Author: Mike Gorse <mgorse novell com>
Date:   Thu Feb 3 12:04:21 2011 -0600

    Refactor EditableText so that Text methods can be called from it

 pyatspi/Accessibility.py |   10 +---
 pyatspi/Makefile.am      |    1 +
 pyatspi/editabletext.py  |  115 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 8 deletions(-)
---
diff --git a/pyatspi/Accessibility.py b/pyatspi/Accessibility.py
index 9c487b9..4fb8431 100644
--- a/pyatspi/Accessibility.py
+++ b/pyatspi/Accessibility.py
@@ -18,6 +18,7 @@ from registry import *
 Registry = Registry()
 
 from constants import *
+from editabletext import *
 from role import *
 from state import *
 from text import *
@@ -174,14 +175,7 @@ Atspi.Component.setSize = Atspi.Component.set_size
 Atspi.Accessible.queryDocument = lambda x: Document(getInterface(Atspi.Accessible.get_document, x))
 
 ### editable text ###
-EditableText = Atspi.EditableText
-Atspi.Accessible.queryEditableText = lambda x: getInterface(Atspi.Accessible.get_editable_text, x)
-Atspi.EditableText.copyText = Atspi.EditableText.copy_text
-Atspi.EditableText.cutText = Atspi.EditableText.cut_text
-Atspi.EditableText.deleteText = Atspi.EditableText.delete_text
-Atspi.EditableText.insertText = Atspi.EditableText.insert_text
-Atspi.EditableText.pasteText = Atspi.EditableText.paste_text
-Atspi.EditableText.setTextContents = Atspi.EditableText.set_text_contents
+Atspi.Accessible.queryEditableText = lambda x: EditableText(getInterface(Atspi.Accessible.get_text, x))
 
 ### hyperlink ###
 Hyperlink = Atspi.Hyperlink
diff --git a/pyatspi/Makefile.am b/pyatspi/Makefile.am
index 7fc96f2..e1ae1e2 100644
--- a/pyatspi/Makefile.am
+++ b/pyatspi/Makefile.am
@@ -18,6 +18,7 @@ pyatspi_PYTHON = \
 		factory.py		\
 		__init__.py		\
 	document.py \
+	editabletext.py \
 		interfaces.py		\
 		registry.py		\
 		role.py			\
diff --git a/pyatspi/editabletext.py b/pyatspi/editabletext.py
new file mode 100644
index 0000000..ead32a4
--- /dev/null
+++ b/pyatspi/editabletext.py
@@ -0,0 +1,115 @@
+#Copyright (C) 2008 Codethink Ltd
+
+#This library is free software; you can redistribute it and/or
+#modify it under the terms of the GNU Lesser General Public
+#License version 2 as published by the Free Software Foundation.
+
+#This program is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#GNU General Public License for more details.
+#You should have received a copy of the GNU Lesser General Public License
+#along with this program; if not, write to the Free Software
+#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+from interfaces import *
+from text import *
+from gi.repository import Atspi
+
+__all__ = [
+           "EditableText",
+          ]
+
+#------------------------------------------------------------------------------
+
+class EditableText(Text):
+        """
+        Derived from interface Text, EditableText provides methods for
+        modifying textual content of components which support editing.
+        EditableText also interacts with the system clipboard via copyText,
+        cutText, and pasteText.
+        """
+
+        def copyText(self, start, end):
+                """
+                Copy a range of text into the system clipboard. 
+                @param : startPos
+                the character offset of the first character in the range of text
+                being copied. 
+                @param : endPos
+                the offset of the first character past the end of the range of
+                text being copied.
+                """
+                return Atspi.EditableText.copy_text(self.obj, start, end)
+
+        def cutText(self, start, end):
+                """
+                Excise a range of text from a Text object, copying it into the
+                system clipboard. 
+                @param : startPos
+                the character offset of the first character in the range of text
+                being cut. 
+                @param : endPos
+                the offset of the first character past the end of the range of
+                text being cut. 
+                @return True if the text was successfully cut, False otherwise.
+                """
+                return Atspi.EditableText.cut_text(self.obj, start, end)
+
+        def deleteText(self, start, end):
+                """
+                Excise a range of text from a Text object without copying it
+                into the system clipboard. 
+                @param : startPos
+                the character offset of the first character in the range of text
+                being deleted. 
+                @param : endPos
+                the offset of the first character past the end of the range of
+                text being deleted. 
+                @return True if the text was successfully deleted, False otherwise.
+                """
+                return Atspi.EditableText.delete_text(self.obj, start, end)
+
+        def insertText(self, position, text, length):
+                """
+                Insert new text contents into an existing text object at a given
+                location, while retaining the old contents. 
+                @param : position
+                the character offset into the Text implementor's content at which
+                the new content will be inserted. 
+                @param : text
+                a UTF-8 string of which length characters will be inserted into
+                the text object's text buffer. 
+                @param : length
+                the number of characters of text to insert. If the character
+                count of text is less than or equal to length, the entire contents
+                of text will be inserted.
+                @return True if the text content was successfully inserted, False
+                otherwise.
+                """
+                return Atspi.EditableText.insert_text(self.obj, position, text, length)
+
+        def pasteText(self, position):
+                """
+                Copy the text contents of the system clipboard, if any, into
+                a Text object, inserting it at a particular character offset.
+                @param : position
+                the character offset before which the text will be inserted.
+                @return True if the text was successfully pasted into the Text
+                object, False otherwise.
+                """
+                return Atspi.EditableText.paste_text(self.obj, position)
+
+        def setTextContents(self, contents):
+                """
+                Replace the text contents with a new string, discarding the old
+                contents.
+                @param : newContents
+                a UTF-8 string with which the text object's contents will be
+                replaced. 
+                @return True if the text content was successfully changed, False
+                otherwise.
+                """
+                return Atspi.EditableText.set_text_contents(self.obj, contents)
+
+#END----------------------------------------------------------------------------



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]