Skip to content

Commit a3776d1

Browse files
committed
Update to use new MathCAT structure (published as a crate).
Found problem with addon not working -- needed to include python3.dll in build
1 parent 294e9b0 commit a3776d1

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "MathCatForPython"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Neil Soiffer <soiffer@alum.mit.edu>"]
55
edition = "2018"
66

@@ -12,8 +12,8 @@ edition = "2018"
1212
name = "libmathcat_py"
1313
crate-type = ["cdylib"]
1414

15-
[dependencies.MathCAT]
16-
path = "../mathcat/"
15+
[dependencies]
16+
mathcat = "0.1.2"
1717

1818
[dependencies.pyo3]
1919
version = "0.15.1"

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
# Copyright: this file is copyright GPL2
55
# The code additionally makes use of the MathCAT library (written in Rust) which is covered by the MIT license
66
# and also (obviously) requires external speech engines and braille drivers.
7-
# Note: this code is a lot of cut/paste from other code and very likely could be substantially improved/cleaned.
7+
# The plugin also requires the use of a small python dll: python3.dll
8+
# python3.dll has "Copyright © 2001-2022 Python Software Foundation; All Rights Reserved"
9+
810

11+
# Note: this code is a lot of cut/paste from other code and very likely could be substantially improved/cleaned.
912
import braille # we generate braille
1013
import globalPlugins # we are a global plugin
1114
import globalPluginHandler # we are a global plugin
@@ -278,13 +281,13 @@ def getSpeechForMathMl(self, mathml):
278281

279282

280283
def getBrailleForMathMl(self, mathml):
284+
log.info("***MathCAT getBrailleForMathMl")
281285
try:
282286
libmathcat.SetMathML(mathml)
283287
except Exception as e:
284288
log.error(e)
285289
speech.speakMessage(_("Illegal MathML found: see NVDA error log for details"))
286290
try:
287-
log.info("***MathCAT getBrailleForMathMl")
288291
return libmathcat.GetBraille("")
289292
except Exception as e:
290293
log.error(e)
@@ -311,5 +314,3 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
311314
def __init__(self, *args, **kwargs):
312315
super().__init__(*args, **kwargs)
313316
MathCAT.__init__(self)
314-
315-
log.info("---- read mathcat file 1 ---")

NVDA-addon/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/csh
22

3-
cargo build --release
3+
cargo build --target i686-pc-windows-msvc --release
44

55
# copy over all the rules and then remove a few "extra" files
66
cp -r ../../MathCAT/Rules addon/globalPlugins/MathCAT

src/lib.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#![allow(non_snake_case)]
2626
#![allow(clippy::needless_return)]
2727

28-
use libmathcat::interface::StringOrFloat;
28+
use libmathcat::*;
2929
use pyo3::prelude::*;
3030
use pyo3::wrap_pyfunction;
3131
use pyo3::exceptions::PyOSError;
@@ -36,7 +36,7 @@ fn convert_error<T>(result: Result<T, libmathcat::errors::Error>) -> PyResult<T>
3636
return match result {
3737
Ok(answer) => Ok(answer),
3838
Err(e) => {
39-
Err( PyOSError::new_err(libmathcat::interface::errors_to_string(&e)) )
39+
Err( PyOSError::new_err(errors_to_string(&e)) )
4040
},
4141
};
4242
}
@@ -45,7 +45,7 @@ fn convert_error<T>(result: Result<T, libmathcat::errors::Error>) -> PyResult<T>
4545
/// The absolute path location of the MathCAT Rules dir.
4646
/// IMPORTANT: This should be the first call to MathCAT
4747
pub fn SetRulesDir(_py: Python, rules_dir_location: String) -> PyResult<()> {
48-
return convert_error( libmathcat::interface::SetRulesDir(rules_dir_location) );
48+
return convert_error( set_rules_dir(rules_dir_location) );
4949
}
5050

