[orca] More work on terminal support: Tweak heuristic for auto-inserted text



commit 2f0909adfd6fd8cdd4bebd32edcad42cbad81d4d
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue Aug 23 13:24:31 2016 -0400

    More work on terminal support: Tweak heuristic for auto-inserted text

 src/orca/script_utilities.py                       |    6 -----
 src/orca/scripts/terminal/script.py                |    4 +-
 src/orca/scripts/terminal/script_utilities.py      |   23 ++++++++++++++++---
 test/harness/utils.py                              |    9 +++++++
 .../keystrokes/gnome-terminal/command_not_found.py |   23 ++++++++++++++++++++
 test/keystrokes/gnome-terminal/multiple_tabs.py    |    3 ++
 test/keystrokes/gnome-terminal/tab_completion.py   |   23 ++++++++++++++++++++
 7 files changed, 79 insertions(+), 12 deletions(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index df5c8fa..752b53d 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -4098,12 +4098,6 @@ class Utilities:
 
         return role in roles
 
-    def treatEventAsTerminalCommand(self, event):
-        return False
-
-    def treatEventAsTerminalNoise(self, event):
-        return False
-
     def isPresentableTextChangedEventForLocusOfFocus(self, event):
         if not event.type.startswith("object:text-changed:") \
            and not event.type.startswith("object:text-attributes-changed"):
diff --git a/src/orca/scripts/terminal/script.py b/src/orca/scripts/terminal/script.py
index 66f33a7..3bf1989 100644
--- a/src/orca/scripts/terminal/script.py
+++ b/src/orca/scripts/terminal/script.py
@@ -81,7 +81,7 @@ class Script(default.Script):
     def onTextDeleted(self, event):
         """Callback for object:text-changed:delete accessibility events."""
 
-        if self.utilities.treatEventAsTerminalNoise(event):
+        if self.utilities.treatEventAsNoise(event):
             msg = "TERMINAL: Deletion is believed to be noise"
             debug.println(debug.LEVEL_INFO, msg, True)
             return
@@ -91,7 +91,7 @@ class Script(default.Script):
     def onTextInserted(self, event):
         """Callback for object:text-changed:insert accessibility events."""
 
-        if not self.utilities.treatEventAsTerminalCommand(event):
+        if not self.utilities.treatEventAsCommand(event):
             super().onTextInserted(event)
             return
 
diff --git a/src/orca/scripts/terminal/script_utilities.py b/src/orca/scripts/terminal/script_utilities.py
index 3a8e1bd..9b2a954 100644
--- a/src/orca/scripts/terminal/script_utilities.py
+++ b/src/orca/scripts/terminal/script_utilities.py
@@ -46,6 +46,9 @@ class Utilities(script_utilities.Utilities):
         if len(event.any_data) == 1:
             return event.any_data
 
+        if self.isAutoTextEvent(event):
+            return event.any_data
+
         try:
             text = event.source.queryText()
         except:
@@ -69,10 +72,22 @@ class Utilities(script_utilities.Utilities):
     def isTextArea(self, obj):
         return True
 
-    def treatEventAsTerminalCommand(self, event):
-        if self.lastInputEventWasCommand():
-            return True
+    def isAutoTextEvent(self, event):
+        if not event.type.startswith("object:text-changed:insert"):
+            return False
+
+        if not event.any_data or not event.source:
+            return False
+
+        lastKey, mods = self.lastKeyAndModifiers()
+        if lastKey == "Tab":
+            return event.any_data != "\t"
+        if lastKey == "Return":
+            return event.any_data.startswith("\n")
+
+        return False
 
+    def treatEventAsCommand(self, event):
         if event.type.startswith("object:text-changed:insert") and event.any_data.strip():
             keyString, mods = self.lastKeyAndModifiers()
             if keyString in ["Return", "Tab", "space", " "]:
@@ -84,7 +99,7 @@ class Utilities(script_utilities.Utilities):
 
         return False
 
-    def treatEventAsTerminalNoise(self, event):
+    def treatEventAsNoise(self, event):
         if self.lastInputEventWasCommand():
             return False
 
diff --git a/test/harness/utils.py b/test/harness/utils.py
index d83aff3..58b0683 100644
--- a/test/harness/utils.py
+++ b/test/harness/utils.py
@@ -5,6 +5,7 @@ import re
 import sys
 
 from gi.repository import Gio
+from gi.repository import Gdk
 from macaroon.playback import *
 
 testLogger = Gio.DBusProxy.new_for_bus_sync(
@@ -34,6 +35,14 @@ if outFilename and len(outFilename):
 else:
     myOut = sys.stdout
 
+def getKeyCodeForName(name):
+    keymap = Gdk.Keymap.get_default()
+    success, entries = keymap.get_entries_for_keyval(Gdk.keyval_from_name(name))
+    if success:
+        return entries[-1].keycode
+
+    return None
+
 class StartRecordingAction(AtomicAction):
     '''Tells Orca to log speech and braille output to a string which we
     can later obtain and use in an assertion (see AssertPresentationAction)'''
diff --git a/test/keystrokes/gnome-terminal/command_not_found.py 
b/test/keystrokes/gnome-terminal/command_not_found.py
new file mode 100644
index 0000000..219ee4a
--- /dev/null
+++ b/test/keystrokes/gnome-terminal/command_not_found.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+
+from macaroon.playback import *
+import utils
+
+sequence = MacroSequence()
+sequence.append(PauseAction(3000))
+sequence.append(TypeAction("foo"))
+
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("Return"))
+sequence.append(utils.AssertPresentationAction(
+    "1. Return after typing 'foo'",
+    ["BRAILLE LINE:  ''",
+     "     VISIBLE:  '', cursor=1",
+     "BRAILLE LINE:  ''",
+     "     VISIBLE:  '', cursor=3",
+     "SPEECH OUTPUT: 'bash: foo: command not found...",
+     "'",
+     "SPEECH OUTPUT: '$ '"]))
+
+sequence.append(utils.AssertionSummaryAction())
+sequence.start()
diff --git a/test/keystrokes/gnome-terminal/multiple_tabs.py b/test/keystrokes/gnome-terminal/multiple_tabs.py
index 3db6f0e..9d60b3b 100644
--- a/test/keystrokes/gnome-terminal/multiple_tabs.py
+++ b/test/keystrokes/gnome-terminal/multiple_tabs.py
@@ -5,6 +5,7 @@ import utils
 
 sequence = MacroSequence()
 
+sequence.append(PauseAction(3000))
 sequence.append(TypeAction("ftp"))
 sequence.append(KeyComboAction("Return"))
 
@@ -44,6 +45,7 @@ sequence.append(utils.AssertPresentationAction(
      "SPEECH OUTPUT: '$ '"]))
 
 sequence.append(KeyComboAction("<Alt>1"))
