Skip to content

Commit 6ab0b48

Browse files
committed
Fix #27 -- the part where NVDA has problems when MathCAT has problems.
The "except" parts needed to return valid values. I've tested the speech case, but others remain untested.
1 parent 1cd5352 commit 6ab0b48

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

NVDA-addon/addon/globalPlugins/MathCAT/MathCAT.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ def getBrailleRegions(self, review=False):
147147
region.rawText = libmathcat.GetBraille("")
148148
except Exception as e:
149149
log.error(e)
150+
speech.speakMessage(_("Error in brailling math: see NVDA error log for details"))
151+
region.rawText = ""
150152

151153
# log.info("***MathCAT end getBrailleRegions ***")
152154
yield region
@@ -185,6 +187,8 @@ def script_navigate(self, gesture):
185187
braille.handler.update()
186188
except Exception as e:
187189
log.error(e)
190+
speech.speakMessage(_("Error in navigating math: see NVDA error log for details"))
191+
188192

189193
_startsWithMath = re.compile("\\s*?<math")
190194
@script(
@@ -199,6 +203,8 @@ def script_rawdataToClip(self, gesture):
199203
ui.message(_("copy"))
200204
except Exception as e:
201205
log.error(e)
206+
speech.speakMessage(_("unable to copy math: see NVDA error log for details"))
207+
202208

203209
# not a perfect match sequence, but should capture normal MathML
204210
_mathTagHasNameSpace = re.compile("<math .*?xmlns.+?>")
@@ -275,6 +281,8 @@ def __init__(self):
275281

276282
except Exception as e:
277283
log.error(e)
284+
speech.speakMessage(_("MathCAT initialization failed: see NVDA error log for details"))
285+
278286

279287
# store mathcontent for navigation and copy
280288
mathcontent = None
@@ -287,11 +295,13 @@ def getSpeechForMathMl(self, mathml):
287295
except Exception as e:
288296
log.error(e)
289297
speech.speakMessage(_("Illegal MathML found: see NVDA error log for details"))
298+
libmathcat.SetMathML("<math></math>") # set it to something
290299
try:
291300
return ConvertSSMLTextForNVDA(libmathcat.GetSpokenText())
292301
except Exception as e:
293302
log.error(e)
294303
speech.speakMessage(_("Error in speaking math: see NVDA error log for details"))
304+
return [""]
295305

296306

297307
def getBrailleForMathMl(self, mathml):
@@ -301,11 +311,13 @@ def getBrailleForMathMl(self, mathml):
301311
except Exception as e:
302312
log.error(e)
303313
speech.speakMessage(_("Illegal MathML found: see NVDA error log for details"))
314+
libmathcat.SetMathML("<math></math>") # set it to something
304315
try:
305316
return libmathcat.GetBraille("")
306317
except Exception as e:
307318
log.error(e)
308319
speech.speakMessage(_("Error in brailling math: see NVDA error log for details"))
320+
return ""
309321

310322

311323
def interactWithMathMl(self, mathMl):
@@ -321,3 +333,5 @@ def _setSpeechLanguage(self, mathMl):
321333
self._language = lang
322334
except Exception as e:
323335
log.error(e)
336+
speech.speakMessage(_("MathCAT does not support language %s: see NVDA error log for details" % lang))
337+

0 commit comments

Comments
 (0)