Skip to content

Commit d81626e

Browse files
committed
Add GetNavigationBraille()
Add CopyAs support Bump version number
1 parent 8f4f4a4 commit d81626e

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[package]
88
name = "MathCatForPython"
9-
version = "0.4.2"
9+
version = "0.5.0"
1010
authors = ["Neil Soiffer <soiffer@alum.mit.edu>"]
1111
edition = "2018"
1212

@@ -19,7 +19,7 @@ name = "libmathcat_py"
1919
crate-type = ["cdylib"]
2020

2121
[dependencies.mathcat]
22-
version = "0.4.2"
22+
version = "0.5.0"
2323
# for testing MathCAT without having to publish a new version (change two occurences)
2424
# path = "../MathCAT/"
2525

@@ -29,7 +29,7 @@ features = ["extension-module", "abi3"]
2929

3030
[build-dependencies]
3131
zip = { version = "0.6.2", default-features = false, features = ["deflate"] }
32-
mathcat = "0.4.2"
32+
mathcat = "0.5.0"
3333
# for testing MathCAT without having to publish a new version (change two occurences)
3434
# mathcat = {path = "../MathCAT/"}
3535

addon/globalPlugins/MathCAT/MathCAT.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,24 @@ def script_rawdataToClip(self, gesture: KeyboardInputGesture):
313313
) # copy will fix up name spacing
314314
elif self.init_mathml != "":
315315
mathml = self.init_mathml
316-
self._copyToClipAsMathML(mathml)
316+
copy_as = "mathml"
317+
try:
318+
copy_as = libmathcat.GetPreference("CopyAs").lower()
319+
match copy_as:
320+
case "mathml" | "latex" | "asciimath":
321+
pass
322+
case _:
323+
copy_as = "mathml"
324+
except Exception as e:
325+
log.error(f"Not able to get 'CopyAs' preference: {e}")
326+
327+
mathml = self._wrapMathMLForClipBoard(mathml)
328+
if copy_as != "mathml":
329+
saved_braille_code: str = libmathcat.GetPreference("BrailleCode")
330+
libmathcat.SetPreference("BrailleCode", "LaTeX" if copy_as == "latex" else "ASCIIMath")
331+
mathml = libmathcat.GetNavigationBraille()
332+
libmathcat.SetPreference("BrailleCode", saved_braille_code)
333+
self._copyToClipAsMathML(mathml, copy_as == "mathml")
317334
# Translators: copy to clipboard
318335
ui.message(_("copy"))
319336
except Exception as e:
@@ -337,7 +354,7 @@ def _wrapMathMLForClipBoard(self, text: str) -> str:
337354
)
338355
return mathml_with_ns
339356

340-
def _copyToClipAsMathML(self, text: str, notify: Optional[bool] = False) -> bool:
357+
def _copyToClipAsMathML(self, text: str, is_mathml: bool, notify: Optional[bool] = False) -> bool:
341358
"""Copies the given text to the windows clipboard.
342359
@returns: True if it succeeds, False otherwise.
343360
@param text: the text which will be copied to the clipboard
@@ -350,9 +367,9 @@ def _copyToClipAsMathML(self, text: str, notify: Optional[bool] = False) -> bool
350367
try:
351368
with winUser.openClipboard(gui.mainFrame.Handle):
352369
winUser.emptyClipboard()
353-
text = self._wrapMathMLForClipBoard(text)
354-
self._setClipboardData(self.CF_MathML, '<?xml version="1.0"?>' + text)
355-
self._setClipboardData(self.CF_MathML_Presentation, '<?xml version="1.0"?>' + text)
370+
if is_mathml:
371+
self._setClipboardData(self.CF_MathML, '<?xml version="1.0"?>' + text)
372+
self._setClipboardData(self.CF_MathML_Presentation, '<?xml version="1.0"?>' + text)
356373
self._setClipboardData(winUser.CF_UNICODETEXT, text)
357374
got = getClipData()
358375
except OSError:
@@ -449,7 +466,7 @@ def _add_sounds(self):
449466
try:
450467
return libmathcat.GetPreference("SpeechSound") != "None"
451468
except Exception as e:
452-
print(f"An exception occurred: {e}")
469+
log.error(f"An exception occurred: {e}")
453470
return False
454471

455472
def getBrailleForMathMl(self, mathml: str):

buildVars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _(arg):
3232
and other translations are in progress."""
3333
),
3434
# version
35-
"addon_version": "0.4.2",
35+
"addon_version": "0.5.0",
3636
# Author(s)
3737
"addon_author": "Neil Soiffer <soiffer@alum.mit.edu>",
3838
# URL for the add-on documentation support

src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ pub fn GetPreference(_py: Python, name: String) -> PyResult<String> {
9595
}
9696

9797
#[pyfunction]
98-
#[allow(unused_variables)]
9998
/// Get the braille associated with the MathML node with a given id (MathML set by `SetMathML`]).
10099
/// An empty string can be used to return the braille associated with the entire expression.
101100
///
@@ -104,6 +103,15 @@ pub fn GetBraille(_py: Python, nav_node_id: String) -> PyResult<String> {
104103
return convert_error( get_braille(nav_node_id) );
105104
}
106105

106+
#[pyfunction]
107+
/// Get the braille associated with the MathML node with a given id (MathML set by `SetMathML`]).
108+
/// An empty string can be used to return the braille associated with the entire expression.
109+
///
110+
/// The braille returned depends upon the preference for braille output.
111+
pub fn GetNavigationBraille(_py: Python) -> PyResult<String> {
112+
return convert_error( get_navigation_braille() );
113+
}
114+
107115
#[pyfunction]
108116
/// Given a key code along with the modifier keys, the current node is moved accordingly (or value reported in some cases).
109117
///
@@ -156,6 +164,7 @@ fn libmathcat(_py: Python, m: &PyModule) -> PyResult<()> {
156164
m.add_function(wrap_pyfunction!(SetPreference, m)?)?;
157165
m.add_function(wrap_pyfunction!(GetPreference, m)?)?;
158166
m.add_function(wrap_pyfunction!(GetBraille, m)?)?;
167+
m.add_function(wrap_pyfunction!(GetNavigationBraille, m)?)?;
159168
m.add_function(wrap_pyfunction!(DoNavigateKeyPress, m)?)?;
160169
m.add_function(wrap_pyfunction!(DoNavigateCommand, m)?)?;
161170
m.add_function(wrap_pyfunction!(GetNavigationMathMLId, m)?)?;

0 commit comments

Comments
 (0)