+sequence.append(PauseAction(3000))
 
 sequence.append(utils.StartRecordingAction())
 sequence.append(KeyComboAction("Return"))
@@ -62,6 +64,7 @@ sequence.append(utils.AssertPresentationAction(
      "SPEECH OUTPUT: 'ftp> '"]))
 
 sequence.append(KeyComboAction("<Alt>2"))
+sequence.append(PauseAction(3000))
 
 sequence.append(utils.StartRecordingAction())
 sequence.append(KeyComboAction("Return"))
diff --git a/test/keystrokes/gnome-terminal/tab_completion.py 
b/test/keystrokes/gnome-terminal/tab_completion.py
new file mode 100644
index 0000000..2ffcb48
--- /dev/null
+++ b/test/keystrokes/gnome-terminal/tab_completion.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+
+from macaroon.playback import *
+import utils
+
+sequence = MacroSequence()
+sequence.append(PauseAction(3000))
+sequence.append(TypeAction("cd "))
+
+slash = utils.getKeyCodeForName("slash")
+sequence.append(KeyPressAction(0, slash, None))
+sequence.append(KeyReleaseAction(0, slash, None))
+
+sequence.append(TypeAction("ho"))
+
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("Tab"))
+sequence.append(utils.AssertPresentationAction(
+    "1. Tab to complete 'cd /ho'",
+    []))
+
+sequence.append(utils.AssertionSummaryAction())
+sequence.start()


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