[orca] Create a dedicated object:state-changed callback for "selected" events
- From: Joanmarie Diggs <joanied src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [orca] Create a dedicated object:state-changed callback for "selected" events
- Date: Wed, 6 Nov 2013 14:41:00 +0000 (UTC)
commit 0dba38544e9d0a943e17f8ded67d5dceedac23eb
Author: Joanmarie Diggs <jdiggs igalia com>
Date: Wed Nov 6 09:39:59 2013 -0500
Create a dedicated object:state-changed callback for "selected" events
src/orca/scripts/default.py | 87 ++++++++++++++---------------
src/orca/scripts/toolkits/CALLY/script.py | 30 +++++++---
2 files changed, 63 insertions(+), 54 deletions(-)
---
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index 7f097f2..c0f3ef8 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -544,7 +544,7 @@ class Script(script.Script):
listeners["object:state-changed:expanded"] = \
self.onExpandedChanged
listeners["object:state-changed:selected"] = \
- self.onStateChanged
+ self.onSelectedChanged
listeners["object:text-attributes-changed"] = \
self.onTextAttributesChanged
listeners["object:text-selection-changed"] = \
@@ -2516,6 +2516,48 @@ class Script(script.Script):
self.updateBraille(obj)
speech.speak(self.speechGenerator.generateSpeech(obj, alreadyFocused=True))
+ def onSelectedChanged(self, event):
+ """Callback for object:state-changed:selected accessibility events."""
+
+ obj = event.source
+ state = obj.getState()
+ if not state.contains(pyatspi.STATE_FOCUSED):
+ return
+
+ if not self.utilities.isSameObject(orca_state.locusOfFocus, obj):
+ return
+
+ if _settingsManager.getSetting('onlySpeakDisplayedText'):
+ return
+
+ isSelected = state.contains(pyatspi.STATE_SELECTED)
+ announceState = False
+ keyString, mods = self.utilities.lastKeyAndModifiers()
+ if keyString == "space":
+ if mods & settings.CTRL_MODIFIER_MASK:
+ announceState = True
+ else:
+ # If we are already selected and the user presses "space" again,
+ # we don't want to speak an intermediate "unselected" state.
+ announceState = isSelected and event.detail1
+ elif keyString in ["Down", "Up"] \
+ and isSelected and obj.getRole() == pyatspi.ROLE_TABLE_CELL:
+ announceState = True
+
+ if not announceState:
+ return
+
+ # TODO - JD: Unlike the other state-changed callbacks, it seems unwise
+ # to call generateSpeech() here because that also will present the
+ # expandable state if appropriate for the object type. The generators
+ # need to gain some smarts w.r.t. state changes.
+
+ voice = self.voices.get(settings.SYSTEM_VOICE)
+ if event.detail1:
+ speech.speak(messages.TEXT_SELECTED, voice, False)
+ else:
+ speech.speak(messages.TEXT_UNSELECTED, voice, False)
+
def onSelectionChanged(self, event):
"""Callback for object:selection-changed accessibility events."""
@@ -2550,49 +2592,6 @@ class Script(script.Script):
- event: the Event
"""
- if event.type.startswith("object:state-changed:selected") \
- and not _settingsManager.getSetting('onlySpeakDisplayedText') \
- and orca_state.locusOfFocus:
- # If this selection state change is for the object which
- # currently has the locus of focus, and the last keyboard
- # event was Space, or we are a focused table cell and we
- # arrowed Down or Up and are now selected, then let the
- # user know the selection state.
- # See bugs #486908 and #519564 for more details.
- #
- announceState = False
- keyString, mods = self.utilities.lastKeyAndModifiers()
- state = orca_state.locusOfFocus.getState()
- if state.contains(pyatspi.STATE_FOCUSED) \
- and self.utilities.isSameObject(
- event.source, orca_state.locusOfFocus):
-
- if keyString == "space":
- if mods & settings.CTRL_MODIFIER_MASK:
- announceState = True
- else:
- # Weed out a bogus situation. If we are already
- # selected and the user presses "space" again,
- # we don't want to speak the intermediate
- # "unselected" state.
- #
- eventState = event.source.getState()
- selected = eventState.contains(pyatspi.STATE_SELECTED)
- announceState = (selected and event.detail1)
-
- elif keyString in ["Down", "Up"] \
- and event.source.getRole() == pyatspi.ROLE_TABLE_CELL \
- and state.contains(pyatspi.STATE_SELECTED):
- announceState = True
-
- if announceState:
- voice = self.voices.get(settings.SYSTEM_VOICE)
- if event.detail1:
- speech.speak(messages.TEXT_SELECTED, voice, False)
- else:
- speech.speak(messages.TEXT_UNSELECTED, voice, False)
- return
-
if event.type.startswith("object:state-changed:focused"):
iconified = False
try:
diff --git a/src/orca/scripts/toolkits/CALLY/script.py b/src/orca/scripts/toolkits/CALLY/script.py
index 409b8ee..645a32e 100644
--- a/src/orca/scripts/toolkits/CALLY/script.py
+++ b/src/orca/scripts/toolkits/CALLY/script.py
@@ -291,6 +291,26 @@ class Script(default.Script):
default.Script.onShowingChanged(self, event)
+ def onSelectedChanged(self, event):
+ """Callback for object:state-changed:selected accessibility events."""
+ try:
+ state = event.source.getState()
+ except:
+ return
+
+ # Some buttons, like the Wikipedia button, claim to be selected but
+ # lack STATE_SELECTED. The other buttons, such as in the Dash and
+ # event switcher, seem to have the right state. Since the ones with
+ # the wrong state seem to be things we don't want to present anyway
+ # we'll stop doing so and hope we are right.
+
+ if event.detail1:
+ if state.contains(pyatspi.STATE_SELECTED):
+ orca.setLocusOfFocus(event, event.source)
+ return
+
+ default.Script.onSelectedChanged(self, event)
+
def onStateChanged(self, event):
"""Called whenever an object's state changes.
@@ -355,16 +375,6 @@ class Script(default.Script):
for label in labels:
self._activeDialogLabels[hash(label)] = label.name
- elif eType.startswith("object:state-changed:selected") and event.detail1:
- # Some buttons, like the Wikipedia button, claim to be selected but
- # lack STATE_SELECTED. The other buttons, such as in the Dash and
- # event switcher, seem to have the right state. Since the ones with
- # the wrong state seem to be things we don't want to present anyway
- # we'll stop doing so and hope we are right.
- if state.contains(pyatspi.STATE_SELECTED):
- orca.setLocusOfFocus(event, event.source)
- return
-
default.Script.onStateChanged(self, event)
def getTextLineAtCaret(self, obj, offset=None):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]