Skip to content

Commit 689cf9c

Browse files
committed
Support Languages and SpeechStyles from folder structure
1 parent 4573941 commit 689cf9c

File tree

7 files changed

+79
-30
lines changed

7 files changed

+79
-30
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Version": 1,
3+
"ProjectMap": {
4+
"a2fe74e1-b743-11d0-ae1a-00a0c90fffc3": {
5+
"ProjectGuid": "a2fe74e1-b743-11d0-ae1a-00a0c90fffc3",
6+
"DisplayName": "Miscellaneous Files",
7+
"ColorIndex": -1
8+
}
9+
},
10+
"NextColorIndex": 0
11+
}

.vs/MathCATForPython/v17/.suo

6.5 KB
Binary file not shown.

.vs/PythonSettings.json

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

.vs/VSWorkspaceState.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"ExpandedNodes": [
3+
"",
4+
"\\NVDA-addon",
5+
"\\NVDA-addon\\addon",
6+
"\\NVDA-addon\\addon\\globalPlugins",
7+
"\\NVDA-addon\\addon\\globalPlugins\\MathCAT"
8+
],
9+
"SelectedNode": "\\NVDA-addon\\addon\\globalPlugins\\MathCAT\\MathCATPreferences.py",
10+
"PreviewInSolutionExplorer": false
11+
}

.vs/slnx.sqlite

0 Bytes
Binary file not shown.

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

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22
import MathCATgui
33
import yaml
44
import os
5+
import glob
56
import sys
67
import webbrowser
78
import gettext
89
_ = gettext.gettext
910

10-
#initialize the languages dictionary
11-
Speech_Language = { "en": "English : en"}
12-
1311
# initialize the user preferences tuples
1412
user_preferences = dict([("", "")])
13+
#Sepech_Language is derived from the folder structure
1514
Speech_Impairment = ("LearningDisability", "Blindness", "LowVision")
15+
#Speech_SpeechStyle is derived from the yaml files under the selected language
1616
Speech_Verbosity = ("Terse", "Medium", "Verbose")
17-
Speech_SpeechStyle = ("ClearSpeak", "SimpleSpeak")
1817
Speech_SubjectArea = ("General")
1918
Speech_Chemistry = ("SpellOut", "AsCompound", "Off")
20-
2119
Navigation_NavMode = ("Enhanced", "Simple", "Character")
2220
#Navigation_ResetNavMode is boolean
2321
#Navigation_OverView is boolean
@@ -29,21 +27,21 @@
2927

3028
def path_to_default_preferences():
3129
#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";
30+
return os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\mathCAT\\globalPlugins\\MathCAT\\Rules\\prefs.yaml"
3331

3432
def path_to_user_preferences_folder():
3533
#the user preferences file is stored at: C:\Users\<user-name>AppData\Roaming\MathCAT\prefs.yaml
36-
return os.path.expanduser('~')+"\\AppData\\Roaming\\MathCAT";
34+
return os.path.expanduser('~')+"\\AppData\\Roaming\\MathCAT"
3735

3836
def path_to_user_preferences():
3937
#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";
38+
return path_to_user_preferences_folder() + "\\prefs.yaml"
4139

4240
def load_default_preferences():
4341
global user_preferences
4442
#load default preferences into the user preferences data structure (overwites existing)
4543
if os.path.exists(path_to_default_preferences()):
46-
with open(path_to_default_preferences()) as f:
44+
with open(path_to_default_preferences(), encoding='utf-8') as f:
4745
user_preferences = yaml.load(f, Loader=yaml.FullLoader)
4846
else:
4947
#default preferences file is NOT found
@@ -66,20 +64,44 @@ def write_user_preferences():
6664
#write values to the user preferences file, NOT the default
6765
yaml.dump(user_preferences, f)
6866

69-
def GetKey(val):
70-
for key, value in Speech_Language.items():
71-
if val == value:
72-
return key
73-
return "en"
74-
7567
class UserInterface(MathCATgui.MathCATPreferencesDialog):
7668

