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 ()) 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 , f )
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 )
@@ -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 ()
0 commit comments