Skip to content

Commit 333d3db

Browse files
committed
MathCAT settings dialog now works with NVDA.
The only remaining problem is that it is not finding the logo.
1 parent 98fd9de commit 333d3db

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

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

Lines changed: 12 additions & 19 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()) 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, f)
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)
@@ -145,6 +144,11 @@ def get_ui_values(self):
145144
def __init__(self,parent):
146145
#initialize parent class
147146
MathCATgui.MathCATPreferencesDialog.__init__(self,parent)
147+
148+
# load in the system values followed by the user prefs (if any)
149+
load_default_preferences()
150+
load_user_preferences()
151+
148152
if "MathCATPreferencesLastCategory" in user_preferences:
149153
#set the categories selection to what we used on last run
150154
self.m_listBoxPreferencesTopic.SetSelection(user_preferences["MathCATPreferencesLastCategory"])
@@ -162,10 +166,10 @@ def __init__(self,parent):
162166
def OnClickOK(self,event):
163167
UserInterface.get_ui_values(self)
164168
write_user_preferences()
165-
app.ExitMainLoop()
169+
self.Destroy()
166170

167171
def OnClickCancel(self,event):
168-
app.ExitMainLoop()
172+
self.Destroy()
169173

170174
def OnClickApply(self,event):
171175
UserInterface.get_ui_values(self)
@@ -193,15 +197,4 @@ def MathCATPreferencesDialogOnCharHook(self,event):
193197
UserInterface.OnClickCancel(self,event)
194198
if keyCode == wx.WXK_RETURN:
195199
UserInterface.OnClickOK(self,event)
196-
#if keyCode == wx.WXK_TAB and wx.KeyboardState.GetModifiers():
197-
# print("Tab")
198200
event.Skip()
199-
200-
app = wx.App(False)
201-
#get the default preferences (we don't write to this file)
202-
load_default_preferences()
203-
#having grabbed the default values, let's see if there is a preferences file for this user
204-
load_user_preferences()
205-
frame = UserInterface(None)
206-
frame.Show(True)
207-
app.MainLoop()

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+

0 commit comments

Comments
 (0)