Skip to content

Commit ef51dc6

Browse files
committed
Integrate the MathCAT settings menu.
There are some lines that will get overridden when the builder file is changed: comment out of import wx.xrc import os and the logo line These need to be fixed, maybe with a change to the build script. Rearranged some code in MathCATPreferences.py to eliminate some global vars. Update the release number
1 parent bb06410 commit ef51dc6

File tree

8 files changed

+78
-76
lines changed

8 files changed

+78
-76
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ name = "libmathcat_py"
1313
crate-type = ["cdylib"]
1414

1515
[dependencies]
16-
mathcat = "0.1.7"
16+
mathcat = "0.1.13"
1717

1818
[dependencies.pyo3]
1919
version = "0.15.1"
2020
features = ["extension-module", "abi3"]
2121

2222
[build-dependencies]
23-
mathcat = "0.1.6"
23+
mathcat = "0.1.13"
2424
zip = "0.5.8"
2525

2626
[profile.release]

NVDA-addon/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
To build the addon, type "scons".
22
This rebuilds addon/manifest.ini and then zips up the addon dir to create
3-
mathCAT-0.1.nvda-addon (where the version number comes from the manifest)
3+
MathCAT-0.1.nvda-addon (where the version number comes from the manifest)

NVDA-addon/README.install

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ To install this addon for NVDA:
33
2. Choose Tools
44
3. Choose Manage add-ons...
55
4. Click Install...
6-
5. Pick the location where you saved mathCAT (the file name starts with "mathCAT" and ends with ".nvda-addon". The version number in the middle will change)
6+
5. Pick the location where you saved MathCAT (the file name starts with "MathCAT" and ends with ".nvda-addon". The version number in the middle will change)
77
6. Click "Open"
88
7. Click "Yes" to agree you want to install it.
99
8. Click "Close" to restart NVDA with MathCAT enabled.

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

Lines changed: 67 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -27,61 +27,48 @@
2727
Braille_BrailleNavHighlight = ("Off", "FirstChar", "EndPoints", "All")
2828
Braille_BrailleCode = ("Nemeth", "UEB")
2929

30-
def path_to_default_preferences():
31-
#the default preferences file is: C:\Users\<user-name>AppData\Roaming\\nvda\\addons\\mathCAT\\globalPlugins\\MathCAT\\Rules\\prefs.yaml
32-
return os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\mathCAT\\globalPlugins\\MathCAT\\Rules\\prefs.yaml"
33-
34-
def path_to_user_preferences_folder():
35-
#the user preferences file is stored at: C:\Users\<user-name>AppData\Roaming\MathCAT\prefs.yaml
36-
return os.path.expanduser('~')+"\\AppData\\Roaming\\MathCAT"
37-
38-
def path_to_user_preferences():
39-
#the user preferences file is stored at: C:\Users\<user-name>AppData\Roaming\MathCAT\prefs.yaml
40-
return path_to_user_preferences_folder() + "\\prefs.yaml"
41-
42-
def load_default_preferences():
43-
global user_preferences
44-
#load default preferences into the user preferences data structure (overwrites existing)
45-
if os.path.exists(path_to_default_preferences()):
46-
with open(path_to_default_preferences(), encoding='utf-8') as f:
47-
user_preferences = yaml.load(f, Loader=yaml.FullLoader)
48-
else:
49-
#default preferences file is NOT found
50-
wx.MessageBox(_(u"MathCat preferences file not found. The program will now exit."), "Error", wx.OK | wx.ICON_ERROR)
51-
os.sys.exit(-1)
52-
53-
def load_user_preferences():
54-
global user_preferences
55-
#merge user file values into the user preferences data structure
56-
if os.path.exists(path_to_user_preferences()):
57-
with open(path_to_user_preferences(), encoding='utf-8') as f:
58-
# merge with the default preferences, overwriting with the user's values
59-
user_preferences.update(yaml.load(f, Loader=yaml.FullLoader))
60-
61-
def write_user_preferences():
62-
if not os.path.exists(path_to_user_preferences_folder()):
63-
#create a folder for the user preferences
64-
os.mkdir(path_to_user_preferences_folder())
65-
with open(path_to_user_preferences(), 'w', encoding="utf-8") as f:
66-
#write values to the user preferences file, NOT the default
67-
yaml.dump(user_preferences, stream=f, allow_unicode=True)
6830

