From 8a8f46738db6271c7c2497c30f8121f474ad18e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9-Abush=20Clause?= Date: Mon, 28 Jul 2025 19:58:16 +0200 Subject: [PATCH 1/2] NVDA 2025.1: support for automatic input and output braille tables Fixes #142 Follow-up --- .../globalPlugins/brailleExtender/__init__.py | 20 +++++++++---------- .../globalPlugins/brailleExtender/addoncfg.py | 1 - .../brailleExtender/tabledictionaries.py | 7 ++++--- addon/globalPlugins/brailleExtender/utils.py | 18 +++++++++++++---- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/addon/globalPlugins/brailleExtender/__init__.py b/addon/globalPlugins/brailleExtender/__init__.py index 2eb3bcf0..8754aa14 100644 --- a/addon/globalPlugins/brailleExtender/__init__.py +++ b/addon/globalPlugins/brailleExtender/__init__.py @@ -269,7 +269,7 @@ def onDefaultDictionary(evt): @staticmethod def onTableDictionary(evt): - outTable = addoncfg.tablesTR[addoncfg.tablesFN.index(config.conf["braille"]["translationTable"])] + outTable = addoncfg.tablesTR[addoncfg.tablesFN.index(utils.getTranslationTable())] gui.mainFrame._popupSettingsDialog(tabledictionaries.DictionaryDlg, _("Table dictionary ({})").format(outTable), "table") @staticmethod @@ -573,8 +573,8 @@ def script_reportExtraInfos(self, gesture): def script_getTableOverview(self, gesture): inTable = brailleInput.handler.table.displayName - ouTable = addoncfg.tablesTR[addoncfg.tablesFN.index(config.conf["braille"]["translationTable"])] - t = (_(" Input table")+": %s\n"+_("Output table")+": %s\n\n") % (inTable+' (%s)' % (brailleInput.handler.table.fileName), ouTable+' (%s)' % (config.conf["braille"]["translationTable"])) + ouTable = addoncfg.tablesTR[addoncfg.tablesFN.index(utils.getTranslationTable())] + t = (_(" Input table")+": %s\n"+_("Output table")+": %s\n\n") % (inTable+' (%s)' % (brailleInput.handler.table.fileName), ouTable+' (%s)' % (utils.getTranslationTable())) t += utils.getTableOverview() ui.browseableMessage("
%s
" % t, _("Table overview (%s)") % brailleInput.handler.table.displayName, True) script_getTableOverview.__doc__ = _("Shows an overview of current input braille table in a browseable message") @@ -755,10 +755,11 @@ def script_switchInputBrailleTable(self, gesture): addoncfg.inputTables.append(config.conf["braille"]["inputTable"]) tid = addoncfg.inputTables.index(config.conf["braille"]["inputTable"]) nID = tid + 1 if tid + 1 < len(addoncfg.inputTables) else 0 - brailleInput.handler.table = brailleTables.listTables( - )[addoncfg.tablesFN.index(addoncfg.inputTables[nID])] + try: + brailleInput.handler.table = brailleTables.getTable(addoncfg.inputTables[nID]) + except ValueError: + brailleInput.handler.table = brailleTables.getTable(brailleTables.getDefaultTableForCurLang(brailleTables.TableType.INPUT)) ui.message(_("Input: %s") % brailleInput.handler.table.displayName) - return script_switchInputBrailleTable.__doc__ = _("Switches between configured braille input tables") def script_switchOutputBrailleTable(self, gesture): @@ -768,19 +769,18 @@ def script_switchOutputBrailleTable(self, gesture): return ui.message(_("You must choose at least two tables for this feature. Please fill in the settings")) if not config.conf["braille"]["translationTable"] in addoncfg.outputTables: addoncfg.outputTables.append(config.conf["braille"]["translationTable"]) - tid = addoncfg.outputTables.index( - config.conf["braille"]["translationTable"]) + tid = addoncfg.outputTables.index(utils.getTranslationTable()) nID = tid + 1 if tid + 1 < len(addoncfg.outputTables) else 0 config.conf["braille"]["translationTable"] = addoncfg.outputTables[nID] utils.refreshBD() tabledictionaries.setDictTables() - ui.message(_("Output: %s") % addoncfg.tablesTR[addoncfg.tablesFN.index(config.conf["braille"]["translationTable"])]) + ui.message(_("Output: %s") % addoncfg.tablesTR[addoncfg.tablesFN.index(utils.getTranslationTable())]) return script_switchOutputBrailleTable.__doc__ = _("Switches between configured braille output tables") def script_currentBrailleTable(self, gesture): inTable = brailleInput.handler.table.displayName - ouTable = addoncfg.tablesTR[addoncfg.tablesFN.index(config.conf["braille"]["translationTable"])] + ouTable = addoncfg.tablesTR[addoncfg.tablesFN.index(utils.getTranslationTable())] if ouTable == inTable: braille.handler.message(_("I⣿O:{I}").format(I=inTable, O=ouTable)) speech.speakMessage(_("Input and output: {I}.").format(I=inTable, O=ouTable)) diff --git a/addon/globalPlugins/brailleExtender/addoncfg.py b/addon/globalPlugins/brailleExtender/addoncfg.py index a51127fc..91dcb3b0 100644 --- a/addon/globalPlugins/brailleExtender/addoncfg.py +++ b/addon/globalPlugins/brailleExtender/addoncfg.py @@ -12,7 +12,6 @@ import globalVars import inputCore from logHandler import log - from .common import ( addonUpdateChannel, configDir, profilesDir, MIN_AUTO_SCROLL_DELAY, DEFAULT_AUTO_SCROLL_DELAY, MAX_AUTO_SCROLL_DELAY, MIN_STEP_DELAY_CHANGE, DEFAULT_STEP_DELAY_CHANGE, MAX_STEP_DELAY_CHANGE, diff --git a/addon/globalPlugins/brailleExtender/tabledictionaries.py b/addon/globalPlugins/brailleExtender/tabledictionaries.py index 23c8302a..9f5f2e45 100644 --- a/addon/globalPlugins/brailleExtender/tabledictionaries.py +++ b/addon/globalPlugins/brailleExtender/tabledictionaries.py @@ -19,6 +19,7 @@ from . import addoncfg from .common import configDir +from .utils import getTranslationTable from . import huc TableDictEntry = namedtuple("TableDictEntry", ("opcode", "textPattern", "braillePattern", "direction", "comment")) @@ -63,7 +64,7 @@ def getValidPathsDict(): return [path for path in paths if valid(path)] def getPathDict(type_): - if type_ == "table": path = os.path.join(configDir, "brailleDicts", config.conf["braille"]["translationTable"]) + if type_ == "table": path = os.path.join(configDir, "brailleDicts", getTranslationTable()) elif type_ == "tmp": path = os.path.join(configDir, "brailleDicts", "tmp") else: path = os.path.join(configDir, "brailleDicts", "default") return "%s.cti" % path @@ -293,7 +294,7 @@ def __init__(self, parent=None, title=_("Edit Dictionary Entry"), textPattern='' if specifyDict: # Translators: This is a label for an edit field in add dictionary entry dialog. dictText = _("Dictionary") - outTable = addoncfg.tablesTR[addoncfg.tablesFN.index(config.conf["braille"]["translationTable"])] + outTable = addoncfg.tablesTR[addoncfg.tablesFN.index(getTranslationTable())] dictChoices = [_("Global"), _("Table ({})").format(outTable), _("Temporary")] self.dictRadioBox = sHelper.addItem(wx.RadioBox(self, label=dictText, choices=dictChoices)) self.dictRadioBox.SetSelection(1) @@ -339,7 +340,7 @@ def __init__(self, parent=None, title=_("Edit Dictionary Entry"), textPattern='' def onSeeEntriesClick(self, evt): - outTable = addoncfg.tablesTR[addoncfg.tablesFN.index(config.conf["braille"]["translationTable"])] + outTable = addoncfg.tablesTR[addoncfg.tablesFN.index(getTranslationTable())] label = [_("Global dictionary"), _("Table dictionary ({})").format(outTable), _("Temporary dictionary")][self.dictRadioBox.GetSelection()] type_ = self.getType_() self.Destroy() diff --git a/addon/globalPlugins/brailleExtender/utils.py b/addon/globalPlugins/brailleExtender/utils.py index fd60a96a..eae4b1ea 100644 --- a/addon/globalPlugins/brailleExtender/utils.py +++ b/addon/globalPlugins/brailleExtender/utils.py @@ -26,10 +26,8 @@ addonHandler.initTranslation() import treeInterceptorHandler import unicodedata -from .addoncfg import CHOICE_braille, CHOICE_speech, CHOICE_speechAndBraille from .common import INSERT_AFTER, INSERT_BEFORE, REPLACE_TEXT, baseDir from . import huc -from . import tabledictionaries from . import volumehelper get_mute = volumehelper.get_mute @@ -37,6 +35,7 @@ def report_volume_level(): + from .addoncfg import CHOICE_braille, CHOICE_speech, CHOICE_speechAndBraille if get_mute() and config.conf["brailleExtender"]["volumeChangeFeedback"] in [CHOICE_braille, CHOICE_speechAndBraille]: return braille.handler.message(_("Muted sound")) volume_level = get_volume_level() @@ -307,7 +306,16 @@ def getCharFromValue(s): n = int(n, b) return chr(n) + +def getTranslationTable(): + translationTable = config.conf["braille"]["translationTable"] + if translationTable == "auto": + return brailleTables.getDefaultTableForCurLang(brailleTables.TableType.OUTPUT) + return translationTable + + def getCurrentBrailleTables(input_=False, brf=False): + from . import tabledictionaries if brf: tables = [ os.path.join(baseDir, "res", "brf.ctb").encode("UTF-8"), @@ -317,8 +325,10 @@ def getCurrentBrailleTables(input_=False, brf=False): tables = [] app = appModuleHandler.getAppModuleForNVDAObject(api.getNavigatorObject()) if app and app.appName != "nvda": tables += tabledictionaries.dictTables - if input_: mainTable = os.path.join(brailleTables.TABLES_DIR, brailleInput.handler._table.fileName) - else: mainTable = os.path.join(brailleTables.TABLES_DIR, config.conf["braille"]["translationTable"]) + if input_: + mainTable = os.path.join(brailleTables.TABLES_DIR, brailleInput.handler._table.fileName) + else: + mainTable = os.path.join(brailleTables.TABLES_DIR, getTranslationTable()) tables += [ mainTable, os.path.join(brailleTables.TABLES_DIR, "braille-patterns.cti") From a6c7d498832972a352f2edae1e639c6d8cc6bf67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9-Abush=20Clause?= Date: Tue, 29 Jul 2025 20:10:51 +0200 Subject: [PATCH 2/2] NVDA 2025.1: change `config.conf["documentFormatting"]["reportFontAttributes"]` -> `config.conf["documentFormatting"]["fontAttributeReporting"]` --- .../globalPlugins/brailleExtender/documentformatting.py | 2 ++ addon/globalPlugins/brailleExtender/patches.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/addon/globalPlugins/brailleExtender/documentformatting.py b/addon/globalPlugins/brailleExtender/documentformatting.py index 02f849be..1399cd2d 100644 --- a/addon/globalPlugins/brailleExtender/documentformatting.py +++ b/addon/globalPlugins/brailleExtender/documentformatting.py @@ -110,6 +110,8 @@ def normalize_report_key(key): key_ = "report" + key[0].upper() + key[1:] if key_ in config.conf["documentFormatting"]: return key_ + if key_ == "reportFontAttributes": + return "fontAttributeReporting" def get_report(key, simple=True): diff --git a/addon/globalPlugins/brailleExtender/patches.py b/addon/globalPlugins/brailleExtender/patches.py index 0ca64b32..a1159871 100644 --- a/addon/globalPlugins/brailleExtender/patches.py +++ b/addon/globalPlugins/brailleExtender/patches.py @@ -682,14 +682,19 @@ def getFormatFieldBraille(field, fieldCache, isAtStart, formatConfig): end_tag_list = [] tags = [] - if formatConfig["reportFontAttributes"]: + fontAttributeReporting = formatConfig.get("fontAttributeReporting") + if fontAttributeReporting is None: + fontAttributeReporting = formatConfig.get("reportFontAttributes") + else: + fontAttributeReporting = fontAttributeReporting == 1 + if fontAttributeReporting: tags += [tag for tag in [ "bold", "italic", "underline", "strikethrough"] if get_method(tag) == CHOICE_tags ] - if (normalize_report_key("superscriptsAndSubscripts") and formatConfig["reportSuperscriptsAndSubscripts"]) or formatConfig["reportFontAttributes"]: + if normalize_report_key("superscriptsAndSubscripts") and formatConfig["reportSuperscriptsAndSubscripts"]: tags += [tag for tag in [ "text-position:sub", "text-position:super"] if get_method(tag) == CHOICE_tags