|
1 | | -#appModules/nvda.py |
2 | | -#A part of NonVisual Desktop Access (NVDA) |
3 | | -#Copyright (C) 2008-2017 NV Access Limited |
4 | | -#This file is covered by the GNU General Public License. |
5 | | -#See the file COPYING for more details. |
| 1 | +# A part of NonVisual Desktop Access (NVDA) |
| 2 | +# Copyright (C) 2008-2021 NV Access Limited, James Teh, Michael Curran, Leonard de Ruijter, Reef Turner, |
| 3 | +# Julien Cochuyt |
| 4 | +# This file may be used under the terms of the GNU General Public License, version 2 or later. |
| 5 | +# For more details see: https://www.gnu.org/licenses/gpl-2.0.html |
| 6 | + |
| 7 | + |
| 8 | +import typing |
6 | 9 |
|
7 | 10 | import appModuleHandler |
8 | 11 | import api |
9 | 12 | import controlTypes |
10 | 13 | import versionInfo |
11 | 14 | from NVDAObjects.IAccessible import IAccessible |
| 15 | +from baseObject import ScriptableObject |
12 | 16 | import gui |
| 17 | +from scriptHandler import script |
13 | 18 | import speech |
| 19 | +import textInfos |
14 | 20 | import braille |
15 | 21 | import config |
16 | 22 | from logHandler import log |
17 | 23 |
|
| 24 | +if typing.TYPE_CHECKING: |
| 25 | + import inputCore |
| 26 | + |
| 27 | + |
18 | 28 | nvdaMenuIaIdentity = None |
19 | 29 |
|
20 | 30 | class NvdaDialog(IAccessible): |
@@ -44,6 +54,118 @@ def _get_description(self): |
44 | 54 | """ |
45 | 55 | return "" |
46 | 56 |
|
| 57 | + |
| 58 | +# Translators: The name of a category of NVDA commands. |
| 59 | +SCRCAT_PYTHON_CONSOLE = _("Python Console") |
| 60 | + |
| 61 | + |
| 62 | +class NvdaPythonConsoleUIOutputClear(ScriptableObject): |
| 63 | + |
| 64 | + # Allow the bound gestures to be edited through the Input Gestures dialog (see L{gui.prePopup}) |
| 65 | + isPrevFocusOnNvdaPopup = True |
| 66 | + |
| 67 | + @script( |
| 68 | + gesture="kb:control+l", |
| 69 | + # Translators: Description of a command to clear the Python Console output pane |
| 70 | + description=_("Clear the output pane"), |
| 71 | + category=SCRCAT_PYTHON_CONSOLE, |
| 72 | + ) |
| 73 | + def script_clearOutput(self, gesture: "inputCore.InputGesture"): |
| 74 | + from pythonConsole import consoleUI |
| 75 | + consoleUI.clear() |
| 76 | + |
| 77 | + |
| 78 | +class NvdaPythonConsoleUIOutputCtrl(ScriptableObject): |
| 79 | + |
| 80 | + # Allow the bound gestures to be edited through the Input Gestures dialog (see L{gui.prePopup}) |
| 81 | + isPrevFocusOnNvdaPopup = True |
| 82 | + |
| 83 | + @script( |
| 84 | + gesture="kb:alt+downArrow", |
| 85 | + # Translators: Description of a command to move to the next result in the Python Console output pane |
| 86 | + description=_("Move to the next result"), |
| 87 | + category=SCRCAT_PYTHON_CONSOLE |
| 88 | + ) |
| 89 | + def script_moveToNextResult(self, gesture: "inputCore.InputGesture"): |
| 90 | + self._resultNavHelper(direction="next", select=False) |
| 91 | + |
| 92 | + @script( |
| 93 | + gesture="kb:alt+upArrow", |
| 94 | + # Translators: Description of a command to move to the previous result |
| 95 | + # in the Python Console output pane |
| 96 | + description=_("Move to the previous result"), |
| 97 | + category=SCRCAT_PYTHON_CONSOLE |
| 98 | + ) |
| 99 | + def script_moveToPrevResult(self, gesture: "inputCore.InputGesture"): |
| 100 | + self._resultNavHelper(direction="previous", select=False) |
| 101 | + |
| 102 | + @script( |
| 103 | + gesture="kb:alt+downArrow+shift", |
| 104 | + # Translators: Description of a command to select from the current caret position to the end |
| 105 | + # of the current result in the Python Console output pane |
| 106 | + description=_("Select until the end of the current result"), |
| 107 | + category=SCRCAT_PYTHON_CONSOLE |
| 108 | + ) |
| 109 | + def script_selectToResultEnd(self, gesture: "inputCore.InputGesture"): |
| 110 | + self._resultNavHelper(direction="next", select=True) |
| 111 | + |
| 112 | + @script( |
| 113 | + gesture="kb:alt+shift+upArrow", |
| 114 | + # Translators: Description of a command to select from the current caret position to the start |
| 115 | + # of the current result in the Python Console output pane |
| 116 | + description=_("Select until the start of the current result"), |
| 117 | + category=SCRCAT_PYTHON_CONSOLE |
| 118 | + ) |
| 119 | + def script_selectToResultStart(self, gesture: "inputCore.InputGesture"): |
| 120 | + self._resultNavHelper(direction="previous", select=True) |
| 121 | + |
| 122 | + def _resultNavHelper(self, direction: str = "next", select: bool = False): |
| 123 | + from pythonConsole import consoleUI |
| 124 | + startPos, endPos = consoleUI.outputCtrl.GetSelection() |
| 125 | + if self.isTextSelectionAnchoredAtStart: |
| 126 | + curPos = endPos |
| 127 | + else: |
| 128 | + curPos = startPos |
| 129 | + if direction == "previous": |
| 130 | + for pos in reversed(consoleUI.outputPositions): |
| 131 | + if pos < curPos: |
| 132 | + break |
| 133 | + else: |
| 134 | + # Translators: Reported when attempting to move to the previous result in the Python Console |
| 135 | + # output pane while there is no previous result. |
| 136 | + speech.speakMessage(_("Top")) |
| 137 | + return |
| 138 | + elif direction == "next": |
| 139 | + for pos in consoleUI.outputPositions: |
| 140 | + if pos > curPos: |
| 141 | + break |
| 142 | + else: |
| 143 | + # Translators: Reported when attempting to move to the next result in the Python Console |
| 144 | + # output pane while there is no next result. |
| 145 | + speech.speakMessage(_("Bottom")) |
| 146 | + return |
| 147 | + else: |
| 148 | + raise ValueError(u"Unexpected direction: {!r}".format(direction)) |
| 149 | + if select: |
| 150 | + consoleUI.outputCtrl.Freeze() |
| 151 | + anchorPos = startPos if self.isTextSelectionAnchoredAtStart else endPos |
| 152 | + consoleUI.outputCtrl.SetSelection(anchorPos, pos) |
| 153 | + consoleUI.outputCtrl.Thaw() |
| 154 | + self.detectPossibleSelectionChange() |
| 155 | + self.isTextSelectionAnchoredAtStart = anchorPos < pos |
| 156 | + else: |
| 157 | + consoleUI.outputCtrl.SetSelection(pos, pos) |
| 158 | + info = self.makeTextInfo(textInfos.POSITION_CARET) |
| 159 | + copy = info.copy() |
| 160 | + info.expand(textInfos.UNIT_LINE) |
| 161 | + if ( |
| 162 | + copy.move(textInfos.UNIT_CHARACTER, 4, endPoint="end") == 4 |
| 163 | + and copy.text == ">>> " |
| 164 | + ): |
| 165 | + info.move(textInfos.UNIT_CHARACTER, 4, endPoint="start") |
| 166 | + speech.speakTextInfo(info, reason=controlTypes.OutputReason.CARET) |
| 167 | + |
| 168 | + |
47 | 169 | class AppModule(appModuleHandler.AppModule): |
48 | 170 | # The configuration profile that has been previously edited. |
49 | 171 | # This ought to be a class property. |
@@ -108,8 +230,26 @@ def isNvdaSettingsDialog(self, obj): |
108 | 230 | return True |
109 | 231 | return False |
110 | 232 |
|
| 233 | + def isNvdaPythonConsoleUIInputCtrl(self, obj): |
| 234 | + from pythonConsole import consoleUI |
| 235 | + if not consoleUI: |
| 236 | + return |
| 237 | + return obj.windowHandle == consoleUI.inputCtrl.GetHandle() |
| 238 | + |
| 239 | + def isNvdaPythonConsoleUIOutputCtrl(self, obj): |
| 240 | + from pythonConsole import consoleUI |
| 241 | + if not consoleUI: |
| 242 | + return |
| 243 | + return obj.windowHandle == consoleUI.outputCtrl.GetHandle() |
| 244 | + |
111 | 245 | def chooseNVDAObjectOverlayClasses(self, obj, clsList): |
112 | 246 | if obj.windowClassName == "#32770" and obj.role == controlTypes.ROLE_DIALOG: |
113 | 247 | clsList.insert(0, NvdaDialog) |
114 | 248 | if self.isNvdaSettingsDialog(obj): |
115 | 249 | clsList.insert(0, NvdaDialogEmptyDescription) |
| 250 | + return |
| 251 | + if self.isNvdaPythonConsoleUIInputCtrl(obj): |
| 252 | + clsList.insert(0, NvdaPythonConsoleUIOutputClear) |
| 253 | + elif self.isNvdaPythonConsoleUIOutputCtrl(obj): |
| 254 | + clsList.insert(0, NvdaPythonConsoleUIOutputClear) |
| 255 | + clsList.insert(0, NvdaPythonConsoleUIOutputCtrl) |
0 commit comments