Skip to content

Commit f743a35

Browse files
authored
Merge branch 'main' into dePickle
2 parents 6abcf38 + 333d3db commit f743a35

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import gettext
99
_ = gettext.gettext
1010

11+
from logHandler import log # logging
12+
1113
# initialize the user preferences tuples
1214
user_preferences = dict([("", "")])
1315
#Speech_Language is derived from the folder structure
@@ -37,10 +39,6 @@ def path_to_user_preferences():
3739
#the user preferences file is stored at: C:\Users\<user-name>AppData\Roaming\MathCAT\prefs.yaml
3840
return path_to_user_preferences_folder() + "\\prefs.yaml"
3941

40-
def path_to_languages_folder():
41-
#the user preferences file is stored at: MathCAT\Rules\Languages
42-
return os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\mathCAT\\globalPlugins\\MathCAT\\Rules\\Languages"
43-
4442
def load_default_preferences():
4543
global user_preferences
4644
#load default preferences into the user preferences data structure (overwrites existing)
@@ -58,7 +56,7 @@ def load_user_preferences():
5856
if os.path.exists(path_to_user_preferences()):
5957
with open(path_to_user_preferences(), encoding='utf-8') as f:
6058
# merge with the default preferences, overwriting with the user's values
61-
user_preferences |= yaml.load(f, Loader=yaml.FullLoader)
59+
user_preferences.update(yaml.load(f, Loader=yaml.FullLoader))
6260

6361
def write_user_preferences():
6462
if not os.path.exists(path_to_user_preferences_folder()):
@@ -69,6 +67,7 @@ def write_user_preferences():
6967
yaml.dump(user_preferences, stream=f, allow_unicode=True)
7068

7169
class UserInterface(MathCATgui.MathCATPreferencesDialog):
70+
7271
def GetLanguages(self):
7372
#clear the language choices
7473
self.m_choiceLanguage.Clear()
@@ -82,7 +81,7 @@ def GetSpeechStyles(self, this_SpeechStyle):
8281
self.m_choiceSpeechStyle.Clear()
8382
#get the currently selected language
8483
this_language = self.m_choiceLanguage.GetStringSelection()
85-
this_path = path_to_languages_folder()+"\\"+this_language+"\\*_Rules.yaml"
84+
this_path = os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\mathCAT\\globalPlugins\\MathCAT\\Rules\\Languages\\"+this_language+"\\*_Rules.yaml"
8685
#populate the m_choiceSpeechStyle choices
8786
for f in glob.glob(this_path):
8887
fname = os.path.basename(f)
@@ -147,6 +146,11 @@ def get_ui_values(self):
147146
def __init__(self,parent):
148147
#initialize parent class
149148
MathCATgui.MathCATPreferencesDialog.__init__(self,parent)
149+
150+
# load in the system values followed by the user prefs (if any)
151+
load_default_preferences()
152+
load_user_preferences()
153+
150154
if "MathCATPreferencesLastCategory" in user_preferences:
151155
#set the categories selection to what we used on last run
152156
self.m_listBoxPreferencesTopic.SetSelection(user_preferences["MathCATPreferencesLastCategory"])
@@ -164,10 +168,10 @@ def __init__(self,parent):
164168
def OnClickOK(self,event):
165169
UserInterface.get_ui_values(self)
166170
write_user_preferences()
167-
app.ExitMainLoop()
171+
self.Destroy()
168172

169173
def OnClickCancel(self,event):
170-
app.ExitMainLoop()
174+
self.Destroy()
171175

172176
def OnClickApply(self,event):
173177
UserInterface.get_ui_values(self)
@@ -220,13 +224,4 @@ def MathCATPreferencesDialogOnCharHook(self,event):
220224
self.m_listBoxPreferencesTopic.SetFocus()
221225
#jump out so the tab key is not processed
222226
return
223-
event.Skip()
224-
225-
app = wx.App(False)
226-
#get the default preferences (we don't write to this file)
227-
load_default_preferences()
228-
#having grabbed the default values, let's see if there is a preferences file for this user
229-
load_user_preferences()
230-
frame = UserInterface(None)
231-
frame.Show(True)
232-
app.MainLoop()
227+

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
from synthDriverHandler import getSynth # speech engine param setting
2525
import winUser # clipboard manipultation
2626
from ctypes import windll # register clipboard formats
27+
from gui import mainFrame
28+
import wx
2729

2830
from . import libmathcat
2931

@@ -170,7 +172,7 @@ def script_navigate(self, gesture):
170172
except Exception as e:
171173
log.error(e)
172174

173-
_startsWithMath = re.compile("\s*?<math")
175+
_startsWithMath = re.compile("\\s*?<math")
174176
@script(
175177
gesture="kb:control+c",
176178
)
@@ -203,10 +205,9 @@ def _copyToClipAsMathML(self, text: str, notify: Optional[bool] = False) -> bool
203205
# copied from api.py and modified to use CF_MathML_Presentation
204206
if not isinstance(text, str) or len(text) == 0:
205207
return False
206-
import gui
207208
from api import getClipData
208209
try:
209-
with winUser.openClipboard(gui.mainFrame.Handle):
210+
with winUser.openClipboard(mainFrame.Handle):
210211
winUser.emptyClipboard()
211212
self._setClipboardData(self.CF_MathML, self._wrapMathMLForClipBoard(text))
212213
self._setClipboardData(self.CF_MathML_Presentation, self._wrapMathMLForClipBoard(text))
@@ -247,7 +248,7 @@ def _setClipboardData(self, format,data):
247248
# NULL the global memory handle so that it is not freed at the end of scope as the clipboard now has it.
248249
h.forget()
249250

250-
251+
from .MathCATPreferences import UserInterface
251252
class MathCAT(mathPres.MathPresentationProvider):
252253
def __init__(self):
253254
# super(MathCAT, self).__init__(*args, **kwargs)
@@ -305,7 +306,7 @@ def _setSpeechLanguage(self, mathMl):
305306
libmathcat.SetPreference("Language", lang.replace("_", "-"))
306307
self._language = lang
307308
except Exception as e:
308-
log.error(e)
309+
log.error(e)
309310

310311

311312
mathPres.registerProvider(MathCAT(), speech=True, braille=True, interaction=True)
@@ -314,3 +315,22 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
314315
def __init__(self, *args, **kwargs):
315316
super().__init__(*args, **kwargs)
316317
MathCAT.__init__(self)
318+
log.info("about to call add_MathCAT_menu\n")
319+
self.add_MathCAT_menu()
320+
321+
def add_MathCAT_menu(self):
322+
log.info("in add_MathCAT_menu\n")
323+
self.toolsMenu = mainFrame.sysTrayIcon.toolsMenu
324+
self.settings = self.toolsMenu.Append(wx.ID_ANY, _("&MathCAT Settings..."))
325+
mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.on_settings, self.settings)
326+
327+
def on_settings(self, evt):
328+
mainFrame._popupSettingsDialog(UserInterface)
329+
330+
def terminate(self):
331+
log.info("======== in terminate (remove settings menu\n")
332+
try:
333+
self.toolsMenu.Remove(self.settings)
334+
except (AttributeError, RuntimeError):
335+
pass
336+

NVDA-addon/buildVars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _(arg):
2929
The initial version of MathCAT is English-only but is designed with translations in mind.
3030
"""),
3131
# version
32-
"addon_version": "0.1.5",
32+
"addon_version": "0.1.6",
3333
# Author(s)
3434
"addon_author": "Neil Soiffer <soiffer@alum.mit.edu>",
3535
# URL for the add-on documentation support

0 commit comments

Comments
 (0)