Skip to content

Commit a25fd8d

Browse files
committed
add settings to ignore characters with shift and beep always characters.
add beep always for specified characters. add settings for tones parameters. add advanced settings dialog. update translation strings catalog template.
1 parent 8076ceb commit a25fd8d

File tree

3 files changed

+169
-20
lines changed

3 files changed

+169
-20
lines changed

addon/globalPlugins/beepKeyboard.py

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,27 @@
33
# Copyright (C) 2019 David CM
44
# Author: David CM <[email protected]>
55
# Released under GPL 2
6-
#globalPlugins/capsLockBeeper.py
6+
#globalPlugins/beepKeyboard.py
77

8-
import config, globalPluginHandler, gui, keyboardHandler, tones, winUser, wx, addonHandler
8+
import codecs, config, globalPluginHandler, gui, keyboardHandler, tones, winUser, wx, addonHandler
99
addonHandler.initTranslation()
1010

1111
confspec = {
1212
"beepUpperWithCapsLock": "boolean(default=True)",
1313
"beepCharacterWithShift": "boolean(default=False)",
1414
"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)"
1627
}
1728
config.conf.spec["beepKeyboard"] = confspec
1829

@@ -21,8 +32,8 @@
2132
# alternate function to report state key.
2233
def _reportToggleKey(self):
2334
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)
2637
if config.conf['beepKeyboard']['announceToggleStatus']: origReportToggleKey(self)
2738

2839
class BeepKeyboardSettingsPanel(gui.SettingsPanel):
@@ -43,6 +54,13 @@ def makeSettings(self, settingsSizer):
4354
# Translators: label for a checkbox option in the settings panel.
4455
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)")))
4556
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()
4664

4765
def onSave(self):
4866
config.conf['beepKeyboard']['beepUpperWithCapsLock'] = self.beepUpperWithCapsLock.GetValue()
@@ -51,15 +69,76 @@ def onSave(self):
5169
config.conf['beepKeyboard']['announceToggleStatus'] = self.announceToggleStatus.GetValue()
5270
if hasattr(config, "post_configProfileSwitch"):
5371
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+
56136

57137
class GlobalPlugin(globalPluginHandler.GlobalPlugin):
58138
def __init__(self):
59139
super(globalPluginHandler.GlobalPlugin, self).__init__()
60-
self.ignoredCharactersForShift = "\t\b\r "
140+
self.handleConfigProfileSwitch()
61141
gui.settingsDialogs.NVDASettingsDialog.categoryClasses.append(BeepKeyboardSettingsPanel)
62-
self.setExternalReportToggleStatus(config.conf['beepKeyboard']['beepToggleKeyChanges'])
63142
if hasattr(config, "post_configProfileSwitch"):
64143
config.post_configProfileSwitch.register(self.handleConfigProfileSwitch)
65144
else:
@@ -68,9 +147,13 @@ def __init__(self):
68147
def event_typedCharacter(self, obj, nextHandler, ch):
69148
nextHandler()
70149
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)
74157

75158
def setExternalReportToggleStatus(self, flag):
76159
if flag:
@@ -79,6 +162,8 @@ def setExternalReportToggleStatus(self, flag):
79162

80163
def handleConfigProfileSwitch(self):
81164
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')
82167

83168
def terminate(self):
84169
super(GlobalPlugin, self).terminate()

beepKeyboard.pot

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#, fuzzy
77
msgid ""
88
msgstr ""
9-
"Project-Id-Version: 'beepKeyboard' '0.1b2'\n"
9+
"Project-Id-Version: 'beepKeyboard' '0.1b3'\n"
1010
"Report-Msgid-Bugs-To: '[email protected]'\n"
11-
"POT-Creation-Date: 2019-04-13 09:13-0600\n"
11+
"POT-Creation-Date: 2019-04-14 11:57-0600\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -20,32 +20,96 @@ msgstr ""
2020
#. Translators: This is the label for the beepKeyboard settings category in NVDA Settings screen.
2121
#. Add-on summary, usually the user visible name of the addon.
2222
#. Translators: Summary for this add-on to be shown on installation and add-on information.
23-
#: addon\globalPlugins\beepKeyboard.py:30 buildVars.py:17
23+
#: addon\globalPlugins\beepKeyboard.py:41 buildVars.py:17
2424
msgid "Beep keyboard"
2525
msgstr ""
2626

