Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/config/configSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@
copyAs = string(default="MathML")

[[braille]]
# Any supported braille code (currently Nemeth, UEB)
brailleCode = string(default="Nemeth")
# Any supported Braille code (such as UEB) or "Auto"
brailleCode = string(default="Auto")
# Highlight with dots 7 & 8 the current nav node -- values are Off, FirstChar, EndPoints, All
brailleNavHighlight = string(default="EndPoints")
# true/false
Expand Down
20 changes: 17 additions & 3 deletions source/gui/settingsDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2948,14 +2948,27 @@ def makeSettings(self, settingsSizer: wx.BoxSizer) -> None:

# Translators: label for combobox to specify which braille code to use
brailleMathCodeText = pgettext("math", "Braille math code for refreshable displays")
brailleMathCodeOptions: list[str] = preferences.getBrailleCodes()
availableBrailleCodes: list[str] = preferences.getBrailleCodes()
autoBrailleCode = preferences.getAutoBrailleCode(availableBrailleCodes)
# Translators: An option in Math settings to select a braille code automatically,
# according to NVDA's language.
autoDisplay = pgettext("math", "Automatic ({name})").format(name=autoBrailleCode)
self._brailleCodeIds: list[str] = ["Auto"]
brailleMathCodeOptions: list[str] = [autoDisplay]
self._brailleCodeIds.extend(availableBrailleCodes)
brailleMathCodeOptions.extend(availableBrailleCodes)
self.brailleMathCodeList = navGroup.addLabeledControl(
brailleMathCodeText,
wx.Choice,
choices=brailleMathCodeOptions,
)
self.bindHelpEvent("MathBrailleCode", self.brailleMathCodeList)
self.brailleMathCodeList.SetStringSelection(config.conf["math"]["braille"]["brailleCode"])
currentBrailleCode = config.conf["math"]["braille"]["brailleCode"]
try:
selectionIndex = self._brailleCodeIds.index(currentBrailleCode)
except ValueError:
selectionIndex = 0
self.brailleMathCodeList.SetSelection(selectionIndex)

# Translators: label for combobox to specify how braille dots should be modified when navigating/selecting subexprs
brailleHighlightsText = pgettext("math", "Highlight the current navigation node with dots 7 and 8")
Expand Down Expand Up @@ -3043,7 +3056,8 @@ def onSave(self):
BrailleNavHighlightOption,
self.brailleHighlightsList.GetSelection(),
)
mathConf["braille"]["brailleCode"] = self.brailleMathCodeList.GetStringSelection()
selectedBrailleIndex = self.brailleMathCodeList.GetSelection()
mathConf["braille"]["brailleCode"] = self._brailleCodeIds[selectedBrailleIndex]
mcPrefs: MathCATUserPreferences = MathCATUserPreferences.fromNVDAConfig()
mcPrefs.save()

Expand Down
2 changes: 2 additions & 0 deletions source/mathPres/MathCAT/MathCAT.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import mathPres
from .localization import getLanguageToUse
from .preferences import setEffectiveBrailleCode
from .speech import convertSSMLTextForNVDA


Expand Down Expand Up @@ -332,6 +333,7 @@ def __init__(self):
log.info(f"MathCAT {libmathcat.GetVersion()} installed. Using rules dir: {rulesDir}")
libmathcat.SetRulesDir(rulesDir)
libmathcat.SetPreference("TTS", "SSML")
setEffectiveBrailleCode()
except Exception:
log.exception()
# Translators: this message directs users to look in the log file
Expand Down
54 changes: 51 additions & 3 deletions source/mathPres/MathCAT/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os

import config
import languageHandler
import yaml
from logHandler import log
from NVDAState import WritePaths
Expand Down Expand Up @@ -229,6 +230,50 @@ def getBrailleCodes() -> list[str]:
return resultBrailleCodes


