|
| 1 | +# -*- coding: UTF-8 -*- |
| 2 | +# Synth ring settings selector: This add-on allows the user to select which settings should appear on the synth settings ring. |
| 3 | +# Copyright (C) 2019 David CM |
| 4 | +# Author: David CM <[email protected]> |
| 5 | +# Released under GPL 2 |
| 6 | +#globalPlugins/synthRingSettingsSelector.py |
| 7 | + |
| 8 | +import config, globalPluginHandler, gui, synthDriverHandler, wx, addonHandler |
| 9 | + |
| 10 | +addonHandler.initTranslation() |
| 11 | + |
| 12 | +confspec = { |
| 13 | + "availableSettings": "string_list(default=list('language', 'voice', 'variant', 'rate', 'rateBoost', 'volume', 'pitch', 'inflection'))" |
| 14 | +} |
| 15 | +config.conf.spec["synthRingSettingsSelector"] = confspec |
| 16 | + |
| 17 | +#saves the original setSynth function |
| 18 | +origSetSynth = synthDriverHandler.setSynth |
| 19 | + |
| 20 | +# alternate function to setSynth. |
| 21 | +def setSynth(name,isFallback=False): |
| 22 | + # return temporally to the original function because that function sometimes calls itself, and we don't want our function to be called. |
| 23 | + synthDriverHandler.setSynth = origSetSynth |
| 24 | + r = origSetSynth(name,isFallback) |
| 25 | + synthDriverHandler.setSynth = setSynth |
| 26 | + if r: setAvailableSettings() |
| 27 | + return r |
| 28 | + |
| 29 | +def setAvailableSettings(): |
| 30 | + if synthDriverHandler._curSynth: |
| 31 | + for s in synthDriverHandler._curSynth.supportedSettings: |
| 32 | + s.availableInSettingsRing = True if s.id in config.conf['synthRingSettingsSelector']['availableSettings'] else False |
| 33 | + synthDriverHandler._curSynth.initSettings() |
| 34 | + |
| 35 | +class SynthRingSettingsSelectorSettingsPanel(gui.SettingsPanel): |
| 36 | + # Translators: This is the label for the Synth ring settings selector settings category in NVDA Settings screen. |
| 37 | + title = _("Synth ring settings selector") |
| 38 | + |
| 39 | + def makeSettings(self, settingsSizer): |
| 40 | + self.curSettings = config.conf['synthRingSettingsSelector']['availableSettings'] |
| 41 | + sHelper = gui.guiHelper.BoxSizerHelper(self, sizer=settingsSizer) |
| 42 | + sHelper.addItem(wx.StaticText(self, label =_("Check the settings that you want to include in the Synth settings ring"))) |
| 43 | + settingsGroup = gui.guiHelper.BoxSizerHelper(self, sizer=wx.StaticBoxSizer( |
| 44 | + wx.StaticBox(self, label= _("Settings group")), wx.VERTICAL)) |
| 45 | + sHelper.addItem(settingsGroup) |
| 46 | + self.settingsCheckbox = {} |
| 47 | + for k in synthDriverHandler._curSynth.supportedSettings: |
| 48 | + self.settingsCheckbox[k.id] = settingsGroup.addItem(wx.CheckBox(self, label =k.displayNameWithAccelerator)) |
| 49 | + self.settingsCheckbox[k.id].SetValue(k.id in self.curSettings) |
| 50 | + |
| 51 | + def onSave(self): |
| 52 | + newSettings = [] |
| 53 | + keys = self.settingsCheckbox.keys() |
| 54 | + for k in keys: |
| 55 | + if self.settingsCheckbox[k].GetValue(): newSettings.append(k) |
| 56 | + [newSettings.append(k) for k in self.curSettings if k not in keys] |
| 57 | + config.conf['synthRingSettingsSelector']['availableSettings'] = newSettings |
| 58 | + config.post_configProfileSwitch.notify() |
| 59 | + |
| 60 | + |
| 61 | +class GlobalPlugin(globalPluginHandler.GlobalPlugin): |
| 62 | + def __init__(self): |
| 63 | + super(globalPluginHandler.GlobalPlugin, self).__init__() |
| 64 | + self.handleConfigProfileSwitch() |
| 65 | + config.post_configProfileSwitch.register(self.handleConfigProfileSwitch) |
| 66 | + synthDriverHandler.setSynth = setSynth |
| 67 | + gui.settingsDialogs.setSynth = setSynth |
| 68 | + setAvailableSettings() |
| 69 | + gui.settingsDialogs.NVDASettingsDialog.categoryClasses.append(SynthRingSettingsSelectorSettingsPanel) |
| 70 | + |
| 71 | + def handleConfigProfileSwitch(self): |
| 72 | + setAvailableSettings() |
| 73 | + |
| 74 | + def terminate(self): |
| 75 | + super(GlobalPlugin, self).terminate() |
| 76 | + synthDriverHandler.setSynth = origSetSynth |
| 77 | + gui.settingsDialogs.setSynth = origSetSynth |
| 78 | + gui.settingsDialogs.NVDASettingsDialog.categoryClasses.remove(SynthRingSettingsSelectorSettingsPanel) |
| 79 | + config.post_configProfileSwitch.unregister(self.handleConfigProfileSwitch) |
0 commit comments