forked from nvaccess/nvda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobalCommands.py
More file actions
executable file
·5462 lines (5093 loc) · 213 KB
/
globalCommands.py
File metadata and controls
executable file
·5462 lines (5093 loc) · 213 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: UTF-8 -*-
# A part of NonVisual Desktop Access (NVDA)
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
# Copyright (C) 2006-2026 NV Access Limited, Peter Vágner, Aleksey Sadovoy, Rui Batista, Joseph Lee,
# Leonard de Ruijter, Derek Riemer, Babbage B.V., Davy Kager, Ethan Holliger, Łukasz Golonka, Accessolutions,
# Julien Cochuyt, Jakub Lukowicz, Bill Dengler, Cyrille Bougot, Rob Meredith, Luke Davis,
# Burman's Computer and Education Ltd, Cary-rowen.
import itertools
from typing import (
Optional,
Tuple,
Union,
)
from annotation import (
_AnnotationNavigation,
_AnnotationNavigationNode,
)
import audioDucking
import touchHandler
import keyboardHandler
import mouseHandler
import eventHandler
import review
import _magnifier
import _magnifier.commands
import controlTypes
import api
import textInfos
import speech
from speech import (
sayAll,
shortcutKeys,
)
from NVDAObjects import NVDAObject, NVDAObjectTextInfo
import globalVars
from logHandler import log, Logger
import gui
import systemUtils
import wx
import config
from config.configFlags import (
TetherTo,
ShowMessages,
BrailleMode,
OutputMode,
TypingEcho,
ReportSpellingErrors,
)
from config.featureFlag import FeatureFlag
from config.featureFlagEnums import BoolFlag
import winUser
import appModuleHandler
import winKernel
import treeInterceptorHandler
import browseMode
import languageHandler
import scriptHandler
from scriptHandler import script
import ui
import braille
import brailleInput
import inputCore
import characterProcessing
from baseObject import ScriptableObject
import core
from winAPI._powerTracking import reportCurrentBatteryStatus
import winVersion
from base64 import b16encode
from utils.security import objectBelowLockScreenAndWindowsIsLocked
import audio
import synthDriverHandler
from utils.displayString import DisplayStringEnum
import _remoteClient
#: Script category for text review commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_TEXTREVIEW = _("Text review")
#: Script category for Object navigation commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_OBJECTNAVIGATION = _("Object navigation")
#: Script category for system caret commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_SYSTEMCARET = _("System caret")
#: Script category for mouse commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_MOUSE = _("Mouse")
#: Script category for speech commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_SPEECH = _("Speech")
#: Script category for configuration dialogs commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_CONFIG = _("Configuration")
#: Script category for configuration profile activation and management commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_CONFIG_PROFILES = _("Configuration profiles")
#: Script category for Braille commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_BRAILLE = _("Braille")
#: Script category for Vision commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_VISION = _("Vision")
#: Script category for tools commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_TOOLS = pgettext("script category", "Tools")
#: Script category for touch commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_TOUCH = _("Touch screen")
#: Script category for focus commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_FOCUS = _("System focus")
#: Script category for system status commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_SYSTEM = _("System status")
#: Script category for input commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_INPUT = _("Input")
#: Script category for document formatting commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_DOCUMENTFORMATTING = _("Document formatting")
#: Script category for audio streaming commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_AUDIO = _("Audio")
#: Script category for Remote Access commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_REMOTE = pgettext("remote", "Remote Access")
# Translators: Reported when there are no settings to configure in synth settings ring
# (example: when there is no setting for language).
NO_SETTINGS_MSG = _("No settings")
# Translators: Reported when there is no selection
NO_SELECTION_MESSAGE = _("No selection")
def toggleBooleanValue(
configSection: str,
configKey: str,
enabledMsg: str,
disabledMsg: str,
) -> None:
"""
Toggles a boolean value in the configuration and returns the appropriate message.
:param configSection: The configuration section containing the boolean key.
:param configKey: The configuration key associated with the boolean value.
:param enabledMsg: The message for the enabled state.
:param disabledMsg: The message for the disabled state.
:return: None.
"""
currentValue = config.conf[configSection][configKey]
newValue = not currentValue
config.conf[configSection][configKey] = newValue
msg = enabledMsg if newValue else disabledMsg
ui.message(msg)
def toggleIntegerValue(
configSection: str,
configKey: str,
enumClass: "DisplayStringEnum",
messageTemplate: str,
) -> None:
"""
Cycles through integer configuration values and displays the corresponding message.
:param configSection: The configuration section containing the integer key.
:param configKey: The configuration key associated with the integer value.
:param enumClass: The enumeration class representing possible states.
:param messageTemplate: The message template with a placeholder, `{mode}`, for the state.
:return: None.
"""
currentValue = config.conf[configSection][configKey]
numVals = len(enumClass)
newValue = (currentValue + 1) % numVals
config.conf[configSection][configKey] = newValue
state = enumClass(newValue)
msg = messageTemplate.format(mode=state.displayString)
ui.message(msg)
class GlobalCommands(ScriptableObject):
"""Commands that are available at all times, regardless of the current focus."""
@script(
description=_(
# Translators: Describes the Cycle audio ducking mode command.
"Cycles through audio ducking modes which determine when NVDA lowers the volume of other sounds",
),
category=SCRCAT_AUDIO,
gesture="kb:NVDA+shift+d",
)
def script_cycleAudioDuckingMode(self, gesture):
if not audioDucking.isAudioDuckingSupported() or audioDucking._isAudioDuckingSuspended():
# Translators: a message when audio ducking is not supported on this machine
ui.message(_("Audio ducking not supported"))
return
curMode = config.conf["audio"]["audioDuckingMode"]
numModes = len(audioDucking.AudioDuckingMode)
nextMode = (curMode + 1) % numModes
audioDucking.setAudioDuckingMode(nextMode)
config.conf["audio"]["audioDuckingMode"] = nextMode
nextLabel = audioDucking.AudioDuckingMode(nextMode).displayString
ui.message(nextLabel)
@script(
description=_(
# Translators: Input help mode message for toggle input help command.
"Turns input help on or off. "
"When on, any input such as pressing a key on the keyboard "
"will tell you what script is associated with that input, if any.",
),
category=SCRCAT_INPUT,
gesture="kb:NVDA+1",
speakOnDemand=True,
)
def script_toggleInputHelp(self, gesture):
inputCore.manager.isInputHelpActive = not inputCore.manager.isInputHelpActive
# Translators: This will be presented when the input help is toggled.
stateOn = _("input help on. Press {gestureKeys} again to turn it off.").format(
gestureKeys=gesture.displayName,
)
# Translators: This will be presented when the input help is toggled.
stateOff = _("input help off")
state = stateOn if inputCore.manager.isInputHelpActive else stateOff
ui.message(state)
@script(
# Translators: Input help mode message for toggle sleep mode command.
description=_("Toggles sleep mode on and off for the active application."),
gestures=("kb(desktop):NVDA+shift+s", "kb(laptop):NVDA+shift+z"),
allowInSleepMode=True,
)
def script_toggleCurrentAppSleepMode(self, gesture):
curFocus = api.getFocusObject()
curApp = curFocus.appModule
if curApp.sleepMode:
curApp.sleepMode = False
# Translators: This is presented when sleep mode is deactivated, NVDA will continue working as expected.
ui.message(_("Sleep mode off"))
eventHandler.executeEvent("gainFocus", curFocus)
else:
eventHandler.executeEvent("loseFocus", curFocus)
curApp.sleepMode = True
# Translators: This is presented when sleep mode is activated, the focused application is self voicing, such as klango or openbook.
ui.message(_("Sleep mode on"))
@script(
description=_(
# Translators: Input help mode message for report current line command.
"Reports the current line under the application cursor. "
"Pressing this key twice will spell the current line. "
"Pressing three times will spell the line using character descriptions.",
),
category=SCRCAT_SYSTEMCARET,
gestures=("kb(desktop):NVDA+upArrow", "kb(laptop):NVDA+l"),
speakOnDemand=True,
)
def script_reportCurrentLine(self, gesture):
obj = api.getFocusObject()
treeInterceptor = obj.treeInterceptor
if (
isinstance(treeInterceptor, treeInterceptorHandler.DocumentTreeInterceptor)
and not treeInterceptor.passThrough
):
obj = treeInterceptor
try:
info = obj.makeTextInfo(textInfos.POSITION_CARET)
except (NotImplementedError, RuntimeError):
info = obj.makeTextInfo(textInfos.POSITION_FIRST)
info.expand(textInfos.UNIT_LINE)
scriptCount = scriptHandler.getLastScriptRepeatCount()
if scriptCount == 0:
speech.speakTextInfo(info, unit=textInfos.UNIT_LINE, reason=controlTypes.OutputReason.CARET)
else:
speech.spellTextInfo(info, useCharacterDescriptions=scriptCount > 1)
@script(
# Translators: Input help mode message for left mouse click command.
description=_("Clicks the left mouse button once at the current mouse position"),
category=SCRCAT_MOUSE,
gestures=("kb:numpadDivide", "kb(laptop):NVDA+["),
)
def script_leftMouseClick(self, gesture):
# Translators: Reported when left mouse button is clicked.
ui.message(_("Left click"))
mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTDOWN, 0, 0)
mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTUP, 0, 0)
@script(
# Translators: Input help mode message for right mouse click command.
description=_("Clicks the right mouse button once at the current mouse position"),
category=SCRCAT_MOUSE,
gestures=("kb:numpadMultiply", "kb(laptop):NVDA+]"),
)
def script_rightMouseClick(self, gesture):
# Translators: Reported when right mouse button is clicked.
ui.message(_("Right click"))
mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_RIGHTDOWN, 0, 0)
mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_RIGHTUP, 0, 0)
@script(
# Translators: Input help mode message for left mouse lock/unlock toggle command.
description=_("Locks or unlocks the left mouse button"),
category=SCRCAT_MOUSE,
gestures=("kb:shift+numpadDivide", "kb(laptop):NVDA+control+["),
)
def script_toggleLeftMouseButton(self, gesture):
if mouseHandler.isLeftMouseButtonLocked():
mouseHandler.unlockLeftMouseButton()
else:
mouseHandler.lockLeftMouseButton()
@script(
# Translators: Input help mode message for right mouse lock/unlock command.
description=_("Locks or unlocks the right mouse button"),
category=SCRCAT_MOUSE,
gestures=("kb:shift+numpadMultiply", "kb(laptop):NVDA+control+]"),
)
def script_toggleRightMouseButton(self, gesture):
if mouseHandler.isRightMouseButtonLocked():
mouseHandler.unlockRightMouseButton()
else:
mouseHandler.lockRightMouseButton()
@script(
description=_(
# Translators: Input help mode message for scroll up at the mouse position command.
"Scroll up at the mouse position",
),
category=SCRCAT_MOUSE,
)
def script_mouseScrollUp(self, gesture: "inputCore.InputGesture") -> None:
mouseHandler.scrollMouseWheel(winUser.WHEEL_DELTA, isVertical=True)
@script(
description=_(
# Translators: Input help mode message for scroll down at the mouse position command.
"Scroll down at the mouse position",
),
category=SCRCAT_MOUSE,
)
def script_mouseScrollDown(self, gesture: "inputCore.InputGesture") -> None:
mouseHandler.scrollMouseWheel(-winUser.WHEEL_DELTA, isVertical=True)
@script(
description=_(
# Translators: Input help mode message for scroll left at the mouse position command.
"Scroll left at the mouse position",
),
category=SCRCAT_MOUSE,
)
def script_mouseScrollLeft(self, gesture: "inputCore.InputGesture") -> None:
mouseHandler.scrollMouseWheel(-winUser.WHEEL_DELTA, isVertical=False)
@script(
description=_(
# Translators: Input help mode message for scroll right at the mouse position command.
"Scroll right at the mouse position",
),
category=SCRCAT_MOUSE,
)
def script_mouseScrollRight(self, gesture: "inputCore.InputGesture") -> None:
mouseHandler.scrollMouseWheel(winUser.WHEEL_DELTA, isVertical=False)
@script(
description=_(
# Translators: Input help mode message for report current selection command.
"Announces the current selection in edit controls and documents. "
"Pressing twice spells this information. "
"Pressing three times spells it using character descriptions. "
"Pressing four times shows it in a browsable message. ",
),
category=SCRCAT_SYSTEMCARET,
gestures=("kb(desktop):NVDA+shift+upArrow", "kb(laptop):NVDA+shift+s"),
speakOnDemand=True,
)
def script_reportCurrentSelection(self, gesture):
obj = api.getFocusObject()
treeInterceptor = obj.treeInterceptor
if (
isinstance(treeInterceptor, treeInterceptorHandler.DocumentTreeInterceptor)
and not treeInterceptor.passThrough
):
obj = treeInterceptor
try:
info = obj.makeTextInfo(textInfos.POSITION_SELECTION)
except (RuntimeError, NotImplementedError):
info = None
if not info or info.isCollapsed:
# Translators: The message reported when there is no selection
ui.message(_("No selection"))
else:
scriptCount = scriptHandler.getLastScriptRepeatCount()
# Translators: The message reported after selected text
selectMessage = speech.speech._getSelectionMessageSpeech(_("%s selected"), info.text)[0]
if scriptCount == 0:
speech.speakTextSelected(info.text)
braille.handler.message(selectMessage)
elif scriptCount == 3:
ui.browseableMessage(info.text, copyButton=True, closeButton=True)
return
elif len(info.text) < speech.speech.MAX_LENGTH_FOR_SELECTION_REPORTING:
speech.speakSpelling(info.text, useCharacterDescriptions=scriptCount > 1)
else:
speech.speakTextSelected(info.text)
braille.handler.message(selectMessage)
@staticmethod
def _getSelection() -> textInfos.TextInfo | None:
"""Gets the current selection, if any.
:return: The TextInfo corresponding to the current selection, or None if no selection is available.
"""
obj = api.getFocusObject()
treeInterceptor = obj.treeInterceptor
if (
isinstance(treeInterceptor, treeInterceptorHandler.DocumentTreeInterceptor)
and not treeInterceptor.passThrough
):
obj = treeInterceptor
try:
info = obj.makeTextInfo(textInfos.POSITION_SELECTION)
return info.copy()
except (RuntimeError, NotImplementedError):
return None
@script(
description=_(
# Translators: Input help mode message for report date and time command.
"If pressed once, reports the current time. If pressed twice, reports the current date",
),
category=SCRCAT_SYSTEM,
gesture="kb:NVDA+f12",
speakOnDemand=True,
)
def script_dateTime(self, gesture):
if scriptHandler.getLastScriptRepeatCount() == 0:
if systemUtils._isSystemClockSecondsVisible():
text = winKernel.GetTimeFormatEx(winKernel.LOCALE_NAME_USER_DEFAULT, None, None, None)
else:
text = winKernel.GetTimeFormatEx(
winKernel.LOCALE_NAME_USER_DEFAULT,
winKernel.TIME_NOSECONDS,
None,
None,
)
else:
text = winKernel.GetDateFormatEx(
winKernel.LOCALE_NAME_USER_DEFAULT,
winKernel.DATE_LONGDATE,
None,
None,
)
ui.message(text)
@script(
# Translators: Input help mode message for set the first value in the synth ring setting.
description=_("Set the first value of the current setting in the synth settings ring"),
category=SCRCAT_SPEECH,
)
def script_firstValueSynthRing(self, gesture: inputCore.InputGesture):
settingName = globalVars.settingsRing.currentSettingName
if not settingName:
ui.message(NO_SETTINGS_MSG)
return
settingValue = globalVars.settingsRing.first()
ui.message("%s %s" % (settingName, settingValue))
@script(
# Translators: Input help mode message for set the last value in the synth ring settings.
description=_("Set the last value of the current setting in the synth settings ring"),
category=SCRCAT_SPEECH,
)
def script_lastValueSynthRing(self, gesture: inputCore.InputGesture):
settingName = globalVars.settingsRing.currentSettingName
if not settingName:
ui.message(NO_SETTINGS_MSG)
return
settingValue = globalVars.settingsRing.last()
ui.message("%s %s" % (settingName, settingValue))
@script(
# Translators: Input help mode message for increase synth setting value command.
description=_("Increases the currently active setting in the synth settings ring"),
category=SCRCAT_SPEECH,
gestures=("kb(desktop):NVDA+control+upArrow", "kb(laptop):NVDA+shift+control+upArrow"),
)
def script_increaseSynthSetting(self, gesture):
settingName = globalVars.settingsRing.currentSettingName
if not settingName:
ui.message(NO_SETTINGS_MSG)
return
settingValue = globalVars.settingsRing.increase()
ui.message("%s %s" % (settingName, settingValue))
@script(
# Translators: Input help mode message for increasing synth setting value command in larger steps.
description=_("Increases the currently active setting in the synth settings ring in a larger step"),
category=SCRCAT_SPEECH,
gestures=("kb(desktop):NVDA+control+pageUp", "kb(laptop):NVDA+shift+control+pageUp"),
)
def script_increaseLargeSynthSetting(self, gesture: inputCore.InputGesture):
settingName = globalVars.settingsRing.currentSettingName
if not settingName:
ui.message(NO_SETTINGS_MSG)
return
settingValue = globalVars.settingsRing.increaseLarge()
ui.message("%s %s" % (settingName, settingValue))
@script(
# Translators: Input help mode message for decrease synth setting value command.
description=_("Decreases the currently active setting in the synth settings ring"),
category=SCRCAT_SPEECH,
gestures=("kb(desktop):NVDA+control+downArrow", "kb(laptop):NVDA+control+shift+downArrow"),
)
def script_decreaseSynthSetting(self, gesture):
settingName = globalVars.settingsRing.currentSettingName
if not settingName:
ui.message(NO_SETTINGS_MSG)
return
settingValue = globalVars.settingsRing.decrease()
ui.message("%s %s" % (settingName, settingValue))
@script(
# Translators: Input help mode message for decreasing synth setting value command in larger steps.
description=_("Decreases the currently active setting in the synth settings ring in a larger step"),
category=SCRCAT_SPEECH,
gestures=("kb(desktop):NVDA+control+pageDown", "kb(laptop):NVDA+control+shift+pageDown"),
)
def script_decreaseLargeSynthSetting(self, gesture: inputCore.InputGesture):
settingName = globalVars.settingsRing.currentSettingName
if not settingName:
ui.message(NO_SETTINGS_MSG)
return
settingValue = globalVars.settingsRing.decreaseLarge()
ui.message("%s %s" % (settingName, settingValue))
@script(
# Translators: Input help mode message for next synth setting command.
description=_("Moves to the next available setting in the synth settings ring"),
category=SCRCAT_SPEECH,
gestures=("kb(desktop):NVDA+control+rightArrow", "kb(laptop):NVDA+shift+control+rightArrow"),
)
def script_nextSynthSetting(self, gesture):
nextSettingName = globalVars.settingsRing.next()
if not nextSettingName:
ui.message(NO_SETTINGS_MSG)
return
nextSettingValue = globalVars.settingsRing.currentSettingValue
ui.message("%s %s" % (nextSettingName, nextSettingValue))
@script(
# Translators: Input help mode message for previous synth setting command.
description=_("Moves to the previous available setting in the synth settings ring"),
category=SCRCAT_SPEECH,
gestures=("kb(desktop):NVDA+control+leftArrow", "kb(laptop):NVDA+shift+control+leftArrow"),
)
def script_previousSynthSetting(self, gesture):
previousSettingName = globalVars.settingsRing.previous()
if not previousSettingName:
ui.message(NO_SETTINGS_MSG)
return
previousSettingValue = globalVars.settingsRing.currentSettingValue
ui.message("%s %s" % (previousSettingName, previousSettingValue))
@script(
# Translators: Input help mode message for toggling keyboard layout.
description=_("Toggles between desktop and laptop keyboard layout"),
category=SCRCAT_INPUT,
)
def script_toggleKeyboardLayout(self, gesture: "inputCore.InputGesture") -> None:
val = config.conf["keyboard"]["keyboardLayout"]
if val == "desktop":
newVal = "laptop"
else:
newVal = "desktop"
config.conf["keyboard"]["keyboardLayout"] = newVal
ui.message(
# Translators: Reported when the user toggles keyboard layout.
# {layout} will be replaced with the new keyboard layout, i.e. desktop or laptop
_("{layout} layout").format(layout=keyboardHandler.KeyboardInputGesture.LAYOUTS[newVal]),
)
@script(
# Translators: Input help mode message for cycling the reporting of typed characters.
description=_("Cycles through options for when to speak typed characters."),
category=SCRCAT_SPEECH,
gesture="kb:NVDA+2",
)
def script_toggleSpeakTypedCharacters(self, gesture: "inputCore.InputGesture") -> None:
toggleIntegerValue(
configSection="keyboard",
configKey="speakTypedCharacters",
enumClass=TypingEcho,
# Translators: Reported when the user cycles through speak typed characters modes.
# {mode} will be replaced with the mode; e.g. Off, On, Only in edit controls.
messageTemplate=_("Speak typed characters {mode}"),
)
@script(
# Translators: Input help mode message for cycling the reporting of typed words.
description=_("Cycles through options for when to speak typed words."),
category=SCRCAT_SPEECH,
gesture="kb:NVDA+3",
)
def script_toggleSpeakTypedWords(self, gesture: "inputCore.InputGesture") -> None:
toggleIntegerValue(
configSection="keyboard",
configKey="speakTypedWords",
enumClass=TypingEcho,
# Translators: Reported when the user cycles through speak typed words modes.
# {mode} will be replaced with the mode; e.g. Off, On, Only in edit controls.
messageTemplate=_("Speak typed words {mode}"),
)
@script(
# Translators: Input help mode message for toggle speak command keys command.
description=_("Toggles on and off the speaking of command keys"),
category=SCRCAT_SPEECH,
gesture="kb:NVDA+4",
)
def script_toggleSpeakCommandKeys(self, gesture):
if config.conf["keyboard"]["speakCommandKeys"]:
# Translators: The message announced when toggling the speak typed command keyboard setting.
state = _("speak command keys off")
config.conf["keyboard"]["speakCommandKeys"] = False
else:
# Translators: The message announced when toggling the speak typed command keyboard setting.
state = _("speak command keys on")
config.conf["keyboard"]["speakCommandKeys"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report font name command.
description=_("Toggles on and off the reporting of font changes"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportFontName(self, gesture):
if config.conf["documentFormatting"]["reportFontName"]:
# Translators: The message announced when toggling the report font name document formatting setting.
state = _("report font name off")
config.conf["documentFormatting"]["reportFontName"] = False
else:
# Translators: The message announced when toggling the report font name document formatting setting.
state = _("report font name on")
config.conf["documentFormatting"]["reportFontName"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report font size command.
description=_("Toggles on and off the reporting of font size changes"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportFontSize(self, gesture):
if config.conf["documentFormatting"]["reportFontSize"]:
# Translators: The message announced when toggling the report font size document formatting setting.
state = _("report font size off")
config.conf["documentFormatting"]["reportFontSize"] = False
else:
# Translators: The message announced when toggling the report font size document formatting setting.
state = _("report font size on")
config.conf["documentFormatting"]["reportFontSize"] = True
ui.message(state)
@script(
description=_(
# Translators: Input help mode message for toggle report font attributes command.
"Cycles font attribute reporting between speech, braille, speech and braille, and off.",
),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportFontAttributes(self, gesture: "inputCore.InputGesture"):
currentValue = config.conf["documentFormatting"]["fontAttributeReporting"]
nextValue = OutputMode((currentValue + 1) % len(OutputMode.__members__))
match nextValue:
case OutputMode.OFF:
# Translators: A state in which font attributes are not reported.
status = _("Do not report font attributes")
case OutputMode.SPEECH:
# Translators: A state in which font attributes are only spoken.
status = _("Speak font attributes")
case OutputMode.BRAILLE:
# Translators: A state in which font attributes are only brailled.
status = _("Braille font attributes")
case OutputMode.SPEECH_AND_BRAILLE:
# Translators: A state in which font attributes are both spoken and brailled.
status = _("Speak and braille font attributes")
config.conf["documentFormatting"]["fontAttributeReporting"] = nextValue
ui.message(status)
@script(
# Translators: Input help mode message for toggle superscripts and subscripts command.
description=_("Toggles on and off the reporting of superscripts and subscripts"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportSuperscriptsAndSubscripts(self, gesture):
shouldReport: bool = not config.conf["documentFormatting"]["reportSuperscriptsAndSubscripts"]
config.conf["documentFormatting"]["reportSuperscriptsAndSubscripts"] = shouldReport
if shouldReport:
# Translators: The message announced when toggling the report superscripts and subscripts
# document formatting setting.
state = _("report superscripts and subscripts on")
else:
# Translators: The message announced when toggling the report superscripts and subscripts
# document formatting setting.
state = _("report superscripts and subscripts off")
ui.message(state)
@script(
# Translators: Input help mode message for toggle report revisions command.
description=_("Toggles on and off the reporting of revisions"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportRevisions(self, gesture):
if config.conf["documentFormatting"]["reportRevisions"]:
# Translators: The message announced when toggling the report revisions document formatting setting.
state = _("report revisions off")
config.conf["documentFormatting"]["reportRevisions"] = False
else:
# Translators: The message announced when toggling the report revisions document formatting setting.
state = _("report revisions on")
config.conf["documentFormatting"]["reportRevisions"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report emphasis command.
description=_("Toggles on and off the reporting of emphasis"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportEmphasis(self, gesture):
if config.conf["documentFormatting"]["reportEmphasis"]:
# Translators: The message announced when toggling the report emphasis document formatting setting.
state = _("report emphasis off")
config.conf["documentFormatting"]["reportEmphasis"] = False
else:
# Translators: The message announced when toggling the report emphasis document formatting setting.
state = _("report emphasis on")
config.conf["documentFormatting"]["reportEmphasis"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report marked (highlighted) content command.
description=_("Toggles on and off the reporting of highlighted text"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportHighlightedText(self, gesture):
shouldReport: bool = not config.conf["documentFormatting"]["reportHighlight"]
config.conf["documentFormatting"]["reportHighlight"] = shouldReport
if shouldReport:
# Translators: The message announced when toggling the report marked document formatting setting.
state = _("report highlighted on")
else:
# Translators: The message announced when toggling the report marked document formatting setting.
state = _("report highlighted off")
ui.message(state)
@script(
# Translators: Input help mode message for toggle report colors command.
description=_("Toggles on and off the reporting of colors"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportColor(self, gesture):
if config.conf["documentFormatting"]["reportColor"]:
# Translators: The message announced when toggling the report colors document formatting setting.
state = _("report colors off")
config.conf["documentFormatting"]["reportColor"] = False
else:
# Translators: The message announced when toggling the report colors document formatting setting.
state = _("report colors on")
config.conf["documentFormatting"]["reportColor"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report alignment command.
description=_("Toggles on and off the reporting of text alignment"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportAlignment(self, gesture):
if config.conf["documentFormatting"]["reportAlignment"]:
# Translators: The message announced when toggling the report alignment document formatting setting.
state = _("report alignment off")
config.conf["documentFormatting"]["reportAlignment"] = False
else:
# Translators: The message announced when toggling the report alignment document formatting setting.
state = _("report alignment on")
config.conf["documentFormatting"]["reportAlignment"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report style command.
description=_("Toggles on and off the reporting of style changes"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportStyle(self, gesture):
if config.conf["documentFormatting"]["reportStyle"]:
# Translators: The message announced when toggling the report style document formatting setting.
state = _("report style off")
config.conf["documentFormatting"]["reportStyle"] = False
else:
# Translators: The message announced when toggling the report style document formatting setting.
state = _("report style on")
config.conf["documentFormatting"]["reportStyle"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report spelling errors command.
description=_("Cycles through options for how to report spelling or grammar errors"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportSpellingErrors(self, gesture: inputCore.InputGesture):
currentValue = config.conf["documentFormatting"]["reportSpellingErrors2"]
newValue = ((currentValue + 1) % ReportSpellingErrors.BRAILLE) | (
currentValue & ReportSpellingErrors.BRAILLE
)
config.conf["documentFormatting"]["reportSpellingErrors2"] = newValue
ui.message(
# Translators: Reported when the user cycles through the choices to report spelling or grammar errors.
# {mode} will be replaced with the mode; e.g. Off, Speech, Sound, Speech and sound.
_("Report errors {mode}").format(
mode=ReportSpellingErrors(newValue & ~ReportSpellingErrors.BRAILLE).displayString,
),
)
@script(
# Translators: Input help mode message for command to toggle report spelling or grammar errors in braille.
description=_("Toggles reporting spelling or grammar errors in braille"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportSpellingErrorsInBraille(self, gesture: inputCore.InputGesture):
formatConfig = config.conf["documentFormatting"]["reportSpellingErrors2"]
config.conf["documentFormatting"]["reportSpellingErrors2"] = (
formatConfig ^ ReportSpellingErrors.BRAILLE
)
if config.conf["documentFormatting"]["reportSpellingErrors2"] & ReportSpellingErrors.BRAILLE:
# Translators: Message presented when turning on reporting spelling or grammar errors in braille.
ui.message(_("Report errors in braille on"))
else:
# Translators: Message presented when turning off reporting spelling errors or grammar in braille.
ui.message(_("Report errors in braille off"))
@script(
# Translators: Input help mode message for toggle report pages command.
description=_("Toggles on and off the reporting of pages"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportPage(self, gesture):
if config.conf["documentFormatting"]["reportPage"]:
# Translators: The message announced when toggling the report pages document formatting setting.
state = _("report pages off")
config.conf["documentFormatting"]["reportPage"] = False
else:
# Translators: The message announced when toggling the report pages document formatting setting.
state = _("report pages on")
config.conf["documentFormatting"]["reportPage"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report line numbers command.
description=_("Toggles on and off the reporting of line numbers"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportLineNumber(self, gesture):
if config.conf["documentFormatting"]["reportLineNumber"]:
# Translators: The message announced when toggling the report line numbers document formatting setting.
state = _("report line numbers off")
config.conf["documentFormatting"]["reportLineNumber"] = False
else:
# Translators: The message announced when toggling the report line numbers document formatting setting.
state = _("report line numbers on")
config.conf["documentFormatting"]["reportLineNumber"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report line indentation command.
description=_("Cycles through line indentation settings"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportLineIndentation(self, gesture: inputCore.InputGesture):
ReportLineIndentation = config.configFlags.ReportLineIndentation
numVals = len(ReportLineIndentation)
state = ReportLineIndentation(
(config.conf["documentFormatting"]["reportLineIndentation"] + 1) % numVals,
)
config.conf["documentFormatting"]["reportLineIndentation"] = state.value
# Translators: A message reported when cycling through line indentation settings.
# {mode} will be replaced with the mode; i.e. Off, Speech, Tones or Both Speech and Tones.
ui.message(_("Report line indentation {mode}").format(mode=state.displayString))
@script(
# Translators: Input help mode message for toggle ignore blank lines for line indentation reporting command.
description=_("Toggles on and off the ignoring of blank lines for line indentation reporting"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleignoreBlankLinesForReportLineIndentation(self, gesture: inputCore.InputGesture) -> None:
ignore = config.conf["documentFormatting"]["ignoreBlankLinesForRLI"]
config.conf["documentFormatting"]["ignoreBlankLinesForRLI"] = not ignore
if ignore:
# Translators: The message announced when toggling off the ignore blank lines for line indentation
# reporting document formatting setting.
ui.message(_("Ignore blank lines for line indentation reporting off"))
else:
# Translators: The message announced when toggling on the ignore blank lines for line indentation
# reporting document formatting setting.
ui.message(_("Ignore blank lines for line indentation reporting on"))
@script(
# Translators: Input help mode message for toggle report paragraph indentation command.
description=_("Toggles on and off the reporting of paragraph indentation"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportParagraphIndentation(self, gesture):
if config.conf["documentFormatting"]["reportParagraphIndentation"]:
# Translators: The message announced when toggling the report paragraph indentation document formatting setting.
state = _("report paragraph indentation off")
config.conf["documentFormatting"]["reportParagraphIndentation"] = False
else:
# Translators: The message announced when toggling the report paragraph indentation document formatting setting.
state = _("report paragraph indentation on")
config.conf["documentFormatting"]["reportParagraphIndentation"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report line spacing command.
description=_("Toggles on and off the reporting of line spacing"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportLineSpacing(self, gesture):
if config.conf["documentFormatting"]["reportLineSpacing"]:
# Translators: The message announced when toggling the report line spacing document formatting setting.
state = _("report line spacing off")
config.conf["documentFormatting"]["reportLineSpacing"] = False
else:
# Translators: The message announced when toggling the report line spacing document formatting setting.
state = _("report line spacing on")
config.conf["documentFormatting"]["reportLineSpacing"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report tables command.
description=_("Toggles on and off the reporting of tables"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportTables(self, gesture):
if config.conf["documentFormatting"]["reportTables"]:
# Translators: The message announced when toggling the report tables document formatting setting.
state = _("report tables off")
config.conf["documentFormatting"]["reportTables"] = False
else:
# Translators: The message announced when toggling the report tables document formatting setting.
state = _("report tables on")
config.conf["documentFormatting"]["reportTables"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report table row/column headers command.
description=_("Cycle through the possible modes to report table row and column headers"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportTableHeaders(self, gesture):
ReportTableHeaders = config.configFlags.ReportTableHeaders
numVals = len(ReportTableHeaders)
state = ReportTableHeaders((config.conf["documentFormatting"]["reportTableHeaders"] + 1) % numVals)
config.conf["documentFormatting"]["reportTableHeaders"] = state.value
# Translators: Reported when the user cycles through report table header modes.
# {mode} will be replaced with the mode; e.g. None, Rows and columns, Rows or Columns.
ui.message(_("Report table headers {mode}").format(mode=state.displayString))
@script(
# Translators: Input help mode message for toggle report table cell coordinates command.
description=_("Toggles on and off the reporting of table cell coordinates"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportTableCellCoords(self, gesture):
if config.conf["documentFormatting"]["reportTableCellCoords"]:
# Translators: The message announced when toggling the report table cell coordinates document formatting setting.
state = _("report table cell coordinates off")
config.conf["documentFormatting"]["reportTableCellCoords"] = False
else:
# Translators: The message announced when toggling the report table cell coordinates document formatting setting.
state = _("report table cell coordinates on")
config.conf["documentFormatting"]["reportTableCellCoords"] = True
ui.message(state)
@script(
# Translators: Input help mode message for toggle report cell borders command.
description=_("Cycles through the cell border reporting settings"),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportCellBorders(self, gesture: inputCore.InputGesture):
ReportCellBorders = config.configFlags.ReportCellBorders
numVals = len(ReportCellBorders)
state = ReportCellBorders((config.conf["documentFormatting"]["reportCellBorders"] + 1) % numVals)
config.conf["documentFormatting"]["reportCellBorders"] = state.value
# Translators: Reported when the user cycles through report cell border modes.
# {mode} will be replaced with the mode; e.g. Off, Styles and Colors and styles.
ui.message(_("Report cell borders {mode}").format(mode=state.displayString))