Skip to content

Commit 1de5244

Browse files
committed
Merge branch 'main' of github.com:NSoiffer/MathCATForPython
2 parents 5f6c919 + 4573941 commit 1de5244

File tree

5 files changed

+534
-0
lines changed

5 files changed

+534
-0
lines changed

.vs/MathCATForPython/v17/.suo

26.5 KB
Binary file not shown.

.vs/ProjectSettings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"CurrentProjectSetting": null
3+
}

.vs/slnx.sqlite

96 KB
Binary file not shown.
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import wx
2+
import MathCATgui
3+
import yaml
4+
import os
5+
import sys
6+
import webbrowser
7+
import gettext
8+
_ = gettext.gettext
9+
10+
#initialize the languages dictionary
11+
Speech_Language = { "en": "English : en"}
12+
13+
# initialize the user preferences tuples
14+
user_preferences = dict([("", "")])
15+
Speech_Impairment = ("LearningDisability", "Blindness", "LowVision")
16+
Speech_Verbosity = ("Terse", "Medium", "Verbose")
17+
Speech_SpeechStyle = ("ClearSpeak", "SimpleSpeak")
18+
Speech_SubjectArea = ("General")
19+
Speech_Chemistry = ("SpellOut", "AsCompound", "Off")
20+
21+
Navigation_NavMode = ("Enhanced", "Simple", "Character")
22+
#Navigation_ResetNavMode is boolean
23+
#Navigation_OverView is boolean
24+
Navigation_NavVerbosity = ("Terse", "Medium", "Verbose")
25+
#Navigation_AutoZoomOut is boolean
26+
27+
Braille_BrailleNavHighlight = ("Off", "FirstChar", "EndPoints", "All")
28+
Braille_BrailleCode = ("Nemeth", "UEB")
29+
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 (overwites existing)
45+
if os.path.exists(path_to_default_preferences()):
46+
with open(path_to_default_preferences()) 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()) as f:
58+
# merge with the default preferences, overwriting with the user's values
59+
user_preferences |= 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') as f:
66+
#write values to the user preferences file, NOT the default
67+
yaml.dump(user_preferences, f)
68+
69+
def GetKey(val):
70+
for key, value in Speech_Language.items():
71+
if val == value:
72+
return key
73+
return "en"
74+
75+
class UserInterface(MathCATgui.MathCATPreferencesDialog):
76+
77+
def set_ui_values(self):
78+
#set the UI elements to the ones read from the preference file(s)
79+
try:
80+
self.m_choiceImpairment.SetSelection(Speech_Impairment.index(user_preferences["Speech"]["Impairment"]))
81+
self.m_choiceLanguage.SetStringSelection(Speech_Language[user_preferences["Speech"]["Language"]])
82+
self.m_choiceSpeechStyle.SetSelection(Speech_SpeechStyle.index(user_preferences["Speech"]["SpeechStyle"]))
83+
self.m_choiceSpeechAmount.SetSelection(Speech_Verbosity.index(user_preferences["Speech"]["Verbosity"]))
84+
self.m_choiceSpeechForChemical.SetSelection(Speech_Chemistry.index(user_preferences["Speech"]["Chemistry"]))
85+
self.m_choiceNavigationMode.SetSelection(Navigation_NavMode.index(user_preferences["Navigation"]["NavMode"]))
86+
self.m_checkBoxResetNavigationMode.SetValue(user_preferences["Navigation"]["ResetNavMode"])
87+
self.m_choiceSpeechAmountNavigation.SetSelection(Navigation_NavVerbosity.index(user_preferences["Navigation"]["NavVerbosity"]))
88+
if user_preferences["Navigation"]["Overview"]:
89+
self.m_choiceNavigationSpeech.SetSelection(0)
90+
else:
91+
self.m_choiceNavigationSpeech.SetSelection(1)
92+
self.m_checkBoxResetNavigationSpeech.SetValue(user_preferences["Navigation"]["ResetOverview"])
93+
self.m_checkBoxAutomaticZoom.SetValue(user_preferences["Navigation"]["AutoZoomOut"])
94+
self.m_choiceBrailleHighlights.SetSelection(Braille_BrailleNavHighlight.index(user_preferences["Braille"]["BrailleNavHighlight"]))
95+
self.m_choiceBrailleMathCode.SetSelection(Braille_BrailleCode.index(user_preferences["Braille"]["BrailleCode"]))
96+
except KeyError as err:
97+
print('Key not found')
98+
99+
def get_ui_values(self):
100+
global user_preferences
101+
# read the values from the UI and update the user preferences dictionary
102+
user_preferences["Speech"]["Impairment"] = Speech_Impairment[self.m_choiceImpairment.GetSelection()]
103+
user_preferences["Speech"]["Language"] = GetKey( self.m_choiceLanguage.GetStringSelection())
104+
user_preferences["Speech"]["SpeechStyle"] = Speech_SpeechStyle[self.m_choiceSpeechStyle.GetSelection()]
105+
user_preferences["Speech"]["Verbosity"] = Speech_Verbosity[self.m_choiceSpeechAmount.GetSelection()]
106+
user_preferences["Speech"]["Chemistry"] = Speech_Chemistry[self.m_choiceSpeechForChemical.GetSelection()]
107+
user_preferences["Navigation"]["NavMode"] = Navigation_NavMode[self.m_choiceNavigationMode.GetSelection()]
108+
user_preferences["Navigation"]["ResetNavMode"] = self.m_checkBoxResetNavigationMode.GetValue()
109+
user_preferences["Navigation"]["NavVerbosity"] = Navigation_NavVerbosity[self.m_choiceSpeechAmountNavigation.GetSelection()]
110+
if self.m_choiceNavigationSpeech.GetSelection() == 0:
111+
user_preferences["Navigation"]["Overview"] = True
112+
else:
113+
user_preferences["Navigation"]["Overview"] = False
114+
user_preferences["Navigation"]["ResetOverview"] = self.m_checkBoxResetNavigationSpeech.GetValue()
115+
user_preferences["Navigation"]["AutoZoomOut"] = self.m_checkBoxAutomaticZoom.GetValue()
116+
user_preferences["Braille"]["BrailleNavHighlight"] = Braille_BrailleNavHighlight[self.m_choiceBrailleHighlights.GetSelection()]
117+
user_preferences["Braille"]["BrailleCode"] = Braille_BrailleCode[self.m_choiceBrailleMathCode.GetSelection()]
118+
user_preferences["MathCATPreferencesLastCategory"] = self.m_listBoxPreferencesTopic.GetSelection()
119+
120+
def __init__(self,parent):
121+
#initialize parent class
122+
MathCATgui.MathCATPreferencesDialog.__init__(self,parent)
123+
if "MathCATPreferencesLastCategory" in user_preferences:
124+
#set the categories selection to what we used on last run
125+
self.m_listBoxPreferencesTopic.SetSelection(user_preferences["MathCATPreferencesLastCategory"])
126+
#show the appropriate dialogue page
127+
self.m_simplebookPanelsCategories.SetSelection(self.m_listBoxPreferencesTopic.GetSelection())
128+
else:
129+
#set the categories selection to the first item
130+
self.m_listBoxPreferencesTopic.SetSelection(0)
131+
user_preferences["MathCATPreferencesLastCategory"]="0"
132+
#populate the language choices
133+
self.m_choiceLanguage.Clear()
134+
for lang in Speech_Language.values():
135+
self.m_choiceLanguage.Append(lang)
136+
#populate the SpeechStyle choices
137+
#this will need to be done on change of language
138+
self.m_choiceSpeechStyle.Clear()
139+
self.m_choiceSpeechStyle.Append("ClearSpeak")
140+
141+
UserInterface.set_ui_values(self)
142+
143+
def OnClickOK(self,event):
144+
UserInterface.get_ui_values(self)
145+
write_user_preferences()
146+
app.ExitMainLoop()
147+
148+
def OnClickCancel(self,event):
149+
app.ExitMainLoop()
150+
151+
def OnClickApply(self,event):
152+
UserInterface.get_ui_values(self)
153+
write_user_preferences()
154+
155+
def OnClickReset(self,event):
156+
load_default_preferences()
157+
UserInterface.set_ui_values(self)
158+
159+
def OnClickHelp(self,event):
160+
webbrowser.open('https://nsoiffer.github.io/MathCAT/users.html')
161+
162+
def OnListBoxCategories(self,event):
163+
#show the appropriate dialogue page
164+
self.m_simplebookPanelsCategories.SetSelection(self.m_listBoxPreferencesTopic.GetSelection())
165+
166+
def MathCATPreferencesDialogOnCharHook(self,event):
167+
#designed choice is that Enter is the same as clicking OK, and Escape is the same as clicking Cancel
168+
keyCode = event.GetKeyCode()
169+
if keyCode == wx.WXK_ESCAPE:
170+
UserInterface.OnClickCancel(self,event)
171+
if keyCode == wx.WXK_RETURN:
172+
UserInterface.OnClickOK(self,event)
173+
event.Skip()
174+
175+
app = wx.App(False)
176+
#get the default preferences (we don't write to this file)
177+
load_default_preferences()
178+
#having grabbed the default values, let's see if there is a preferences file for this user
179+
load_user_preferences()
180+
frame = UserInterface(None)
181+
frame.Show(True)
182+
app.MainLoop()

0 commit comments

Comments
 (0)