Skip to content

Commit 3f8f864

Browse files
committed
Merged lines that were split across multiple lines -- they fit within the 130 char changed line limit. This makes searches easier to understand.
1 parent 53cea15 commit 3f8f864

File tree

4 files changed

+78
-229
lines changed

4 files changed

+78
-229
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@
3434
"Diné bizaad",
3535
"Dorerin",
3636
"Dorerin Naoero",
37+
"eigh",
3738
"English",
3839
"Español",
40+
"espeak",
41+
"ESPEAK",
3942
"Esperanto",
4043
"Ɛʋɛ",
4144
"Faka",

addon/globalPlugins/MathCAT/MathCAT.py

Lines changed: 23 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ def getLanguageToUse(mathMl: str) -> str:
9595
return mathCATLanguageSetting
9696

9797
languageMatch = RE_MATH_LANG.search(mathMl)
98-
language = (
99-
languageMatch.group(2) if languageMatch else getCurrentLanguage()
100-
) # seems to be current voice's language
98+
language = (languageMatch.group(2) if languageMatch else getCurrentLanguage()) # seems to be current voice's language
10199
language = language.lower().replace("_", "-")
102100
return language
103101

@@ -133,9 +131,7 @@ def ConvertSSMLTextForNVDA(text: str, language: str = "") -> list:
133131
# use_volume = VolumeCommand in supported_commands
134132
use_phoneme = PhonemeCommand in supported_commands
135133
# as of 7/23, oneCore voices do not implement the CharacterModeCommand despite it being in supported_commands
136-
use_character = (
137-
CharacterModeCommand in supported_commands and synth.name != "oneCore"
138-
)
134+
use_character = (CharacterModeCommand in supported_commands and synth.name != "oneCore")
139135
out = []
140136
if mathCATLanguageSetting != language:
141137
try:
@@ -154,17 +150,9 @@ def ConvertSSMLTextForNVDA(text: str, language: str = "") -> list:
154150
elif m.lastgroup == "char":
155151
ch = m.group("char")
156152
if use_character:
157-
out.extend(
158-
(CharacterModeCommand(True), ch, CharacterModeCommand(False))
159-
)
153+
out.extend((CharacterModeCommand(True), ch, CharacterModeCommand(False)))
160154
else:
161-
out.extend(
162-
(
163-
" ",
164-
"eigh" if ch == "a" and language.startswith("en") else ch,
165-
" ",
166-
)
167-
)
155+
out.extend((" ", "eigh" if ch == "a" and language.startswith("en") else ch, " "))
168156
elif m.lastgroup == "beep":
169157
out.append(BeepCommand(2000, 50))
170158
elif m.lastgroup == "pitch":
@@ -223,11 +211,7 @@ def reportFocus(self):
223211
except Exception as e:
224212
log.error(e)
225213
# Translators: this message directs users to look in the log file
226-
speech.speakMessage(
227-
_(
228-
"Error in starting navigation of math: see NVDA error log for details"
229-
)
230-
)
214+
speech.speakMessage(_("Error in starting navigation of math: see NVDA error log for details"))
231215

232216
def getBrailleRegions(self, review: bool = False):
233217
# log.info("***MathCAT start getBrailleRegions")
@@ -240,9 +224,7 @@ def getBrailleRegions(self, review: bool = False):
240224
except Exception as e:
241225
log.error(e)
242226
# Translators: this message directs users to look in the log file
243-
speech.speakMessage(
244-
_("Error in brailling math: see NVDA error log for details")
245-
)
227+
speech.speakMessage(_("Error in brailling math: see NVDA error log for details"))
246228
region.rawText = ""
247229

