1
1
# -*- coding: UTF-8 -*-
2
2
# Beep keyboard: This add-on beeps with some keyboard events.
3
- # Copyright (C) 2019 David CM
3
+ # Copyright (C) 2019 - 2022 David CM
4
4
# Author: David CM <[email protected] >
5
5
# Released under GPL 2
6
6
#globalPlugins/beepKeyboard.py
7
7
8
8
import api , codecs , config , globalPluginHandler , gui , keyboardHandler , tones , ui , winreg , winUser , wx , addonHandler
9
+
9
10
addonHandler .initTranslation ()
10
11
11
- # config schema
12
- confspec = {
13
- "beepUpperWithCapsLock" : "boolean(default=True)" ,
14
- "beepCharacterWithShift" : "boolean(default=False)" ,
15
- "beepToggleKeyChanges" : "boolean(default=False)" ,
16
- "announceToggleStatus" : "boolean(default=True)" ,
17
- "disableBeepingOnPasswordFields" : "boolean(default=True)" ,
18
- "ignoredCharactersForShift" : "string(default='\\ x1b\\ t\\ b\\ r ')" ,
19
- "beepForCharacters" : "string(default='')" ,
20
- "shiftedCharactersTone" : "int_list(default=list(6000,10,25))" ,
21
- "customCharactersTone" : "int_list(default=list(6000,10,25))" ,
22
- "capsLockUpperTone" : "int_list(default=list(3000,40,50))" ,
23
- "toggleOffTone" : "int_list(default=list(500,40,50))" ,
24
- "toggleOnTone" : "int_list(default=list(2000, 40, 50))"
25
- }
26
- config .conf .spec ["beepKeyboard" ] = confspec
12
+
13
+ from ._configHelper import *
14
+ class AppConfig (BaseConfig ):
15
+ def __init__ (self ):
16
+ super ().__init__ ('beepKeyboard' )
17
+
18
+ beepUpperWithCapsLock = OptConfig ('boolean(default=True)' )
19
+ beepCharacterWithShift = OptConfig ('boolean(default=False)' )
20
+ beepToggleKeyChanges = OptConfig ('boolean(default=False)' )
21
+ announceToggleStatus = OptConfig ('boolean(default=True)' )
22
+ disableBeepingOnPasswordFields = OptConfig ('boolean(default=True)' )
23
+ ignoredCharactersForShift = OptConfig ("string(default='\\ x1b\\ t\\ b\\ r ')" )
24
+ beepForCharacters = OptConfig ("string(default='')" )
25
+ shiftedCharactersTone = OptConfig ('int_list(default=list(6000,10,25))' )
26
+ customCharactersTone = OptConfig ('int_list(default=list(6000,10,25))' )
27
+ capsLockUpperTone = OptConfig ('int_list(default=list(3000,40,50))' )
28
+ toggleOffTone = OptConfig ('int_list(default=list(500,40,50))' )
29
+ toggleOnTone = OptConfig ('int_list(default=list(2000, 40, 50))' )
30
+ AF = registerConfig (AppConfig )
31
+
27
32
28
33
# Constants.
29
34
REG_TOGGLE_KEYS = r"Control Panel\Accessibility\ToggleKeys"
35
40
36
41
def beep (l ):
37
42
""" it receives a list with three arguments to beep: [pitch, length, volume]"""
38
- if not (config . conf [ 'beepKeyboard' ][ ' disableBeepingOnPasswordFields' ] and api .getFocusObject ().isProtected ):
43
+ if not (AF . disableBeepingOnPasswordFields and api .getFocusObject ().isProtected ):
39
44
tones .beep (* l , right = l [- 1 ])
40
45
41
46
#saves the original _reportToggleKey function
@@ -46,9 +51,9 @@ def _reportToggleKey(self):
46
51
global ignoreToggleKeys
47
52
if not ignoreToggleKeys :
48
53
if winUser .getKeyState (self .vkCode ) & 1 :
49
- beep (config . conf [ 'beepKeyboard' ][ ' toggleOnTone' ] )
50
- else : beep (config . conf [ 'beepKeyboard' ][ ' toggleOffTone' ] )
51
- if ignoreToggleKeys or config . conf [ 'beepKeyboard' ][ ' announceToggleStatus' ] or (config . conf [ 'beepKeyboard' ][ ' disableBeepingOnPasswordFields' ] and api .getFocusObject ().isProtected ):
54
+ beep (AF . toggleOnTone )
55
+ else : beep (AF . toggleOffTone )
56
+ if ignoreToggleKeys or AF . announceToggleStatus or (AF . disableBeepingOnPasswordFields and api .getFocusObject ().isProtected ):
52
57
origReportToggleKey (self )
53
58
54
59
class BeepKeyboardSettingsPanel (gui .SettingsPanel ):
@@ -59,19 +64,19 @@ def makeSettings(self, settingsSizer):
59
64
sHelper = gui .guiHelper .BoxSizerHelper (self , sizer = settingsSizer )
60
65
# Translators: label for a checkbox option in the settings panel.
61
66
self .beepUpperWithCapsLock = sHelper .addItem (wx .CheckBox (self , label = _ ("Beep for uppercases when &caps lock is on" )))
62
- self .beepUpperWithCapsLock .SetValue (config . conf [ 'beepKeyboard' ][ ' beepUpperWithCapsLock' ] )
67
+ self .beepUpperWithCapsLock .SetValue (AF . beepUpperWithCapsLock )
63
68
# Translators: label for a checkbox option in the settings panel.
64
69
self .beepCharacterWithShift = sHelper .addItem (wx .CheckBox (self , label = _ ("Beep for typed characters when &shift is pressed" )))
65
- self .beepCharacterWithShift .SetValue (config . conf [ 'beepKeyboard' ][ ' beepCharacterWithShift' ] )
70
+ self .beepCharacterWithShift .SetValue (AF . beepCharacterWithShift )
66
71
# Translators: label for a checkbox option in the settings panel.
67
72
self .beepToggleKeyChanges = sHelper .addItem (wx .CheckBox (self , label = _ ("Beep for &toggle keys changes" )))
68
- self .beepToggleKeyChanges .SetValue (config . conf [ 'beepKeyboard' ][ ' beepToggleKeyChanges' ] )
73
+ self .beepToggleKeyChanges .SetValue (AF . beepToggleKeyChanges )
69
74
# Translators: label for a checkbox option in the settings panel.
70
75
self .announceToggleStatus = sHelper .addItem (wx .CheckBox (self , label = _ ("&Announce toggle keys changes (if Beep for toggle keys changes is disabled NVDA will have the original behavior)" )))
71
- self .announceToggleStatus .SetValue (config . conf [ 'beepKeyboard' ][ ' announceToggleStatus' ] )
76
+ self .announceToggleStatus .SetValue (AF . announceToggleStatus )
72
77
# Translators: label for a checkbox option in the settings panel.
73
78
self .disableBeepingOnPasswordFields = sHelper .addItem (wx .CheckBox (self , label = _ ("&disable beeping on password fields" )))
74
- self .disableBeepingOnPasswordFields .SetValue (config . conf [ 'beepKeyboard' ][ ' disableBeepingOnPasswordFields' ] )
79
+ self .disableBeepingOnPasswordFields .SetValue (AF . disableBeepingOnPasswordFields )
75
80
76
81
# Translators: label for a button to open advanced settings dialog in the settings panel.
77
82
advancedButton = sHelper .addItem (wx .Button (self , label = _ ("&Open advanced options" )))
@@ -82,11 +87,11 @@ def onAdvanced(self, evt):
82
87
advanced .ShowModal ()
83
88
84
89
def onSave (self ):
85
- config . conf [ 'beepKeyboard' ][ ' beepUpperWithCapsLock' ] = self .beepUpperWithCapsLock .GetValue ()
86
- config . conf [ 'beepKeyboard' ][ ' beepCharacterWithShift' ] = self .beepCharacterWithShift .GetValue ()
87
- config . conf [ 'beepKeyboard' ][ ' beepToggleKeyChanges' ] = self .beepToggleKeyChanges .GetValue ()
88
- config . conf [ 'beepKeyboard' ][ ' announceToggleStatus' ] = self .announceToggleStatus .GetValue ()
89
- config . conf [ 'beepKeyboard' ][ ' disableBeepingOnPasswordFields' ] = self .disableBeepingOnPasswordFields .GetValue ()
90
+ AF . beepUpperWithCapsLock = self .beepUpperWithCapsLock .GetValue ()
91
+ AF . beepCharacterWithShift = self .beepCharacterWithShift .GetValue ()
92
+ AF . beepToggleKeyChanges = self .beepToggleKeyChanges .GetValue ()
93
+ AF . announceToggleStatus = self .announceToggleStatus .GetValue ()
94
+ AF . disableBeepingOnPasswordFields = self .disableBeepingOnPasswordFields .GetValue ()
90
95
config .post_configProfileSwitch .notify ()
91
96
92
97
class AdvancedBeepKeyboardSettingsDialog (gui .SettingsDialog ):
@@ -95,14 +100,13 @@ class AdvancedBeepKeyboardSettingsDialog(gui.SettingsDialog):
95
100
96
101
def makeSettings (self , settingsSizer ):
97
102
sHelper = gui .guiHelper .BoxSizerHelper (self , sizer = settingsSizer )
98
- co = config .conf ['beepKeyboard' ]
99
103
# Translators: label for an edit text control option in the advanced settings dialog.
100
104
self .ignoredCharactersForShift = sHelper .addLabeledControl (_ ("&Ignored characters with shift pressed" ), wx .TextCtrl )
101
- self .ignoredCharactersForShift .SetValue (co [ ' ignoredCharactersForShift' ] )
105
+ self .ignoredCharactersForShift .SetValue (AF . ignoredCharactersForShift )
102
106
# Translators: label for an edit text control option in the advanced settings dialog.
103
107
self .beepForCharacters = sHelper .addLabeledControl (_ ("Beep &always for the following characters" ), wx .TextCtrl )
104
- self .beepForCharacters .SetValue (co [ ' beepForCharacters' ] )
105
- self .tonesParameters = [co [ ' shiftedCharactersTone' ], co [ ' customCharactersTone' ], co [ ' capsLockUpperTone' ], co [ ' toggleOffTone' ], co [ ' toggleOnTone' ] ]
108
+ self .beepForCharacters .SetValue (AF . beepForCharacters )
109
+ self .tonesParameters = [AF . shiftedCharactersTone , AF . customCharactersTone , AF . capsLockUpperTone , AF . toggleOffTone , AF . toggleOnTone ]
106
110
# Translators: label for a combo box control in the advanced settings dialog.
107
111
self .toneOptionsList = sHelper .addLabeledControl (_ ("&Select tone to configure" ), wx .Choice , choices = [
108
112
# Translators: label for an option of a combo box control.
@@ -165,9 +169,9 @@ def onToneOptionChange(self, evt):
165
169
166
170
def onOk (self , evt ):
167
171
self .updateCurrentToneValues ()
168
- config . conf [ 'beepKeyboard' ][ ' ignoredCharactersForShift' ] = self .ignoredCharactersForShift .GetValue ()
169
- config . conf [ 'beepKeyboard' ][ ' beepForCharacters' ] = self .beepForCharacters .GetValue ()
170
- config . conf [ 'beepKeyboard' ][ ' shiftedCharactersTone' ], config . conf [ 'beepKeyboard' ][ ' customCharactersTone' ], config . conf [ 'beepKeyboard' ][ ' capsLockUpperTone' ], config . conf [ 'beepKeyboard' ][ ' toggleOffTone' ], config . conf [ 'beepKeyboard' ][ ' toggleOnTone' ] = self .tonesParameters
172
+ AF . ignoredCharactersForShift = self .ignoredCharactersForShift .GetValue ()
173
+ AF . beepForCharacters = self .beepForCharacters .GetValue ()
174
+ AF . shiftedCharactersTone , AF . customCharactersTone , AF . capsLockUpperTone , AF . toggleOffTone , AF . toggleOnTone = self .tonesParameters
171
175
config .post_configProfileSwitch .notify ()
172
176
super (AdvancedBeepKeyboardSettingsDialog , self ).onOk (evt )
173
177
@@ -192,11 +196,11 @@ def checkEaseAccessToggleKeys(self):
192
196
193
197
def event_typedCharacter (self , obj , nextHandler , ch ):
194
198
nextHandler ()
195
- if config . conf [ 'beepKeyboard' ][ ' beepUpperWithCapsLock' ] and winUser .getKeyState (winUser .VK_CAPITAL )& 1 and ch .isupper ():
196
- beep (config . conf [ 'beepKeyboard' ][ ' capsLockUpperTone' ] )
197
- elif config . conf [ 'beepKeyboard' ][ ' beepCharacterWithShift' ] and not winUser .getKeyState (winUser .VK_CONTROL ) & 32768 and winUser .getKeyState (winUser .VK_SHIFT ) & 32768 and ch not in self .ignoredCharactersForShift and not (config .conf ["keyboard" ]["beepForLowercaseWithCapslock" ] and ch .islower () and winUser .getKeyState (winUser .VK_CAPITAL )& 1 ):
198
- beep (config . conf [ 'beepKeyboard' ][ ' shiftedCharactersTone' ] )
199
- elif ch in self .beepForCharacters : beep (config . conf [ 'beepKeyboard' ][ ' customCharactersTone' ] )
199
+ if AF . beepUpperWithCapsLock and winUser .getKeyState (winUser .VK_CAPITAL )& 1 and ch .isupper ():
200
+ beep (AF . capsLockUpperTone )
201
+ elif AF . beepCharacterWithShift and not winUser .getKeyState (winUser .VK_CONTROL ) & 32768 and winUser .getKeyState (winUser .VK_SHIFT ) & 32768 and ch not in self .ignoredCharactersForShift and not (config .conf ["keyboard" ]["beepForLowercaseWithCapslock" ] and ch .islower () and winUser .getKeyState (winUser .VK_CAPITAL )& 1 ):
202
+ beep (AF . shiftedCharactersTone )
203
+ elif ch in self .beepForCharacters : beep (AF . customCharactersTone )
200
204
201
205
def setExternalReportToggleStatus (self , flag ):
202
206
global ignoreToggleKeys
@@ -208,9 +212,9 @@ def setExternalReportToggleStatus(self, flag):
208
212
keyboardHandler .KeyboardInputGesture ._reportToggleKey = origReportToggleKey
209
213
210
214
def handleConfigProfileSwitch (self ):
211
- self .setExternalReportToggleStatus (config . conf [ 'beepKeyboard' ][ ' beepToggleKeyChanges' ] )
212
- self .ignoredCharactersForShift = codecs .decode (config . conf [ 'beepKeyboard' ][ ' ignoredCharactersForShift' ] , 'unicode_escape' )
213
- self .beepForCharacters = codecs .decode (config . conf [ 'beepKeyboard' ][ ' beepForCharacters' ] , 'unicode_escape' )
215
+ self .setExternalReportToggleStatus (AF . beepToggleKeyChanges )
216
+ self .ignoredCharactersForShift = codecs .decode (AF . ignoredCharactersForShift , 'unicode_escape' )
217
+ self .beepForCharacters = codecs .decode (AF . beepForCharacters , 'unicode_escape' )
214
218
215
219
def terminate (self ):
216
220
super (GlobalPlugin , self ).terminate ()
0 commit comments