|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import addonHandler |
| 4 | +import api |
1 | 5 | import characterProcessing |
| 6 | +import globalCommands |
2 | 7 | import globalPluginHandler |
3 | 8 | import languageHandler |
| 9 | +import nvwave |
| 10 | +import scriptHandler |
4 | 11 | import speech |
| 12 | +import textInfos |
| 13 | + |
| 14 | +SOUNDS_DIR = Path(__file__).parent / "media" |
| 15 | +DIFF_SOUNDS = { |
| 16 | + "-": "diffLineDeleted.wav", |
| 17 | + "+": "diffLineInserted.wav", |
| 18 | +} |
| 19 | +DIFF_SOUNDS = {k: str(SOUNDS_DIR / v) for k, v in DIFF_SOUNDS.items()} |
5 | 20 |
|
6 | 21 | SPACE = characterProcessing.processSpeechSymbol(languageHandler.getLanguage(), " ") |
7 | 22 | end_utterance_command = speech.commands.EndUtteranceCommand() |
8 | 23 |
|
| 24 | +# We need this to get translations fromNVDA standard catalog. |
| 25 | +gettext = _ |
| 26 | +addonHandler.initTranslation() |
| 27 | + |
9 | 28 |
|
10 | 29 | def get_spelling_speech_decorator(func): |
11 | 30 | def wrapper(*args, **kwargs): |
@@ -63,3 +82,56 @@ def terminate(self): |
63 | 82 | speech.speech._getSpellingSpeechWithoutCharMode = ( |
64 | 83 | self._speech_speech__getSpellingSpeechWithoutCharMode |
65 | 84 | ) |
| 85 | + |
| 86 | + @scriptHandler.script( |
| 87 | + description=gettext( |
| 88 | + # Translators: Input help mode message for move review cursor to previous line command. |
| 89 | + "Moves the review cursor to the previous line of the current navigator object and speaks it", |
| 90 | + ), |
| 91 | + resumeSayAllMode=speech.sayAll.CURSOR.REVIEW, |
| 92 | + category=globalCommands.SCRCAT_TEXTREVIEW, |
| 93 | + gestures=("kb:numpad7", "kb(laptop):NVDA+upArrow", "ts(text):flickUp"), |
| 94 | + ) |
| 95 | + def script_review_previous_line(self, gesture): |
| 96 | + result = globalCommands.commands.script_review_previousLine(gesture) |
| 97 | + self.report_diff_line_status() |
| 98 | + return result |
| 99 | + |
| 100 | + @scriptHandler.script( |
| 101 | + description=gettext( |
| 102 | + # Translators: Input help mode message for read current line under review cursor command. |
| 103 | + "Reports the line of the current navigator object where the review cursor is situated. " |
| 104 | + "If this key is pressed twice, the current line will be spelled. " |
| 105 | + "Pressing three times will spell the line using character descriptions.", |
| 106 | + ), |
| 107 | + category=globalCommands.SCRCAT_TEXTREVIEW, |
| 108 | + gestures=("kb:numpad8", "kb(laptop):NVDA+shift+."), |
| 109 | + speakOnDemand=True, |
| 110 | + ) |
| 111 | + def script_review_currentLine(self, gesture): |
| 112 | + result = globalCommands.commands.script_review_currentLine(gesture) |
| 113 | + if scriptHandler.getLastScriptRepeatCount() == 0: |
| 114 | + self.report_diff_line_status() |
| 115 | + return result |
| 116 | + |
| 117 | + @scriptHandler.script( |
| 118 | + description=gettext( |
| 119 | + # Translators: Input help mode message for move review cursor to next line command. |
| 120 | + "Moves the review cursor to the next line of the current navigator object and speaks it", |
| 121 | + ), |
| 122 | + resumeSayAllMode=speech.sayAll.CURSOR.REVIEW, |
| 123 | + category=globalCommands.SCRCAT_TEXTREVIEW, |
| 124 | + gestures=("kb:numpad9", "kb(laptop):NVDA+downArrow", "ts(text):flickDown"), |
| 125 | + ) |
| 126 | + def script_review_nextLine(self, gesture): |
| 127 | + result = globalCommands.commands.script_review_nextLine(gesture) |
| 128 | + self.report_diff_line_status() |
| 129 | + return result |
| 130 | + |
| 131 | + def report_diff_line_status(self): |
| 132 | + info = api.getReviewPosition().copy() |
| 133 | + info.expand(textInfos.UNIT_LINE) |
| 134 | + text = info.text |
| 135 | + if not text or text[0] not in DIFF_SOUNDS: |
| 136 | + return |
| 137 | + nvwave.playWaveFile(DIFF_SOUNDS[text[0]]) |
0 commit comments