248230
# log.info("***MathCAT end getBrailleRegions ***")
@@ -251,11 +233,9 @@ def getBrailleRegions(self, review: bool = False):
251233
def getScript(self, gesture: KeyboardInputGesture):
252234
# Pass most keys to MathCAT. Pretty ugly.
253235
if (
254-
isinstance(gesture, KeyboardInputGesture)
255-
and "NVDA" not in gesture.modifierNames
256-
and (
257-
gesture.mainKeyName
258-
in {
236+
isinstance(gesture, KeyboardInputGesture) and
237+
"NVDA" not in gesture.modifierNames and
238+
gesture.mainKeyName in {
259239
"leftArrow",
260240
"rightArrow",
261241
"upArrow",
@@ -277,17 +257,15 @@ def getScript(self, gesture: KeyboardInputGesture):
277257
"9",
278258
}
279259
# or len(gesture.mainKeyName) == 1
280-
)
281260
):
282261
return self.script_navigate
283-
return super().getScript(gesture)
262+
else:
263+
return super().getScript(gesture)
284264

285265
def script_navigate(self, gesture: KeyboardInputGesture):
286266
# log.info("***MathCAT script_navigate")
287267
try:
288-
if (
289-
gesture is not None
290-
): # == None when initial focus -- handled in reportFocus()
268+
if (gesture is not None): # == None when initial focus -- handled in reportFocus()
291269
modNames = gesture.modifierNames
292270
text = libmathcat.DoNavigateKeyPress(
293271
gesture.vkCode,
@@ -374,9 +352,7 @@ def _copyToClipAsMathML(self, text: str, notify: Optional[bool] = False) -> bool
374352
winUser.emptyClipboard()
375353
text = self._wrapMathMLForClipBoard(text)
376354
self._setClipboardData(self.CF_MathML, '<?xml version="1.0"?>' + text)
377-
self._setClipboardData(
378-
self.CF_MathML_Presentation, '<?xml version="1.0"?>' + text
379-
)
355+
self._setClipboardData(self.CF_MathML_Presentation, '<?xml version="1.0"?>' + text)
380356
self._setClipboardData(winUser.CF_UNICODETEXT, text)
381357
got = getClipData()
382358
except OSError:
@@ -419,17 +395,13 @@ def __init__(self):
419395
try:
420396
# IMPORTANT -- SetRulesDir must be the first call to libmathcat besides GetVersion()
421397
rules_dir = path.join(path.dirname(path.abspath(__file__)), "Rules")
422-
log.info(
423-
f"MathCAT {libmathcat.GetVersion()} installed. Using rules dir: {rules_dir}"
424-
)
398+
log.info(f"MathCAT {libmathcat.GetVersion()} installed. Using rules dir: {rules_dir}")
425399
libmathcat.SetRulesDir(rules_dir)
426400
libmathcat.SetPreference("TTS", "SSML")
427401
except Exception as e:
428402
log.error(e)
429403
# Translators: this message directs users to look in the log file
430-
speech.speakMessage(
431-
_("MathCAT initialization failed: see NVDA error log for details")
432-
)
404+
speech.speakMessage(_("MathCAT initialization failed: see NVDA error log for details"))
433405
self._language = ""
434406

435407
def getSpeechForMathMl(self, mathml: str):
@@ -440,9 +412,7 @@ def getSpeechForMathMl(self, mathml: str):
440412
log.error(e)
441413
log.error(f"MathML is {mathml}")
442414
# Translators: this message directs users to look in the log file
443-
speech.speakMessage(
444-
_("Illegal MathML found: see NVDA error log for details")
445-
)
415+
speech.speakMessage(_("Illegal MathML found: see NVDA error log for details"))
446416
libmathcat.SetMathML("<math></math>") # set it to something
447417
try:
448418
synth = getSynth()
@@ -458,26 +428,20 @@ def getSpeechForMathMl(self, mathml: str):
458428
"true" if synthConfig["sayCapForCapitals"] else "false",
459429
)
460430
if PitchCommand in supported_commands:
461-
libmathcat.SetPreference(
462-
"CapitalLetters_Pitch", str(synthConfig["capPitchChange"])
463-
)
431+
libmathcat.SetPreference("CapitalLetters_Pitch", str(synthConfig["capPitchChange"]))
464432
if self._add_sounds():
465433
return (
466434
[BeepCommand(800, 25)]
467435
+ ConvertSSMLTextForNVDA(libmathcat.GetSpokenText(), self._language)
468436
+ [BeepCommand(600, 15)]
469437
)
470438
else:
471-
return ConvertSSMLTextForNVDA(
472-
libmathcat.GetSpokenText(), self._language
473-
)
439+
return ConvertSSMLTextForNVDA(libmathcat.GetSpokenText(), self._language)
474440

475441
except Exception as e:
476442
log.error(e)
477443
# Translators: this message directs users to look in the log file
478-
speech.speakMessage(
479-
_("Error in speaking math: see NVDA error log for details")
480-
)
444+
speech.speakMessage(_("Error in speaking math: see NVDA error log for details"))
481445
return [""]
482446

483447
def _add_sounds(self):
@@ -495,18 +459,14 @@ def getBrailleForMathMl(self, mathml: str):
495459
log.error(e)
496460
log.error(f"MathML is {mathml}")
497461
# Translators: this message directs users to look in the log file
498-
speech.speakMessage(
499-
_("Illegal MathML found: see NVDA error log for details")
500-
)
462+
speech.speakMessage(_("Illegal MathML found: see NVDA error log for details"))
501463
libmathcat.SetMathML("<math></math>") # set it to something
502464
try:
503465
return libmathcat.GetBraille("")
504466
except Exception as e:
505467
log.error(e)
506468
# Translators: this message directs users to look in the log file
507-
speech.speakMessage(
508-
_("Error in brailling math: see NVDA error log for details")
509-
)
469+
speech.speakMessage(_("Error in brailling math: see NVDA error log for details"))
510470
return ""
511471

512472
def interactWithMathMl(self, mathml: str):
@@ -541,9 +501,7 @@ def patched_speak(self, speechSequence: SpeechSequence): # noqa: C901
541501
elif isinstance(item, IndexCommand):
542502
textList.append('<mark name="%d" />' % item.index)
543503
elif isinstance(item, CharacterModeCommand):
544-
textList.append(
545-
'<say-as interpret-as="characters">' if item.state else "</say-as>"
546-
)
504+
textList.append('<say-as interpret-as="characters">' if item.state else "</say-as>")
547505
elif isinstance(item, LangChangeCommand):
548506
langChangeXML = self._handleLangChangeCommand(item, langChanged)
549507
textList.append(langChangeXML)
@@ -553,9 +511,7 @@ def patched_speak(self, speechSequence: SpeechSequence): # noqa: C901
553511
elif type(item) in self.PROSODY_ATTRS:
554512
if prosody:
555513
# Close previous prosody tag.
556-
textList.append(
557-
'<break time="1ms" />'
558-
) # hack added for cutoff speech (github.com/NSoiffer/MathCATForPython/issues/55)
514+
textList.append('<break time="1ms" />') # hack added for cutoff speech (issue #55)
559515
textList.append("</prosody>")
560516
attr = self.PROSODY_ATTRS[type(item)]
561517
if item.multiplier == 1:

0 commit comments

Comments
 (0)