2727Braille_BrailleNavHighlight = ("Off" , "FirstChar" , "EndPoints" , "All" )
2828Braille_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
6931class 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 ):
0 commit comments