Skip to content

Commit 1871945

Browse files
committed
Add copy as "speech"
Fixes #83
1 parent 03c690a commit 1871945

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

addon/globalPlugins/MathCAT/MathCAT.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ def ConvertSSMLTextForNVDA(text: str) -> list:
203203

204204

205205
class MathCATInteraction(mathPres.MathInteractionNVDAObject):
206-
# Put MathML on the clipboard using the two formats below (defined by MathML spec)
206+
# Put MathML or other formats on the clipboard.
207+
# MathML is put on the clipboard using the two formats below (defined by MathML spec)
207208
# We use both formats because some apps may only use one or the other
208209
# Note: filed https://github.com/nvaccess/nvda/issues/13240 to make this usable outside of MathCAT
209210
CF_MathML = windll.user32.RegisterClipboardFormatW("MathML")
@@ -352,7 +353,20 @@ def script_rawdataToClip(self, gesture: KeyboardInputGesture):
352353
) # copy will fix up name spacing
353354
elif self.init_mathml != "":
354355
mathml = self.init_mathml
355-
text_to_copy = self._wrapMathMLForClipBoard(mathml)
356+
if copy_as == "speech":
357+
# save the old MathML, set the navigation MathML as MathMl, get the speech, then reset the MathML
358+
saved_mathml: str = self.init_mathml
359+
saved_tts = libmathcat.GetPreference("TTS")
360+
if saved_mathml == '': # shouldn't happen
361+
raise Exception("Internal error -- MathML not set for copy")
362+
libmathcat.SetPreference("TTS", "None")
363+
libmathcat.SetMathML(mathml)
364+
# get the speech text and collapse the whitespace
365+
text_to_copy = ' '.join(libmathcat.GetSpokenText().split())
366+
libmathcat.SetPreference("TTS", saved_tts)
367+
libmathcat.SetMathML(saved_mathml)
368+
else:
369+
text_to_copy = self._wrapMathMLForClipBoard(mathml)
356370

357371
self._copyToClipAsMathML(text_to_copy, copy_as == "mathml")
358372
# Translators: copy to clipboard

addon/globalPlugins/MathCAT/MathCATPreferences.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# Navigation_OverView is boolean
3838
Navigation_NavVerbosity = ("Terse", "Medium", "Verbose")
3939
# Navigation_AutoZoomOut is boolean
40-
Navigation_CopyAs = ("MathML", "LaTeX", "ASCIIMath")
40+
Navigation_CopyAs = ("MathML", "LaTeX", "ASCIIMath", "Speech")
4141
Braille_BrailleNavHighlight = ("Off", "FirstChar", "EndPoints", "All")
4242

4343

@@ -638,8 +638,8 @@ def validate_user_preferences():
638638
UserInterface.validate("Navigation", "NavVerbosity", ["Terse", "Medium", "Full"], "Medium")
639639
# AutoZoomOut: true # Auto zoom out of 2D exprs (use shift-arrow to force zoom out if unchecked)
640640
UserInterface.validate("Navigation", "AutoZoomOut", [False, True], True)
641-
# CopyAs: MathML # MathML, LaTeX, ASCIIMath
642-
UserInterface.validate("Navigation", "CopyAs", ["MathML", "LaTeX", "ASCIIMath"], "MathML")
641+
# CopyAs: MathML # MathML, LaTeX, ASCIIMath, Speech
642+
UserInterface.validate("Navigation", "CopyAs", ["MathML", "LaTeX", "ASCIIMath", "Speech"], "MathML")
643643
# Braille:
644644
# BrailleNavHighlight: EndPoints
645645
# Highlight with dots 7 & 8 the current nav node -- values are Off, FirstChar, EndPoints, All

addon/globalPlugins/MathCAT/MathCATgui.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ def __init__(self, parent):
584584
_("LaTeX"),
585585
# Translators: options for Copy expression to clipboard as -- "ASCIIMath"
586586
_("ASCIIMath"),
587+
# Translators: options for Copy expression to clipboard as -- speech text
588+
_("Speech"),
587589
]
588590
self.m_choiceCopyAs = wx.Choice(
589591
self.m_panelNavigation,

0 commit comments

Comments
 (0)