6931
class UserInterface(MathCATgui.MathCATPreferencesDialog):
32+
def __init__(self,parent):
33+
#initialize parent class
34+
MathCATgui.MathCATPreferencesDialog.__init__(self,parent)
35+
36+
# load in the system values followed by the user prefs (if any)
37+
UserInterface.load_default_preferences()
38+
UserInterface.load_user_preferences()
39+
40+
if "MathCATPreferencesLastCategory" in user_preferences:
41+
#set the categories selection to what we used on last run
42+
self.m_listBoxPreferencesTopic.SetSelection(user_preferences["MathCATPreferencesLastCategory"])
43+
#show the appropriate dialogue page
44+
self.m_simplebookPanelsCategories.SetSelection(self.m_listBoxPreferencesTopic.GetSelection())
45+
else:
46+
#set the categories selection to the first item
47+
self.m_listBoxPreferencesTopic.SetSelection(0)
48+
user_preferences["MathCATPreferencesLastCategory"]="0"
49+
#populate the languages
50+
UserInterface.GetLanguages(self)
51+
#set the ui items to match the preferences
52+
UserInterface.set_ui_values(self)
53+
54+
def path_to_languages_folder():
55+
#the user preferences file is stored at: MathCAT\Rules\Languages
56+
return os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\mathCAT\\globalPlugins\\MathCAT\\Rules\\Languages"
7057

7158
def GetLanguages(self):
7259
#clear the language choices
7360
self.m_choiceLanguage.Clear()
7461
#populate the language choices
75-
for f in os.listdir(path_to_languages_folder()):
76-
if os.path.isdir(path_to_languages_folder()+"\\"+f):
62+
for f in os.listdir(UserInterface.path_to_languages_folder()):
63+
if os.path.isdir(UserInterface.path_to_languages_folder()+"\\"+f):
7764
self.m_choiceLanguage.Append(f)
7865

7966
def GetSpeechStyles(self, this_SpeechStyle):
8067
#clear the SpeechStyle choices
8168
self.m_choiceSpeechStyle.Clear()
8269
#get the currently selected language
8370
this_language = self.m_choiceLanguage.GetStringSelection()
84-
this_path = os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\mathCAT\\globalPlugins\\MathCAT\\Rules\\Languages\\"+this_language+"\\*_Rules.yaml"
71+
this_path = os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\MathCAT\\globalPlugins\\MathCAT\\Rules\\Languages\\"+this_language+"\\*_Rules.yaml"
8572
#populate the m_choiceSpeechStyle choices
8673
for f in glob.glob(this_path):
8774
fname = os.path.basename(f)
@@ -103,7 +90,7 @@ def set_ui_values(self):
10390
#the language in the settings file is not in the folder structure, something went wrong, set to the first in the list
10491
self.m_choiceLanguage.SetSelection(0)
10592
#now get the available SpeechStyles from the folder structure and set to the preference setting is possible
106-
UserInterface.GetSpeechStyles(self, user_preferences["Speech"]["SpeechStyle"])
93+
self.GetSpeechStyles(user_preferences["Speech"]["SpeechStyle"])
10794
self.m_choiceSpeechAmount.SetSelection(Speech_Verbosity.index(user_preferences["Speech"]["Verbosity"]))
10895
self.m_sliderRelativeSpeed.SetValue(user_preferences["Speech"]["MathRate"])
10996
self.m_choiceSpeechForChemical.SetSelection(Speech_Chemistry.index(user_preferences["Speech"]["Chemistry"]))
@@ -143,42 +130,59 @@ def get_ui_values(self):
143130
user_preferences["Braille"]["BrailleCode"] = Braille_BrailleCode[self.m_choiceBrailleMathCode.GetSelection()]
144131
user_preferences["MathCATPreferencesLastCategory"] = self.m_listBoxPreferencesTopic.GetSelection()
145132

