[orca] Remove some duplicated code
- From: Joanmarie Diggs <joanied src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [orca] Remove some duplicated code
- Date: Tue, 20 Jan 2015 18:01:07 +0000 (UTC)
commit 0f5c41d2bda7bf74016648750e6b8d29cf7a867b
Author: Joanmarie Diggs <jdiggs igalia com>
Date: Tue Jan 20 13:00:43 2015 -0500
Remove some duplicated code
po/POTFILES.in | 2 -
src/orca/flat_review.py | 22 +------------
src/orca/generator.py | 69 ++++++++--------------------------------
src/orca/object_properties.py | 4 ++
src/orca/script_utilities.py | 14 ++++++++
src/orca/tutorialgenerator.py | 38 +++-------------------
6 files changed, 40 insertions(+), 109 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 51d87d2..0aa15f5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,8 +8,6 @@ src/orca/brltablenames.py
src/orca/chnames.py
src/orca/cmdnames.py
src/orca/colornames.py
-src/orca/flat_review.py
-src/orca/generator.py
src/orca/guilabels.py
src/orca/keynames.py
src/orca/keybindings.py
diff --git a/src/orca/flat_review.py b/src/orca/flat_review.py
index a8e3cd3..54ad7b8 100644
--- a/src/orca/flat_review.py
+++ b/src/orca/flat_review.py
@@ -37,7 +37,6 @@ from . import orca_state
from . import settings
from .braille_generator import BrailleGenerator
-from .orca_i18n import _
# [[[WDW - HACK Regular expression to split strings on whitespace
# boundaries, which is what we'll use for word dividers instead of
@@ -1029,25 +1028,8 @@ class Context:
elif role == pyatspi.ROLE_TABLE_CELL:
# Handle table cells that act like check boxes.
- #
- try:
- action = accessible.queryAction()
- except NotImplementedError:
- action = None
-
- if action:
- hasToggle = False
- for i in range(0, action.nActions):
- # Translators: this is the action name for
- # the 'toggle' action. It must be the same
- # string used in the *.po file for gail.
- #
- if action.getName(i) in ["toggle", _("toggle")]:
- hasToggle = True
- break
- if hasToggle:
- self._insertStateZone(zones, accessible,
- pyatspi.ROLE_CHECK_BOX)
+ if self.script.utilities.hasMeaningfulToggleAction(accessible):
+ self._insertStateZone(zones, accessible, pyatspi.ROLE_CHECK_BOX)
if zone:
if stateOnLeft:
diff --git a/src/orca/generator.py b/src/orca/generator.py
index b2a1018..ffa5fb8 100644
--- a/src/orca/generator.py
+++ b/src/orca/generator.py
@@ -37,7 +37,6 @@ from . import messages
from . import object_properties
from . import settings
-from .orca_i18n import _ # for gettext support
import collections
def _formatExceptionInfo(maxTBlevel=5):
@@ -482,21 +481,11 @@ class Generator:
returned if this is not a checkable cell.
"""
result = []
- try:
- action = obj.queryAction()
- except NotImplementedError:
- action = None
- if action:
- for i in range(0, action.nActions):
- # Translators: this is the action name for
- # the 'toggle' action. It must be the same
- # string used in the *.po file for gail.
- #
- if action.getName(i) in ["toggle", _("toggle")]:
- oldRole = self._overrideRole(pyatspi.ROLE_CHECK_BOX,
- args)
- result.extend(self.generate(obj, **args))
- self._restoreRole(oldRole, args)
+ if self._script.utilities.hasMeaningfulToggleAction(obj):
+ oldRole = self._overrideRole(pyatspi.ROLE_CHECK_BOX, args)
+ result.extend(self.generate(obj, **args))
+ self._restoreRole(oldRole, args)
+
return result
def _generateCheckedState(self, obj, **args):
@@ -584,8 +573,6 @@ class Generator:
args['stringType'] = 'checkbox'
indicators = self._script.formatting.getString(**args)
if obj.getState().contains(pyatspi.STATE_CHECKED):
- # Translators: this represents the state of a checked menu item.
- #
result.append(indicators[1])
return result
@@ -748,19 +735,9 @@ class Generator:
cellOrder = []
hasToggle = [False, False]
for i, child in enumerate(obj):
- try:
- action = child.queryAction()
- except NotImplementedError:
- continue
- else:
- for j in range(0, action.nActions):
- # Translators: this is the action name for
- # the 'toggle' action. It must be the same
- # string used in the *.po file for gail.
- #
- if action.getName(j) in ["toggle", _("toggle")]:
- hasToggle[i] = True
- break
+ if self._script.utilities.hasMeaningfulToggleAction(child):
+ hasToggle[i] = True
+ break
if hasToggle[0] and not hasToggle[1]:
cellOrder = [ 1, 0 ]
elif not hasToggle[0] and hasToggle[1]:
@@ -790,20 +767,9 @@ class Generator:
cellOrder = []
hasToggle = [False, False]
for i, child in enumerate(obj):
- try:
- action = child.queryAction()
- except NotImplementedError:
- continue
- else:
- for j in range(0, action.nActions):
- # Translators: this is the action name for
- # the 'toggle' action. It must be the same
- # string used in the *.po file for gail.
- #
- if action.getName(j) in ["toggle", _("toggle")]:
- hasToggle[i] = True
- break
-
+ if self._script.utilities.hasMeaningfulToggleAction(child):
+ hasToggle[i] = True
+ break
if hasToggle[0] and not hasToggle[1]:
cellOrder = [ 1, 0 ]
elif not hasToggle[0] and hasToggle[1]:
@@ -840,16 +806,9 @@ class Generator:
if action and (label == None or len(label) == 0):
index = self._script.utilities.cellIndex(obj)
column = parentTable.getColumnAtIndex(index)
- for j in range(0, action.nActions):
- # Translators: this is the action name for
- # the 'toggle' action. It must be the same
- # string used in the *.po file for gail.
- #
- if action.getName(j) in ["toggle",
- _("toggle")]:
- accHeader = \
- parentTable.getColumnHeader(column)
- result.append(accHeader.name)
+ if self._script.utilities.hasMeaningfulToggleAction(obj):
+ accHeader = parentTable.getColumnHeader(column)
+ result.append(accHeader.name)
return result
def _generateRealTableCell(self, obj, **args):
diff --git a/src/orca/object_properties.py b/src/orca/object_properties.py
index 08d936d..ad120b4 100644
--- a/src/orca/object_properties.py
+++ b/src/orca/object_properties.py
@@ -31,6 +31,10 @@ __license__ = "LGPL"
from .orca_i18n import _, C_
+# Translators: this is the action name for the 'toggle' action. It must be the
+# same string used in the *.po file for gail.
+ACTION_TOGGLE = _("toggle")
+
# Translators: this is a indication of the focused icon and the count of the
# total number of icons within an icon panel. An example of an icon panel is
# the Nautilus folder view.
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index e2e63f9..54f32ce 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -42,6 +42,7 @@ from . import mathsymbols
from . import messages
from . import mouse_review
from . import orca_state
+from . import object_properties
from . import pronunciation_dict
from . import settings
@@ -2784,3 +2785,16 @@ class Utilities:
break
return level
+
+ def hasMeaningfulToggleAction(self, obj):
+ try:
+ action = obj.queryAction()
+ except NotImplementedError:
+ return False
+
+ toggleActionNames = ["toggle", object_properties.ACTION_TOGGLE]
+ for i in range(action.nActions):
+ if action.getName(i) in toggleActionNames:
+ return True
+
+ return False
diff --git a/src/orca/tutorialgenerator.py b/src/orca/tutorialgenerator.py
index e16b100..4cf3d62 100644
--- a/src/orca/tutorialgenerator.py
+++ b/src/orca/tutorialgenerator.py
@@ -552,20 +552,9 @@ class TutorialGenerator:
cellOrder = []
hasToggle = [ False, False ]
for i, child in enumerate(obj):
- try:
- action = child.queryAction()
- except NotImplementedError:
- continue
- else:
- for j in range(0, action.nActions):
- # Translators: this is the action name for
- # the 'toggle' action. It must be the same
- # string used in the *.po file for gail.
- #
- if action.getName(j) in ["toggle", _("toggle")]:
- hasToggle[i] = True
- break
-
+ if self._script.utilities.hasMeaningfulToggleAction(child):
+ hasToggle[i] = True
+ break
if hasToggle[0] and not hasToggle[1]:
cellOrder = [ 1, 0 ]
elif not hasToggle[0] and hasToggle[1]:
@@ -588,24 +577,9 @@ class TutorialGenerator:
# state, check the NODE_CHILD_OF relation, etc. Logged as
# bugzilla bug 319750.]]]
#
- try:
- action = obj.queryAction()
- except NotImplementedError:
- action = None
- if action:
- for i in range(0, action.nActions):
- debug.println(debug.LEVEL_FINEST,
- "tutorialgenerator._getTutorialForTableCell" \
- + "looking at action %d" % i)
-
- # Translators: this is the action name for
- # the 'toggle' action. It must be the same
- # string used in the *.po file for gail.
- #
- if action.getName(i) in ["toggle", _("toggle")]:
- utterances = self._getTutorialForCheckBox(obj,
- alreadyFocused, forceTutorial)
- break
+ if self._script.utilities.hasMeaningfulToggleAction(obj):
+ utterances = self._getTutorialForCheckBox(
+ obj, alreadyFocused, forceTutorial)
state = obj.getState()
if state.contains(pyatspi.STATE_EXPANDABLE):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]