69+
def GetLanguages(self):
70+
#clear the language choices
71+
self.m_choiceLanguage.Clear()
72+
#populate the language choices
73+
for f in os.listdir(os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\mathCAT\\globalPlugins\\MathCAT\\Rules\\Languages"):
74+
if os.path.isdir(os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\mathCAT\\globalPlugins\\MathCAT\\Rules\\Languages\\"+f):
75+
self.m_choiceLanguage.Append(f)
76+
77+
def GetSpeechStyles(self, this_SpeechStyle):
78+
#clear the SpeechStyle choices
79+
self.m_choiceSpeechStyle.Clear()
80+
#get the currently selected language
81+
this_language = self.m_choiceLanguage.GetStringSelection()
82+
this_path = os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\mathCAT\\globalPlugins\\MathCAT\\Rules\\Languages\\"+this_language+"\\*_Rules.yaml"
83+
#populate the m_choiceSpeechStyle choices
84+
for f in glob.glob(this_path):
85+
fname = os.path.basename(f)
86+
self.m_choiceSpeechStyle.Append((fname[:fname.find("_Rules.yaml")]))
87+
try:
88+
#set the SpeechStyle to the same as previous
89+
self.m_choiceSpeechStyle.SetStringSelection(this_SpeechStyle)
90+
except:
91+
#that didn't work, choose the first in the list
92+
self.m_choiceSpeechStyle.SetSelection(0)
93+
7794
def set_ui_values(self):
7895
#set the UI elements to the ones read from the preference file(s)
7996
try:
8097
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"]))
98+
try:
99+
self.m_choiceLanguage.SetStringSelection(user_preferences["Speech"]["Language"])
100+
except:
101+
#the language in the settings file is not in the folder structure, something went wrong, set to the first in the list
102+
self.m_choiceLanguage.SetSelection(0)
103+
#now get the available SpeechStyles from the folder structure and set to the preference setting is possible
104+
UserInterface.GetSpeechStyles(self, user_preferences["Speech"]["SpeechStyle"])
83105
self.m_choiceSpeechAmount.SetSelection(Speech_Verbosity.index(user_preferences["Speech"]["Verbosity"]))
84106
self.m_choiceSpeechForChemical.SetSelection(Speech_Chemistry.index(user_preferences["Speech"]["Chemistry"]))
85107
self.m_choiceNavigationMode.SetSelection(Navigation_NavMode.index(user_preferences["Navigation"]["NavMode"]))
@@ -100,8 +122,8 @@ def get_ui_values(self):
100122
global user_preferences
101123
# read the values from the UI and update the user preferences dictionary
102124
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()]
125+
user_preferences["Speech"]["Language"] = self.m_choiceLanguage.GetStringSelection()
126+
user_preferences["Speech"]["SpeechStyle"] = self.m_choiceSpeechStyle.GetStringSelection()
105127
user_preferences["Speech"]["Verbosity"] = Speech_Verbosity[self.m_choiceSpeechAmount.GetSelection()]
106128
user_preferences["Speech"]["Chemistry"] = Speech_Chemistry[self.m_choiceSpeechForChemical.GetSelection()]
107129
user_preferences["Navigation"]["NavMode"] = Navigation_NavMode[self.m_choiceNavigationMode.GetSelection()]
@@ -129,15 +151,9 @@ def __init__(self,parent):
129151
#set the categories selection to the first item
130152
self.m_listBoxPreferencesTopic.SetSelection(0)
131153
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-
154+
#populate the languages
155+
UserInterface.GetLanguages(self)
156+
#set the ui items to match the preferences
141157
UserInterface.set_ui_values(self)
142158

143159
def OnClickOK(self,event):
@@ -160,9 +176,13 @@ def OnClickHelp(self,event):
160176
webbrowser.open('https://nsoiffer.github.io/MathCAT/users.html')
161177

162178
def OnListBoxCategories(self,event):
163-
#show the appropriate dialogue page
179+
#the category changed, now show the appropriate dialogue page
164180
self.m_simplebookPanelsCategories.SetSelection(self.m_listBoxPreferencesTopic.GetSelection())
165181

182+
def OnLanguage(self,event):
183+
#the language changed, get the SpeechStyles for the new language
184+
UserInterface.GetSpeechStyles(self, self.m_choiceSpeechStyle.GetSelection())
185+
166186
def MathCATPreferencesDialogOnCharHook(self,event):
167187
#designed choice is that Enter is the same as clicking OK, and Escape is the same as clicking Cancel
168188
keyCode = event.GetKeyCode()

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __init__( self, parent ):
9393

9494
bSizer713.Add( self.m_staticText2111, 0, wx.ALL, 5 )
9595

96-
m_choiceSpeechStyleChoices = [ _(u"ClearSpeakxxxxxx") ]
96+
m_choiceSpeechStyleChoices = [ _(u"xxxxxxxxxxxxxxxx") ]
9797
self.m_choiceSpeechStyle = wx.Choice( self.m_panelSpeech, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, m_choiceSpeechStyleChoices, 0 )
9898
self.m_choiceSpeechStyle.SetSelection( 0 )
9999
bSizer713.Add( self.m_choiceSpeechStyle, 0, wx.ALL, 5 )
@@ -311,6 +311,7 @@ def __init__( self, parent ):
311311
self.Bind( wx.EVT_CHAR_HOOK, self.MathCATPreferencesDialogOnCharHook )
312312
self.Bind( wx.EVT_KEY_UP, self.MathCATPreferencesDialogOnKeyUp )
313313
self.m_listBoxPreferencesTopic.Bind( wx.EVT_LISTBOX, self.OnListBoxCategories )
314+
self.m_choiceLanguage.Bind( wx.EVT_CHOICE, self.OnLanguage )
314315
self.m_buttonOK.Bind( wx.EVT_BUTTON, self.OnClickOK )
315316
self.m_buttonCancel.Bind( wx.EVT_BUTTON, self.OnClickCancel )
316317
self.m_buttonApply.Bind( wx.EVT_BUTTON, self.OnClickApply )
@@ -331,6 +332,9 @@ def MathCATPreferencesDialogOnKeyUp( self, event ):
331332
def OnListBoxCategories( self, event ):
332333
event.Skip()
333334

335+
def OnLanguage( self, event ):
336+
event.Skip()
337+
334338
def OnClickOK( self, event ):
335339
event.Skip()
336340

0 commit comments

Comments
 (0)