146-
def __init__(self,parent):
147-
#initialize parent class
148-
MathCATgui.MathCATPreferencesDialog.__init__(self,parent)
133+
def path_to_default_preferences():
134+
#the default preferences file is: C:\Users\<user-name>AppData\Roaming\\nvda\\addons\\MathCAT\\globalPlugins\\MathCAT\\Rules\\prefs.yaml
135+
return os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\MathCAT\\globalPlugins\\MathCAT\\Rules\\prefs.yaml"
149136

150-
# load in the system values followed by the user prefs (if any)
151-
load_default_preferences()
152-
load_user_preferences()
137+
def path_to_user_preferences_folder():
138+
#the user preferences file is stored at: C:\Users\<user-name>AppData\Roaming\MathCAT\prefs.yaml
139+
return os.path.expanduser('~')+"\\AppData\\Roaming\\MathCAT"
153140

154-
if "MathCATPreferencesLastCategory" in user_preferences:
155-
#set the categories selection to what we used on last run
156-
self.m_listBoxPreferencesTopic.SetSelection(user_preferences["MathCATPreferencesLastCategory"])
157-
#show the appropriate dialogue page
158-
self.m_simplebookPanelsCategories.SetSelection(self.m_listBoxPreferencesTopic.GetSelection())
141+
def path_to_user_preferences():
142+
#the user preferences file is stored at: C:\Users\<user-name>AppData\Roaming\MathCAT\prefs.yaml
143+
return UserInterface.path_to_user_preferences_folder() + "\\prefs.yaml"
144+
145+
def load_default_preferences():
146+
global user_preferences
147+
#load default preferences into the user preferences data structure (overwrites existing)
148+
if os.path.exists(UserInterface.path_to_default_preferences()):
149+
with open(UserInterface.path_to_default_preferences(), encoding='utf-8') as f:
150+
user_preferences = yaml.load(f, Loader=yaml.FullLoader)
159151
else:
160-
#set the categories selection to the first item
161-
self.m_listBoxPreferencesTopic.SetSelection(0)
162-
user_preferences["MathCATPreferencesLastCategory"]="0"
163-
#populate the languages
164-
UserInterface.GetLanguages(self)
165-
#set the ui items to match the preferences
166-
UserInterface.set_ui_values(self)
152+
#default preferences file is NOT found
153+
wx.MessageBox(_(u"MathCat preferences file not found. The program will now exit."), "Error", wx.OK | wx.ICON_ERROR)
154+
os.sys.exit(-1)
155+
156+
def load_user_preferences():
157+
global user_preferences
158+
#merge user file values into the user preferences data structure
159+
if os.path.exists(UserInterface.path_to_user_preferences()):
160+
with open(UserInterface.path_to_user_preferences(), encoding='utf-8') as f:
161+
# merge with the default preferences, overwriting with the user's values
162+
user_preferences.update(yaml.load(f, Loader=yaml.FullLoader))
163+
164+
def write_user_preferences():
165+
if not os.path.exists(UserInterface.path_to_user_preferences_folder()):
166+
#create a folder for the user preferences
167+
os.mkdir(UserInterface.path_to_user_preferences_folder())
168+
with open(UserInterface.path_to_user_preferences(), 'w', encoding="utf-8") as f:
169+
#write values to the user preferences file, NOT the default
170+
yaml.dump(user_preferences, stream=f, allow_unicode=True)
167171

168172
def OnClickOK(self,event):
169173
UserInterface.get_ui_values(self)
170-
write_user_preferences()
174+
UserInterface.write_user_preferences()
171175
self.Destroy()
172176

173177
def OnClickCancel(self,event):
174178
self.Destroy()
175179

176180
def OnClickApply(self,event):
177181
UserInterface.get_ui_values(self)
178-
write_user_preferences()
182+
UserInterface.write_user_preferences()
179183

