88import gettext
99_ = gettext .gettext
1010
11+ from logHandler import log # logging
12+
1113# initialize the user preferences tuples
1214user_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-
4442def 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
6361def 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
7169class 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+
0 commit comments