3
3
# Copyright (C) 2019 David CM
4
4
# Author: David CM <[email protected] >
5
5
# Released under GPL 2
6
- #globalPlugins/capsLockBeeper .py
6
+ #globalPlugins/beepKeyboard .py
7
7
8
- import config , globalPluginHandler , gui , keyboardHandler , tones , winUser , wx , addonHandler
8
+ import codecs , config , globalPluginHandler , gui , keyboardHandler , tones , winUser , wx , addonHandler
9
9
addonHandler .initTranslation ()
10
10
11
11
confspec = {
12
12
"beepUpperWithCapsLock" : "boolean(default=True)" ,
13
13
"beepCharacterWithShift" : "boolean(default=False)" ,
14
14
"beepToggleKeyChanges" : "boolean(default=False)" ,
15
- "announceToggleStatus" : "boolean(default=True)"
15
+ "announceToggleStatus" : "boolean(default=True)" ,
16
+ "ignoredCharactersForShift" : "string(default='\t \b \r ')" ,
17
+ "beepForCharacters" : "string(default='')" ,
18
+ "shiftedCharactersPitch" : "integer(default=6000)" ,
19
+ "shiftedCharactersLength" : "integer(default=10)" ,
20
+ "shiftedCharactersVolume" : "integer(default=25)" ,
21
+ "customCharactersPitch" : "integer(default=6000)" ,
22
+ "customCharactersLength" : "integer(default=10)" ,
23
+ "customCharactersVolume" : "integer(default=25)" ,
24
+ "capsLockUpperPitch" : "integer(default=3000)" ,
25
+ "toggleOffPitch" : "integer(default=1000)" ,
26
+ "toggleOnPitch" : "integer(default=2000)"
16
27
}
17
28
config .conf .spec ["beepKeyboard" ] = confspec
18
29
21
32
# alternate function to report state key.
22
33
def _reportToggleKey (self ):
23
34
if winUser .getKeyState (self .vkCode ) & 1 :
24
- tones .beep (2000 , 40 )
25
- else : tones .beep (1000 , 40 )
35
+ tones .beep (config . conf [ 'beepKeyboard' ][ 'toggleOnPitch' ], 40 )
36
+ else : tones .beep (config . conf [ 'beepKeyboard' ][ 'toggleOffPitch' ], 40 )
26
37
if config .conf ['beepKeyboard' ]['announceToggleStatus' ]: origReportToggleKey (self )
27
38
28
39
class BeepKeyboardSettingsPanel (gui .SettingsPanel ):
@@ -43,6 +54,13 @@ def makeSettings(self, settingsSizer):
43
54
# Translators: label for a checkbox option in the settings panel.
44
55
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)" )))
45
56
self .announceToggleStatus .SetValue (config .conf ['beepKeyboard' ]['announceToggleStatus' ])
57
+
58
+ self .advancedButton = sHelper .addItem (wx .Button (self , label = _ ("&Open advanced options" )))
59
+ self .advancedButton .Bind (wx .EVT_BUTTON , self .onAdvanced )
60
+
61
+ def onAdvanced (self , evt ):
62
+ advanced = AdvancedBeepKeyboardSettingsDialog (self , multiInstanceAllowed = True )
63
+ advanced .ShowModal ()
46
64
47
65
def onSave (self ):
48
66
config .conf ['beepKeyboard' ]['beepUpperWithCapsLock' ] = self .beepUpperWithCapsLock .GetValue ()
@@ -51,15 +69,76 @@ def onSave(self):
51
69
config .conf ['beepKeyboard' ]['announceToggleStatus' ] = self .announceToggleStatus .GetValue ()
52
70
if hasattr (config , "post_configProfileSwitch" ):
53
71
config .post_configProfileSwitch .notify ()
54
- else :
55
- config .configProfileSwitched .notify ()
72
+ else : config .configProfileSwitched .notify ()
73
+
74
+
75
+ class AdvancedBeepKeyboardSettingsDialog (gui .SettingsDialog ):
76
+ # Translators: This is the label for the beep keyboard advanced settings dialog
77
+ title = _ ("Advanced settings - Keyboard beep" )
78
+
79
+ def makeSettings (self , settingsSizer ):
80
+ sHelper = gui .guiHelper .BoxSizerHelper (self , sizer = settingsSizer )
81
+ # Translators: label for an edit text control option in the advanced settings dialog.
82
+ self .ignoredCharactersForShift = sHelper .addLabeledControl (_ ("Ignored characters with shift pressed" ), wx .TextCtrl )
83
+ self .ignoredCharactersForShift .SetValue (config .conf ['beepKeyboard' ]['ignoredCharactersForShift' ])
84
+ # Translators: label for an edit text control option in the advanced settings dialog.
85
+ self .beepForCharacters = sHelper .addLabeledControl (_ ("beep always for the following characters" ), wx .TextCtrl )
86
+ self .beepForCharacters .SetValue (config .conf ['beepKeyboard' ]['beepForCharacters' ])
87
+ # Translators: label for an edit text control option in the advanced settings dialog.
88
+ self .shiftedCharactersPitch = sHelper .addLabeledControl (_ ("shifted characters tone pitch" ), wx .TextCtrl )
89
+ self .shiftedCharactersPitch .SetValue (str (config .conf ['beepKeyboard' ]['shiftedCharactersPitch' ]))
90
+ # Translators: label for an edit text control option in the advanced settings dialog.
91
+ self .shiftedCharactersLength = sHelper .addLabeledControl (_ ("shifted characters tone length" ), wx .TextCtrl )
92
+ self .shiftedCharactersLength .SetValue (str (config .conf ['beepKeyboard' ]['shiftedCharactersLength' ]))
93
+ # Translators: label for an edit text control option in the advanced settings dialog.
94
+ self .shiftedCharactersVolume = sHelper .addLabeledControl (_ ("shifted characters tone volume" ), wx .TextCtrl )
95
+ self .shiftedCharactersVolume .SetValue (str (config .conf ['beepKeyboard' ]['shiftedCharactersVolume' ]))
96
+ # Translators: label for an edit text control option in the advanced settings dialog.
97
+ self .customCharactersPitch = sHelper .addLabeledControl (_ ("Custom characters tone pitch" ), wx .TextCtrl )
98
+ self .customCharactersPitch .SetValue (str (config .conf ['beepKeyboard' ]['customCharactersPitch' ]))
99
+ # Translators: label for an edit text control option in the advanced settings dialog.
100
+ self .customCharactersLength = sHelper .addLabeledControl (_ ("Custom characters tone length" ), wx .TextCtrl )
101
+ self .customCharactersLength .SetValue (str (config .conf ['beepKeyboard' ]['customCharactersLength' ]))
102
+ # Translators: label for an edit text control option in the advanced settings dialog.
103
+ self .customCharactersVolume = sHelper .addLabeledControl (_ ("Custom characters tone volume" ), wx .TextCtrl )
104
+ self .customCharactersVolume .SetValue (str (config .conf ['beepKeyboard' ]['customCharactersVolume' ]))
105
+ # Translators: label for an edit text control option in the advanced settings dialog.
106
+ self .capsLockUpperPitch = sHelper .addLabeledControl (_ ("Caps lock on typed characters tone pitch" ), wx .TextCtrl )
107
+ self .capsLockUpperPitch .SetValue (str (config .conf ['beepKeyboard' ]['capsLockUpperPitch' ]))
108
+ # Translators: label for an edit text control option in the advanced settings dialog.
109
+ self .toggleOffPitch = sHelper .addLabeledControl (_ ("toggle off tone pitch" ), wx .TextCtrl )
110
+ self .toggleOffPitch .SetValue (str (config .conf ['beepKeyboard' ]['toggleOffPitch' ]))
111
+ # Translators: label for an edit text control option in the advanced settings dialog.
112
+ self .toggleOnPitch = sHelper .addLabeledControl (_ ("toggle on tone pitch" ), wx .TextCtrl )
113
+ self .toggleOnPitch .SetValue (str (config .conf ['beepKeyboard' ]['toggleOnPitch' ]))
114
+
115
+ def postInit (self ):
116
+ # ensure that focus is on the ignoredCharactersForShift
117
+ self .ignoredCharactersForShift .SetFocus ()
118
+
119
+ def onOk (self , evt ):
120
+ config .conf ['beepKeyboard' ]['ignoredCharactersForShift' ] = self .ignoredCharactersForShift .GetValue ()
121
+ config .conf ['beepKeyboard' ]['beepForCharacters' ] = self .beepForCharacters .GetValue ()
122
+ config .conf ['beepKeyboard' ]['shiftedCharactersPitch' ] = self .shiftedCharactersPitch .GetValue ()
123
+ config .conf ['beepKeyboard' ]['shiftedCharactersLength' ] = self .shiftedCharactersLength .GetValue ()
124
+ config .conf ['beepKeyboard' ]['shiftedCharactersVolume' ] = self .shiftedCharactersVolume .GetValue ()
125
+ config .conf ['beepKeyboard' ]['customCharactersPitch' ] = self .customCharactersPitch .GetValue ()
126
+ config .conf ['beepKeyboard' ]['"customCharactersLength' ] = self .customCharactersLength .GetValue ()
127
+ config .conf ['beepKeyboard' ]['"customCharactersVolume' ] = self .customCharactersVolume .GetValue ()
128
+ config .conf ['beepKeyboard' ]['capsLockUpperPitch' ] = self .capsLockUpperPitch .GetValue ()
129
+ config .conf ['beepKeyboard' ]['toggleOffPitch' ] = self .toggleOffPitch .GetValue ()
130
+ config .conf ['beepKeyboard' ]['toggleOnPitch' ] = self .toggleOnPitch .GetValue ()
131
+ if hasattr (config , "post_configProfileSwitch" ):
132
+ config .post_configProfileSwitch .notify ()
133
+ else : config .configProfileSwitched .notify ()
134
+ super (AdvancedBeepKeyboardSettingsDialog , self ).onOk (evt )
135
+
56
136
57
137
class GlobalPlugin (globalPluginHandler .GlobalPlugin ):
58
138
def __init__ (self ):
59
139
super (globalPluginHandler .GlobalPlugin , self ).__init__ ()
60
- self .ignoredCharactersForShift = " \t \b \r "
140
+ self .handleConfigProfileSwitch ()
61
141
gui .settingsDialogs .NVDASettingsDialog .categoryClasses .append (BeepKeyboardSettingsPanel )
62
- self .setExternalReportToggleStatus (config .conf ['beepKeyboard' ]['beepToggleKeyChanges' ])
63
142
if hasattr (config , "post_configProfileSwitch" ):
64
143
config .post_configProfileSwitch .register (self .handleConfigProfileSwitch )
65
144
else :
@@ -68,9 +147,13 @@ def __init__(self):
68
147
def event_typedCharacter (self , obj , nextHandler , ch ):
69
148
nextHandler ()
70
149
if config .conf ['beepKeyboard' ]['beepUpperWithCapsLock' ] and winUser .getKeyState (winUser .VK_CAPITAL )& 1 and ch .isupper ():
71
- tones .beep (3000 ,40 )
72
- elif config .conf ['beepKeyboard' ]['beepCharacterWithShift' ] and (winUser .getKeyState (winUser .VK_LSHIFT ) & 32768 or winUser .getKeyState (winUser .VK_RSHIFT ) & 32768 ) and ch not in self .ignoredCharactersForShift and not (config .conf ["keyboard" ]["beepForLowercaseWithCapslock" ] and ch .islower () and winUser .getKeyState (winUser .VK_CAPITAL )& 1 ):
73
- tones .beep (6000 , 10 , 30 , 30 )
150
+ tones .beep (config .conf ['beepKeyboard' ]['capsLockUpperPitch' ], 40 )
151
+ 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 ):
152
+ v = config .conf ['beepKeyboard' ]['shiftedCharactersVolume' ]
153
+ tones .beep (config .conf ['beepKeyboard' ]['shiftedCharactersPitch' ], config .conf ['beepKeyboard' ]['shiftedCharactersLength' ], v , v )
154
+ elif ch in self .beepForCharacters :
155
+ v = config .conf ['beepKeyboard' ]['customCharactersVolume' ]
156
+ tones .beep (config .conf ['beepKeyboard' ]['customCharactersPitch' ], config .conf ['beepKeyboard' ]['customCharactersLength' ], v , v )
74
157
75
158
def setExternalReportToggleStatus (self , flag ):
76
159
if flag :
@@ -79,6 +162,8 @@ def setExternalReportToggleStatus(self, flag):
79
162
80
163
def handleConfigProfileSwitch (self ):
81
164
self .setExternalReportToggleStatus (config .conf ['beepKeyboard' ]['beepToggleKeyChanges' ])
165
+ self .ignoredCharactersForShift = codecs .decode (config .conf ['beepKeyboard' ]['ignoredCharactersForShift' ], 'unicode_escape' )
166
+ self .beepForCharacters = codecs .decode (config .conf ['beepKeyboard' ]['beepForCharacters' ], 'unicode_escape' )
82
167
83
168
def terminate (self ):
84
169
super (GlobalPlugin , self ).terminate ()
0 commit comments