180184
def OnClickReset(self,event):
181-
load_default_preferences()
185+
UserInterface.load_default_preferences()
182186
UserInterface.set_ui_values(self)
183187

184188
def OnClickHelp(self,event):

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
###########################################################################
99

1010
import wx
11-
import wx.xrc
11+
# import wx.xrc
12+
import os
1213

1314
import gettext
1415
_ = gettext.gettext
@@ -43,7 +44,7 @@ def __init__( self, parent ):
4344

4445
bSizerCategories.Add( ( 0, 0), 1, wx.EXPAND, 5 )
4546

46-
self.m_bitmapLogo = wx.StaticBitmap( self.m_panelCategories, wx.ID_ANY, wx.Bitmap( u"logo.png", wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, 0 )
47+
self.m_bitmapLogo = wx.StaticBitmap( self.m_panelCategories, wx.ID_ANY, wx.Bitmap( os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\MathCAT\\globalPlugins\\MathCAT\\logo.png", wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, 0 )
4748
bSizerCategories.Add( self.m_bitmapLogo, 0, wx.ALL, 5 )
4849

4950

@@ -242,7 +243,7 @@ def __init__( self, parent ):
242243

243244
bSizer171 = wx.BoxSizer( wx.HORIZONTAL )
244245

245-
self.m_staticTextBrailleHighlights = wx.StaticText( self.m_panelBraille, wx.ID_ANY, _(u"Highlight with dots 7 & 8 the current nav node:"), wx.DefaultPosition, wx.DefaultSize, 0 )
246+
self.m_staticTextBrailleHighlights = wx.StaticText( self.m_panelBraille, wx.ID_ANY, _(u"Highlight with dots 7 && 8 the current nav node:"), wx.DefaultPosition, wx.DefaultSize, 0 )
246247
self.m_staticTextBrailleHighlights.Wrap( -1 )
247248

248249
bSizer171.Add( self.m_staticTextBrailleHighlights, 0, wx.ALL, 5 )

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,10 @@ def _setSpeechLanguage(self, mathMl):
314314
class GlobalPlugin(globalPluginHandler.GlobalPlugin):
315315
def __init__(self, *args, **kwargs):
316316
super().__init__(*args, **kwargs)
317-
MathCAT.__init__(self)
318-
log.info("about to call add_MathCAT_menu\n")
317+
# MathCAT.__init__(self)
319318
self.add_MathCAT_menu()
320319

321320
def add_MathCAT_menu(self):
322-
log.info("in add_MathCAT_menu\n")
323321
self.toolsMenu = mainFrame.sysTrayIcon.toolsMenu
324322
self.settings = self.toolsMenu.Append(wx.ID_ANY, _("&MathCAT Settings..."))
325323
mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.on_settings, self.settings)
@@ -328,7 +326,6 @@ def on_settings(self, evt):
328326
mainFrame._popupSettingsDialog(UserInterface)
329327

330328
def terminate(self):
331-
log.info("======== in terminate (remove settings menu\n")
332329
try:
333330
self.toolsMenu.Remove(self.settings)
334331
except (AttributeError, RuntimeError):

NVDA-addon/buildVars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def _(arg):
1616
# Add-on information variables
1717
addon_info = {
1818
# add-on Name/identifier, internal for NVDA
19-
"addon_name": "mathCAT",
19+
"addon_name": "MathCAT",
2020
# Add-on summary, usually the user visible name of the addon.
2121
# Translators: Summary for this add-on
2222
# to be shown on installation and add-on information found in Add-ons Manager.

build-addon.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ cargo build --target i686-pc-windows-msvc --release
55

66
cp target/i686-pc-windows-msvc/release/libmathcat_py.dll NVDA-addon/addon/globalPlugins/MathCAT/libmathcat.pyd
77
cd NVDA-addon
8-
rm mathCAT-*.nvda-addon
8+
rm MathCAT-*.nvda-addon
99
scons
1010

0 commit comments

Comments
 (0)