From 645a20c508cf052935fe62a49195eba23e313f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9-Abush=20Clause?= Date: Sat, 26 Mar 2022 12:34:10 +0100 Subject: [PATCH] Allow to define a replacement for a specific input braille table --- .../brailleExtender/advancedinput.py | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/addon/globalPlugins/brailleExtender/advancedinput.py b/addon/globalPlugins/brailleExtender/advancedinput.py index 31d70376..542b52ca 100644 --- a/addon/globalPlugins/brailleExtender/advancedinput.py +++ b/addon/globalPlugins/brailleExtender/advancedinput.py @@ -1,6 +1,6 @@ # advancedinput.py # Part of BrailleExtender addon for NVDA -# Copyright 2016-2021 André-Abush CLAUSE, released under GPL. +# Copyright 2016-2022 André-Abush CLAUSE, released under GPL. import codecs import json import os @@ -176,24 +176,26 @@ def getReplacements(abreviations, strict=False): entry for entry in advancedInputDictHandler.getEntries() if entry.abreviation.startswith(abreviation) - and entry.table in [currentInputTable, "*"] + and entry.table in [currentInputTable, '*'] ] else: out += [ entry for entry in advancedInputDictHandler.getEntries() if entry.abreviation == abreviation - and entry.table in [currentInputTable, "*"] + and entry.table in [currentInputTable, '*'] ] return out -def translateTable(tableFilename): - if tableFilename == "*": - return _("all tables") - for table in brailleTables.listTables(): +def translateTable(tableFilename, return_index=False): + if tableFilename == '*': + return 0 if return_index else _("Any (all tables)") + for i, table in enumerate(brailleTables.listTables(), 1): + if not table.input: + continue if table.fileName == tableFilename: - return table.displayName + return i if return_index else table.displayName return tableFilename @@ -319,6 +321,7 @@ def onEditClick(self, event): entryDialog = DictionaryEntryDlg(self) entryDialog.abreviationTextCtrl.SetValue(entry.abreviation) entryDialog.replacementTextCtrl.SetValue(entry.replacement) + entryDialog.table.SetSelection(translateTable(entry.table, True)) while entryDialog.ShowModal() == wx.ID_OK: self.entry = entryDialog.dictEntry if not self._isValid(editIndex): @@ -376,17 +379,23 @@ def __init__(self, parent=None, title=_("Edit Dictionary Entry")): sHelper = gui.guiHelper.BoxSizerHelper(self, orientation=wx.VERTICAL) # Translators: This is a label for an edit field in add dictionary # entry dialog. - abreviationLabelText = _("&Abreviation") + abreviationLabelText = _("&Abreviation:") self.abreviationTextCtrl = sHelper.addLabeledControl( abreviationLabelText, wx.TextCtrl ) # Translators: This is a label for an edit field in add dictionary # entry dialog. - replacementLabelText = _("&Replace by") + replacementLabelText = _("&Replace by:") self.replacementTextCtrl = sHelper.addLabeledControl( replacementLabelText, wx.TextCtrl ) + label = _("Input table:") + choices = [translateTable('*')] + choices.extend([table.displayName for table in brailleTables.listTables() if table.input]) + self.table = sHelper.addLabeledControl(label, wx.Choice, choices=choices) + self.table.SetSelection(0) + sHelper.addDialogDismissButtons( self.CreateButtonSizer(wx.OK | wx.CANCEL)) @@ -409,7 +418,11 @@ def onOk(self, evt): if msg: return gui.messageBox(msg, addonName, wx.OK | wx.ICON_ERROR) abreviation = getTextInBraille(abreviation) - newEntry = AdvancedInputDictEntry(abreviation, replacement, "*") + table = '*' + idx = self.table.GetSelection() + if idx > 0: + table = [table.fileName for table in brailleTables.listTables() if table.input][idx-1] + newEntry = AdvancedInputDictEntry(abreviation, replacement, table) self.dictEntry = newEntry evt.Skip() @@ -432,6 +445,7 @@ def makeSettings(self, settingsSizer): wx.TextCtrl, value=config.conf["brailleExtender"]["advancedInputMode"] ["escapeSignUnicodeValue"],) + def onSave(self): config.conf["brailleExtender"]["advancedInputMode"]["stopAfterOneChar"] = self.stopAdvancedInputModeAfterOneChar.IsChecked()