[orca] Replace the old list shortcuts "mode" + hacks and replace it with proper lists
- From: Joanmarie Diggs <joanied src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [orca] Replace the old list shortcuts "mode" + hacks and replace it with proper lists
- Date: Tue, 19 Feb 2013 22:08:18 +0000 (UTC)
commit b7187a826f279c0936b2e6fe4971bea31b4f81a1
Author: Joanmarie Diggs <jdiggs igalia com>
Date: Tue Feb 19 17:05:39 2013 -0500
Replace the old list shortcuts "mode" + hacks and replace it with proper lists
src/orca/cmdnames.py | 9 ---
src/orca/messages.py | 43 ++++---------
src/orca/orca.py | 146 ++----------------------------------------
src/orca/orca_state.py | 10 ---
src/orca/scripts/default.py | 82 ++++++++++++++----------
5 files changed, 68 insertions(+), 222 deletions(-)
---
diff --git a/src/orca/cmdnames.py b/src/orca/cmdnames.py
index c15c89c..88fd73a 100644
--- a/src/orca/cmdnames.py
+++ b/src/orca/cmdnames.py
@@ -372,15 +372,6 @@ PROCESS_BRAILLE_CUT_LINE = _("Marks the end of a text selection.")
# have a handler.
ENTER_LEARN_MODE = _("Enters learn mode. Press escape to exit learn mode.")
-# Translators: Orca has a "List Shortcuts" mode that will allow the user to list
-# a group of keyboard shortcuts. The Orca default shortcuts can be listed by
-# pressing 1, and Orca shortcuts for the application under focus can be listed
-# by pressing 2. User can press Up/ Down to navigate and hear the list, change
-# to another list by pressing 1/2, and exit the "List Shortcuts" Mode by
-# pressing Escape.
-ENTER_LIST_SHORTCUTS_MODE = \
- _("Enters list shortcuts mode. Press escape to exit list shortcuts mode.")
-
# Translators: the speech rate is how fast the speech synthesis engine will
# generate speech.
DECREASE_SPEECH_RATE = _("Decreases the speech rate.")
diff --git a/src/orca/messages.py b/src/orca/messages.py
index 222dc39..e642b6d 100644
--- a/src/orca/messages.py
+++ b/src/orca/messages.py
@@ -33,6 +33,12 @@ __license__ = "LGPL"
from .orca_i18n import _, C_, ngettext
from .orca_platform import version
+# Translators: Sometimes when we attempt to get the name of an accessible
+# software application, we fail because the app or one of its elements is
+# defunct. This is a generic name so that we can still refer to this element
+# in messages.
+APPLICATION_NO_NAME = C_("generic name", "application")
+
# Translators: This is presented when the user has navigated to an empty line.
BLANK = _("blank")
@@ -399,8 +405,9 @@ LEARN_MODE_START_BRAILLE = _("Learn mode. Press escape to exit.")
# Mode.
LEARN_MODE_START_SPEECH = \
_("Entering learn mode. Press any key to hear its function. " \
- "To get a list of Orca shortcuts, press the Orca modifier " \
- "plus H twice quickly. To view the documentation, press F1. " \
+ "To get a list of Orca's default shortcuts, press 1. " \
+ "To get a list of Orca's shortcuts for the current application, " \
+ "press 2. To view Orca's documentation, press F1. " \
"To exit learn mode, press the escape key.")
# Translators: Orca has a "Learn Mode" that will allow the user to type any key
@@ -427,37 +434,11 @@ LINE_SELECTED_RIGHT = _("line selected to end from previous cursor position")
LINK = _("link")
# Translators: The following string instructs the user how to navigate amongst
-# the list of commands presented in 'list shortcuts' mode as well as how to exit
-# the list when finished.
-LIST_SHORTCUTS_MODE_NAVIGATION = \
+# the list of commands presented in learn mode, as well as how to exit the list
+# when finished.
+LIST_SHORTCUTS_NAVIGATION = \
_("Use Up and Down Arrow to navigate the list. Press Escape to exit.")
-# Translators: This message is presented when the user is in 'list shortcuts'
-# mode. This is the message we present when the user requested a list of
-# application-specific shortcuts, but none could be found for that application.
-LIST_SHORTCUTS_MODE_NO_RESULTS = _("No Orca shortcuts for %s found.")
-
-# Translators: Orca has a 'List Shortcuts' mode by which a user can navigate
-# through a list of the bound commands in Orca. This is the message that is
-# presented to the user as confirmation that this mode has been entered.
-LIST_SHORTCUTS_MODE_START = _("List shortcuts mode.")
-
-# Translators: Orca has a 'List Shortcuts' mode by which a user can navigate
-# through a list of the bound commands in Orca. This is the message that is
-# presented to the user as confirmation that this mode has been exited.
-LIST_SHORTCUTS_MODE_STOP = _("Exiting list shortcuts mode.")
-
-# Translators: Orca has a 'List Shortcuts' mode by which a user can navigate
-# through a list of the bound commands in Orca. Pressing 1 presents the
-# commands/shortcuts available for all applications. These are the "default"
-# commands/shortcuts. Pressing 2 presents commands/shortcuts Orca provides for
-# the application with focus. The following message is presented to the user
-# upon entering this mode.
-LIST_SHORTCUTS_MODE_TUTORIAL = \
- _("Press 1 for Orca's default shortcuts. Press 2 for " \
- "Orca's shortcuts for the current application. " \
- "Press escape to exit.")
-
# Translators: A live region is an area of a web page that is periodically
# updated, e.g. stock ticker. http://www.w3.org/TR/wai-aria/terms#def_liveregion
# Orca has several features to facilitate accessing live regions. This message
diff --git a/src/orca/orca.py b/src/orca/orca.py
index cbd1da6..834f40f 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -241,14 +241,15 @@ def _processKeyboardEvent(event):
# Special modes.
if not isPressedEvent and keyboardEvent.event_string == "Escape":
script.exitLearnMode(keyboardEvent)
- if orca_state.learnModeEnabled and keyboardEvent.event_string == "F1" \
- and not keyboardEvent.modifiers:
- orca_state.learnModeEnabled = False
- return helpForOrca()
+ if orca_state.learnModeEnabled and not keyboardEvent.modifiers:
+ if keyboardEvent.event_string == "F1":
+ orca_state.learnModeEnabled = False
+ return helpForOrca()
+ if keyboardEvent.event_string in ["1", "2"]:
+ orca_state.learnModeEnabled = False
+ return script.listOrcaShortcuts(keyboardEvent)
if orca_state.capturingKeys:
return False
- if orca_state.listShortcutsModeEnabled:
- return listShortcuts(keyboardEvent)
if notification_messages.listNotificationMessagesModeEnabled:
return notification_messages.listNotificationMessages(keyboardEvent)
@@ -519,139 +520,6 @@ def helpForOrca(script=None, inputEvent=None, page=""):
Gtk.get_current_event_time())
return True
-def listShortcuts(event):
- """When list shortcuts mode is enabled, this function provides a means
- by which users can navigate through Orca bound Orca commands. Pressing
- 1 results in a list of the default shortcuts; pressing 2 results in a
- list of shortcuts for the focused application, should one exist. List
- navigation is accomplished through the Up and Down Arrow keys. Escape
- exits the list. In this mode, other keys are disabled.
-
- Arguments:
- - event: an AT-SPI DeviceEvent
-
- Returns True if the event is consumed (and False if not).
- """
-
- numShortcuts = len(orca_state.listOfShortcuts)
- consumed = False
- message = ""
-
- navigation = messages.LIST_SHORTCUTS_MODE_NAVIGATION
- if event.type == pyatspi.KEY_PRESSED_EVENT:
- if (event.event_string == "1"):
- if not numShortcuts or orca_state.typeOfShortcuts != "default":
- orca_state.listOfShortcuts = getListOfShortcuts("default")
- orca_state.typeOfShortcuts = "default"
- numShortcuts = len(orca_state.listOfShortcuts)
- orca_state.ptrToShortcut = 0
- # Translators: This message is presented when the user is in
- # 'list of shortcuts mode'. In this messsage, we present the
- # number of shortcuts found.
- #
- message = ngettext("%d Orca default shortcut found.",
- "%d Orca default shortcuts found.",
- numShortcuts) % numShortcuts
- message = message + " " + navigation
- orca_state.activeScript.presentMessage(message)
- message = orca_state.listOfShortcuts[orca_state.ptrToShortcut][0]+ \
- " " + orca_state.listOfShortcuts[orca_state.ptrToShortcut][1]
- orca_state.activeScript.speakMessage(message)
- orca_state.activeScript.displayBrailleMessage(message, -1, -1)
- consumed = True
- elif (event.event_string == "2"):
- if not numShortcuts or orca_state.typeOfShortcuts != "application":
- orca_state.listOfShortcuts = getListOfShortcuts("application")
- orca_state.typeOfShortcuts = "application"
- numShortcuts = len(orca_state.listOfShortcuts)
- if numShortcuts > 0:
- orca_state.ptrToShortcut = 0
- # Translators: This message is presented when the user is in
- # 'list of shortcuts mode'. In this message, we present the
- # number of shortcuts found for the named application.
- #
- message = ngettext( \
- "%(count)d Orca shortcut for %(application)s found.",
- "%(count)d Orca shortcuts for %(application)s found.",
- numShortcuts) % \
- {"count" : numShortcuts,
- "application" : orca_state.activeScript.app.name}
- message = message + " " + navigation
- orca_state.activeScript.presentMessage(message)
- message = \
- orca_state.listOfShortcuts[orca_state.ptrToShortcut][0] + \
- " " + orca_state.listOfShortcuts[orca_state.ptrToShortcut][1]
- orca_state.activeScript.speakMessage(message)
- orca_state.activeScript.displayBrailleMessage(message, -1, -1)
- else:
- message = messages.LIST_SHORTCUTS_MODE_NO_RESULTS % \
- orca_state.activeScript.app.name
- orca_state.activeScript.speakMessage(message)
- orca_state.activeScript.displayBrailleMessage(message, -1, -1)
- consumed = True
- elif (event.event_string == "Up"):
- if (numShortcuts > 0):
- if orca_state.ptrToShortcut > 0:
- orca_state.ptrToShortcut = orca_state.ptrToShortcut-1
- else:
- orca_state.ptrToShortcut = numShortcuts-1
- orca_state.activeScript.presentMessage(
- messages.WRAPPING_TO_BOTTOM)
- message = \
- orca_state.listOfShortcuts[orca_state.ptrToShortcut][0] + \
- " " + orca_state.listOfShortcuts[orca_state.ptrToShortcut][1]
- orca_state.activeScript.speakMessage(message)
- orca_state.activeScript.displayBrailleMessage(message, -1, -1)
- consumed = True
- elif (event.event_string == "Down"):
- if (numShortcuts > 0):
- if orca_state.ptrToShortcut < numShortcuts-1:
- orca_state.ptrToShortcut = orca_state.ptrToShortcut+1
- else:
- orca_state.ptrToShortcut = 0
- orca_state.activeScript.presentMessage(messages.WRAPPING_TO_TOP)
- message = \
- orca_state.listOfShortcuts[orca_state.ptrToShortcut][0] + \
- " " + orca_state.listOfShortcuts[orca_state.ptrToShortcut][1]
- orca_state.activeScript.speakMessage(message)
- orca_state.activeScript.displayBrailleMessage(message, -1, -1)
- consumed = True
- elif (event.event_string == "Escape"):
- orca_state.activeScript.exitListShortcutsMode(event)
- consumed = True
- else:
- message = messages.LIST_SHORTCUTS_MODE_TUTORIAL
- orca_state.activeScript.speakMessage(message)
- orca_state.activeScript.displayBrailleMessage(message, -1, -1)
- consumed = True
- elif (event.type == pyatspi.KEY_RELEASED_EVENT) and (event.event_string \
- == "Escape"):
- consumed = True
- return consumed
-
-
-def getListOfShortcuts(typeOfShortcuts):
- """Returns a list of (description, shortcut) tuples, sorted by shortcut.
-
- Arguments:
- - typeOfShortcuts: a string specifying the desired type of shortcuts.
- Valid values are 'default' for Orca-wide shortcuts and 'application'
- for Orca shortcuts unique to the currently-focused application.
- """
-
- script = orca_state.activeScript
- if typeOfShortcuts == "default":
- bindings = script.getDefaultKeyBindings()
- bound = bindings.getBoundBindings()
- elif typeOfShortcuts == "application":
- app = script.getAppKeyBindings()
- toolkit = script.getToolkitKeyBindings()
- bound = app.getBoundBindings()
- bound.extend(toolkit.getBoundBindings())
-
- shortcuts = [(kb.handler.description, kb.asString(True)) for kb in bound]
- return sorted(shortcuts, key=lambda shortcut: shortcut[1])
-
def quitOrca(script=None, inputEvent=None):
"""Quit Orca. Check if the user wants to confirm this action.
If so, show the confirmation GUI otherwise just shutdown.
diff --git a/src/orca/orca_state.py b/src/orca/orca_state.py
index 13e910a..d4b8a06 100644
--- a/src/orca/orca_state.py
+++ b/src/orca/orca_state.py
@@ -102,16 +102,6 @@ searchQuery = None
#
learnModeEnabled = False
-# Assists with list shortcuts mode (what you enter when you press
-# Insert + H (double click) and exit when you press escape.
-#
-listShortcutsModeEnabled = False
-
-# Assists in list shortcuts mode
-listOfShortcuts = []
-typeOfShortcuts = ''
-ptrToShortcut = -1
-
# Whether we should use the pronunciation dictionary to help speak
# certain words. This will be True everywhere except when focus is
# in the Pronunciation Dictionary in the Orca Preferences dialog.
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index f43b280..14db35b 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -47,6 +47,7 @@ import orca.keybindings as keybindings
import orca.messages as messages
import orca.outline as outline
import orca.orca as orca
+import orca.orca_gui_commandlist as commandlist
import orca.orca_i18n as orca_i18n
import orca.orca_state as orca_state
import orca.phonnames as phonnames
@@ -372,9 +373,9 @@ class Script(script.Script):
Script.enterLearnMode,
cmdnames.ENTER_LEARN_MODE)
- self.inputEventHandlers["enterListShortcutsModeHandler"] = \
+ self.inputEventHandlers["listShortcutsHandler"] = \
input_event.InputEventHandler(
- Script.enterListShortcutsMode,
+ Script.listOrcaShortcuts,
cmdnames.ENTER_LEARN_MODE,
False) # Do not enable learn mode for this action
@@ -1034,37 +1035,57 @@ class Script(script.Script):
self.presentMessage(messages.LEARN_MODE_STOP)
orca_state.learnModeEnabled = False
- def enterListShortcutsMode(self, inputEvent):
- """Turns list shortcuts mode on. The user must press the escape key to
- exit list shortcuts mode. Key bindings for learn mode & list shortcuts
- mode are Orca+H & Orca+H(double click) respectively. So, while enabling
- list shortcuts mode, learn mode is enabled as a side effect. We start by
- disabling it.
-
- Returns True to indicate the input event has been consumed.
- """
- orca_state.learnModeEnabled = False
- if orca_state.listShortcutsModeEnabled:
+ def listOrcaShortcuts(self, inputEvent=None):
+ """Shows a simple gui listing Orca's bound commands."""
+
+ if not inputEvent or inputEvent.event_string == "1":
+ bound = self.getDefaultKeyBindings().getBoundBindings()
+ # Translators: This message is presented when the user is in a list
+ # of shortcuts associated with Orca commands which are not specific
+ # to the current application. It appears as the title of the dialog
+ # which contains the list.
+ title = ngettext("%d Orca default shortcut found.",
+ "%d Orca default shortcuts found.",
+ len(bound)) % len(bound)
+ else:
+ try:
+ appName = self.app.name
+ except AttributeError:
+ appName = messages.APPLICATION_NO_NAME
+
+ bound = self.getAppKeyBindings().getBoundBindings()
+ bound.extend(self.getToolkitKeyBindings().getBoundBindings())
+ # Translators: This message is presented when the user is in a list
+ # of shortcuts associated with Orca commands specific to the current
+ # application. It appears at the title of the dialog which contains
+ # the list.
+ title = ngettext("%(count)d Orca shortcut for %(application)s found.",
+ "%(count)d Orca shortcuts for %(application)s found.",
+ len(bound)) % \
+ {"count" : len(bound), "application" : appName}
+
+ if not bound:
+ self.presentMessage(title)
+ self.presentMessage(messages.LEARN_MODE_START_SPEECH)
return True
- message = "%s %s" % (messages.LIST_SHORTCUTS_MODE_START,
- messages.LIST_SHORTCUTS_MODE_TUTORIAL)
- self.speakMessage(message)
- self.displayBrailleMessage(message, -1, -1)
- orca_state.listShortcutsModeEnabled = True
- return True
+ self.exitLearnMode()
- def exitListShortcutsMode(self, inputEvent=None):
- """Turns list shortcuts mode off.
+ rows = [(kb.handler.function,
+ kb.handler.description,
+ kb.asString(True)) for kb in bound]
+ sorted(rows, key=lambda cmd: cmd[2])
- Returns True to indicate the input event has been consumed.
- """
+ # Translators: Function is a table column header where the cells in the
+ # column are a sentence that briefly describes what action Orca will
+ # take if and when the user invokes that keyboard command.
+ header1 = _("Function")
- orca_state.listOfShortcuts = []
- orca_state.typeOfShortcuts = ""
- orca_state.ptrToShortcut = -1
- orca_state.listShortcutsModeEnabled = False
- self.presentMessage(messages.LIST_SHORTCUTS_MODE_STOP)
+ # Translators: Key Binding is a table column header where the cells in the
+ # column represent keyboard combinations the user can press to invoke Orca
+ # commands.
+ header2 = _("Key Binding")
+ commandlist.showUI(title, ("", header1, header2), rows, False)
return True
def findNext(self, inputEvent):
@@ -3078,11 +3099,6 @@ class Script(script.Script):
# disable learn mode
orca_state.learnModeEnabled = False
- # disable list shortcuts mode
- orca_state.listShortcutsModeEnabled = False
- orca_state.listOfShortcuts = []
- orca_state.typeOfShortcuts = ""
-
########################################################################
# #
# Methods for presenting content #
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]