2727
#. Translators: label for a checkbox option in the settings panel.
28-
#: addon\globalPlugins\beepKeyboard.py:35
28+
#: addon\globalPlugins\beepKeyboard.py:46
2929
msgid "Beep for uppercases when &caps lock is on"
3030
msgstr ""
3131

3232
#. Translators: label for a checkbox option in the settings panel.
33-
#: addon\globalPlugins\beepKeyboard.py:38
33+
#: addon\globalPlugins\beepKeyboard.py:49
3434
msgid "Beep for typed characters when &shift is pressed"
3535
msgstr ""
3636

3737
#. Translators: label for a checkbox option in the settings panel.
38-
#: addon\globalPlugins\beepKeyboard.py:41
38+
#: addon\globalPlugins\beepKeyboard.py:52
3939
msgid "Beep for &toggle keys changes"
4040
msgstr ""
4141

4242
#. Translators: label for a checkbox option in the settings panel.
43-
#: addon\globalPlugins\beepKeyboard.py:44
43+
#: addon\globalPlugins\beepKeyboard.py:55
4444
msgid ""
4545
"&Announce toggle keys changes (if Beep for toggle keys changes is disabled "
4646
"NVDA will have the original behavior)"
4747
msgstr ""
4848

49+
#: addon\globalPlugins\beepKeyboard.py:58
50+
msgid "&Open advanced options"
51+
msgstr ""
52+
53+
#. Translators: This is the label for the beep keyboard advanced settings dialog
54+
#: addon\globalPlugins\beepKeyboard.py:77
55+
msgid "Advanced settings - Keyboard beep"
56+
msgstr ""
57+
58+
#. Translators: label for an edit text control option in the advanced settings dialog.
59+
#: addon\globalPlugins\beepKeyboard.py:82
60+
msgid "Ignored characters with shift pressed"
61+
msgstr ""
62+
63+
#. Translators: label for an edit text control option in the advanced settings dialog.
64+
#: addon\globalPlugins\beepKeyboard.py:85
65+
msgid "beep always for the following characters"
66+
msgstr ""
67+
68+
#. Translators: label for an edit text control option in the advanced settings dialog.
69+
#: addon\globalPlugins\beepKeyboard.py:88
70+
msgid "shifted characters tone pitch"
71+
msgstr ""
72+
73+
#. Translators: label for an edit text control option in the advanced settings dialog.
74+
#: addon\globalPlugins\beepKeyboard.py:91
75+
msgid "shifted characters tone length"
76+
msgstr ""
77+
78+
#. Translators: label for an edit text control option in the advanced settings dialog.
79+
#: addon\globalPlugins\beepKeyboard.py:94
80+
msgid "shifted characters tone volume"
81+
msgstr ""
82+
83+
#. Translators: label for an edit text control option in the advanced settings dialog.
84+
#: addon\globalPlugins\beepKeyboard.py:97
85+
msgid "Custom characters tone pitch"
86+
msgstr ""
87+
88+
#. Translators: label for an edit text control option in the advanced settings dialog.
89+
#: addon\globalPlugins\beepKeyboard.py:100
90+
msgid "Custom characters tone length"
91+
msgstr ""
92+
93+
#. Translators: label for an edit text control option in the advanced settings dialog.
94+
#: addon\globalPlugins\beepKeyboard.py:103
95+
msgid "Custom characters tone volume"
96+
msgstr ""
97+
98+
#. Translators: label for an edit text control option in the advanced settings dialog.
99+
#: addon\globalPlugins\beepKeyboard.py:106
100+
msgid "Caps lock on typed characters tone pitch"
101+
msgstr ""
102+
103+
#. Translators: label for an edit text control option in the advanced settings dialog.
104+
#: addon\globalPlugins\beepKeyboard.py:109
105+
msgid "toggle off tone pitch"
106+
msgstr ""
107+
108+
#. Translators: label for an edit text control option in the advanced settings dialog.
109+
#: addon\globalPlugins\beepKeyboard.py:112
110+
msgid "toggle on tone pitch"
111+
msgstr ""
112+
49113
#. Add-on description
50114
#. Translators: Long description to be shown for this add-on on add-on information from add-ons manager
51115
#: buildVars.py:20

buildVars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Translators: Long description to be shown for this add-on on add-on information from add-ons manager
2020
"addon_description" : _("""This add-on beeps with some keyboard events."""),
2121
# version
22-
"addon_version" : "0.1b3",
22+
"addon_version" : "0.2b1",
2323
# Author(s)
2424
"addon_author" : u"David CM <[email protected]>",
2525
# URL for the add-on documentation support

0 commit comments

Comments
 (0)