5151
#[pyfunction]
@@ -55,13 +55,13 @@ pub fn SetRulesDir(_py: Python, rules_dir_location: String) -> PyResult<()> {
5555
/// Returns: the MathML that was set, annotated with 'id' values on each node (if none were present)
5656
/// The 'id' values can be used during navigation for highlighting the current node
5757
pub fn SetMathML(_py: Python, mathml_str: String) -> PyResult<String> {
58-
return convert_error( libmathcat::interface::SetMathML(mathml_str) );
58+
return convert_error( set_mathml(mathml_str) );
5959
}
6060
#[pyfunction]
6161
/// Get the spoken text of the MathML that was set.
6262
/// The speech takes into account any AT or user preferences.
6363
pub fn GetSpokenText(_py: Python) -> PyResult<String> {
64-
return convert_error( libmathcat::interface::GetSpokenText() );
64+
return convert_error( get_spoken_text() );
6565
}
6666

6767
#[pyfunction]
@@ -71,12 +71,7 @@ pub fn GetSpokenText(_py: Python) -> PyResult<String> {
7171
/// This function can be called multiple times to set different values.
7272
/// The values are persistent but can be overwritten by setting a preference with the same name and a different value.
7373
pub fn SetPreference(_py: Python, name: String, value: String) -> PyResult<()> {
74-
let as_float = value.parse::<f64>();
75-
let str_or_float = match as_float {
76-
Ok(f) => StringOrFloat::AsFloat(f),
77-
Err(_) => StringOrFloat::AsString(value),
78-
};
79-
return convert_error( libmathcat::interface::SetPreference(name, str_or_float) );
74+
return convert_error( set_preference(name, value) );
8075
}
8176

8277
#[pyfunction]
@@ -86,7 +81,7 @@ pub fn SetPreference(_py: Python, name: String, value: String) -> PyResult<()> {
8681
/// This function can be called multiple times to set different values.
8782
/// The values are persistent but can be overwritten by setting a preference with the same name and a different value.
8883
pub fn GetPreference(_py: Python, name: String) -> PyResult<String> {
89-
return match libmathcat::interface::GetPreference(name) {
84+
return match get_preference(name) {
9085
Some(value) => Ok(value),
9186
None => Err( PyOSError::new_err("Unknown preference name") ),
9287
}
@@ -99,15 +94,15 @@ pub fn GetPreference(_py: Python, name: String) -> PyResult<String> {
9994
///
10095
/// The braille returned depends upon the preference for braille output.
10196
pub fn GetBraille(_py: Python, nav_node_id: String) -> PyResult<String> {
102-
return convert_error( libmathcat::interface::GetBraille(nav_node_id) );
97+
return convert_error( get_braille(nav_node_id) );
10398
}
10499

105100
#[pyfunction]
106101
/// Given a key code along with the modifier keys, the current node is moved accordingly (or value reported in some cases).
107102
///
108103
/// The spoken text for the new current node is returned.
109104
pub fn DoNavigateKeyPress(_py: Python, key: usize, shift_key: bool, control_key: bool, alt_key: bool, meta_key: bool) -> PyResult<String> {
110-
return convert_error( libmathcat::interface::DoNavigateKeyPress(key, shift_key, control_key, alt_key, meta_key) );
105+
return convert_error( do_navigate_keypress(key, shift_key, control_key, alt_key, meta_key) );
111106
}
112107

113108
#[pyfunction]
@@ -130,19 +125,19 @@ pub fn DoNavigateKeyPress(_py: Python, key: usize, shift_key: bool, control_key:
130125
/// "Describe0","Describe1","Describe2","Describe3","Describe4","Describe5","Describe6","Describe7","Describe8","Describe9",
131126
/// "SetPlacemarker0","SetPlacemarker1","SetPlacemarker2","SetPlacemarker3","SetPlacemarker4","SetPlacemarker5","SetPlacemarker6","SetPlacemarker7","SetPlacemarker8","SetPlacemarker9",
132127
pub fn DoNavigateCommand(_py: Python, command: String) -> PyResult<String> {
133-
return convert_error( libmathcat::interface::DoNavigateCommand(command) );
128+
return convert_error( do_navigate_command(command) );
134129
}
135130

136131
#[pyfunction]
137132
/// Return the MathML associated with the current (navigation) node.
138133
pub fn GetNavigationMathMLId(_py: Python) -> PyResult<(String, usize)> {
139-
return convert_error( libmathcat::interface::GetNavigationMathMLId() );
134+
return convert_error( get_navigation_mathml_id() );
140135
}
141136

142137
#[pyfunction]
143138
/// Return the MathML associated with the current (navigation) node.
144139
pub fn GetNavigationMathML(_py: Python) -> PyResult<(String, usize)> {
145-
return convert_error( libmathcat::interface::GetNavigationMathML() );
140+
return convert_error( get_navigation_mathml() );
146141
}
147142

148143
#[pymodule]

0 commit comments

Comments
 (0)