[pyatspi2] Demonstrates text interface use This python script will an example of how the the pyatspi2 text inte
- From: Mike Gorse <mgorse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pyatspi2] Demonstrates text interface use This python script will an example of how the the pyatspi2 text inte
- Date: Mon, 3 Jun 2013 16:53:54 +0000 (UTC)
commit 05a22cf636e0cf55376559751759d3c7126e8de9
Author: Magdalen Berns <thismagpie live com>
Date: Fri May 31 17:39:44 2013 +0100
Demonstrates text interface use This python script will an example of how the the pyatspi2 text interface
can be used. text.py: https://git.gnome.org/browse/pyatspi2/tree/pyatspi/text.py
caret.py contains:
A client to listen out for a caret move
A function to print the following at the offset:
* The current character
* The current word
* The current sentence
* The current line
Runs fine with latest version of python as well as python 2
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=701063
examples/caret.py | 43 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/examples/caret.py b/examples/caret.py
new file mode 100644
index 0000000..08b52bd
--- /dev/null
+++ b/examples/caret.py
@@ -0,0 +1,43 @@
+#!/usr/bin/python
+#
+# caret.py
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
+# Boston MA 02110-1301 USA.
+#
+# This example demonstrates how the pyatspi2 text interface can be used.
+
+import pyatspi
+
+def on_caret_move(event):
+ if event.source and event.source.getRole() == pyatspi.ROLE_TERMINAL:
+ return
+
+ print_text_at_offset(event.source, event.detail1)
+
+def print_text_at_offset(obj, offset):
+ try:
+ text = obj.queryText()
+ except:
+ return
+ else:
+ char, char_start_offset, char_end_offset = text.getTextAtOffset(offset, pyatspi.TEXT_BOUNDARY_CHAR)
+ word, word_start_offset, word_end_offset = text.getTextAtOffset(offset,
pyatspi.TEXT_BOUNDARY_WORD_START)
+ sentence, sentence_start_offset, sentence_end_offset = text.getTextAtOffset(offset,
pyatspi.TEXT_BOUNDARY_SENTENCE_START)
+ line, line_start_offset, line_end_offset =
text.getTextAtOffset(offset,pyatspi.TEXT_BOUNDARY_LINE_START)
+ print("\n\nChar:%s \nWord:%s \nSentence:%s Line:%s " % (char, word, sentence, line))
+
+pyatspi.Registry.registerEventListener(on_caret_move, "object:text-caret-moved")
+pyatspi.Registry.start()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]