def getAutoBrailleCode(
availableCodes: list[str] | None = None,
languageCode: str | None = None,
) -> str:
"""
Determine the automatic MathCAT Braille code to use based on the current
or provided NVDA language.
"""
if not availableCodes:
availableCodes = getBrailleCodes()
if languageCode is None:
languageCode = languageHandler.getLanguage()

languagesToBrailleCodes: dict[str, str] = {
"en": "UEB",
"es": "CMU",
"es_CO": "CMU",
"fi": "ASCIIMath-finnish",
"sv": "Swedish",
"vi": "Vietnam",
}

res = languagesToBrailleCodes.get(languageCode)
if res and res in availableCodes:
return res
return "ASCIIMath"


def setEffectiveBrailleCode() -> None:
"""
Apply the effective Braille code to MathCAT at runtime, resolving auto
if needed.
"""
try:
brailleCodePref = config.conf["math"]["braille"]["brailleCode"]
effectiveCode = getAutoBrailleCode() if brailleCodePref == "Auto" else brailleCodePref
libmathcat.SetPreference("BrailleCode", effectiveCode)
except Exception as e:
log.debugWarning(
f"MathCAT: failed to set BrailleCode preference: {e}",
exc_info=True,
)


def toNVDAConfigKey(key: str) -> str:
"""Converts a key for MathCAT's preferences (UpperCamelCase) to a
key for NVDA's configobj-based configuration (lowerCamelCase).
Expand Down Expand Up @@ -359,6 +404,9 @@ def save(self) -> None:
log.exception(
f'Error in trying to set MathCAT "Language" preference to "{self._prefs["Speech"]["Language"]}": {e}',
)

setEffectiveBrailleCode()

if not os.path.exists(pathToUserPreferencesFolder()):
# create a folder for the user preferences
os.mkdir(pathToUserPreferencesFolder())
Expand Down Expand Up @@ -482,9 +530,9 @@ def _validateAll(self):
BrailleNavHighlightOption.ENDPOINTS.value,
)
# Braille.BrailleCode
# Default value: "Nemeth"
# Valid values: Any supported braille code (currently Nemeth, UEB, CMU, Vietnam)
self._validate("Braille", "BrailleCode", [], "Nemeth")
# Default value: Auto
# Valid values: Any supported braille code (for example Nemeth, UEB, CMU, Vietnam) or Auto
self._validate("Braille", "BrailleCode", [], "Auto")

def _validate(
self,
Expand Down
2 changes: 1 addition & 1 deletion user_docs/en/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Windows 10 on ARM is also no longer supported.
* VirusTotal scan results are now available in the details for an add-on.
An action has been added to view the full scan results on the VirusTotal website. (#18974)
* A new action has been added to see the latest changes for the current version of an add-on. (#14041, @josephsl, @nvdaes)
* Added built-in support for reading math content by integrating MathCAT. (#18323, @RyanMcCleary)
* Added built-in support for reading math content by integrating MathCAT. (#18323, #19368, @RyanMcCleary, @codeofdusk)
* NVDA can now use on-device AI to generate image descriptions. (#18475, @tianzeshi-study)
* This feature is experimental, and should not be used in situations where inaccurate descriptions could cause harm.
* To use this feature, NVDA will need to download image description data.
Expand Down
5 changes: 3 additions & 2 deletions user_docs/en/userGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -3379,11 +3379,12 @@ Specify how math will be copied to the clipboard.
###### Braille math code for refreshable displays {#MathBrailleCode}

The braille math code to use.
When this option is set to "Automatic", NVDA selects a default math braille code based on the current NVDA language.

| . {.hideHeaderRow} | . |
|---|---|
| Options | ASCIIMath, ASCIIMath-Finnish, CMU, LaTeX, Nemeth, Swedish, UEB, Vietnam |
| Default | Nemeth |
| Options | Automatic, ASCIIMath, ASCIIMath-Finnish, CMU, LaTeX, Nemeth, Swedish, UEB, Vietnam |
| Default | Automatic |

###### Highlight the current navigation node with dots 7 and 8 {#MathBrailleHighlights}

Expand Down
Loading