[orca] Improve logic to filter redundant names
- From: Joanmarie Diggs <joanied src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [orca] Improve logic to filter redundant names
- Date: Tue, 12 Apr 2022 10:48:42 +0000 (UTC)
commit 6915e1ea55fe59d3e55eb302b95e2048eca1340f
Author: Joanmarie Diggs <jdiggs igalia com>
Date: Tue Apr 12 12:32:21 2022 +0200
Improve logic to filter redundant names
The logic to filter out names which were redundant to labels handled
the following conditions:
* The name and label only differed with respect to whitespace
* The label started with the text of the name (e.g. because the
author/developer wanted to append some helpful information)
It did not, however, handle the following:
* The name and label only differed with respect to punctuation
* The name itself had duplicate text (e.g. repeats the label twice)
This failure makes Orca quite chatty with Gtk 4 widgets where the
use_underline attribute is present because Gtk 4 exposes a name
consisting of the displayed text with the underline included
followed by that same text without the underline included.
This commit handles those two missing scenarios.
Fixes #237.
src/orca/generator.py | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/src/orca/generator.py b/src/orca/generator.py
index ebcdaaa22..54aa2710e 100644
--- a/src/orca/generator.py
+++ b/src/orca/generator.py
@@ -28,6 +28,7 @@ __copyright__ = "Copyright (c) 2009 Sun Microsystems Inc." \
__license__ = "LGPL"
import pyatspi
+import re
import sys
import time
import traceback
@@ -396,12 +397,26 @@ class Generator:
descendant = self._script.utilities.realActiveDescendant(obj)
name = self._generateName(descendant)
+ # If we don't have a label, always use the name.
+ if not label:
+ return name
+
result.extend(label)
- if not len(label):
- result.extend(name)
- elif len(name) and name[0].split() != label[0].split() \
- and not label[0].startswith(name[0]):
- result.extend(name)
+ if not name:
+ return result
+
+ # Try to eliminate names which are redundant to the label.
+ # Convert all non-alphanumeric characters to space and get the words.
+ nameWords = re.sub(r"[\W_]", " ", name[0]).split()
+ labelWords = re.sub(r"[\W_]", " ", label[0]).split()
+
+ # If all of the words in the name are in the label, the name is redundant.
+ if set(nameWords).issubset(set(labelWords)):
+ msg = "GENERATOR: name '%s' is redundant to label '%s'" % (name[0], label[0])
+ debug.println(debug.LEVEL_INFO, msg, True)
+ return result
+
+ result.extend(name)
return result
def _generateLabelOrName(self, obj, **args):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]