Skip to content

Commit 627fc0e

Browse files
committed
Added support for zipped up directories and finding speech style files in them
Added `DecimalSeparator` support
1 parent 91cbe0d commit 627fc0e

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

addon/globalPlugins/MathCAT/MathCATPreferences.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from typing import List, Dict, Union
1414
from .MathCAT import ConvertSSMLTextForNVDA
1515
from speech import speak
16+
from zipfile import ZipFile
1617

1718
addonHandler.initTranslation()
1819
_ = gettext.gettext
@@ -25,6 +26,7 @@
2526
# initialize the user preferences tuples
2627
user_preferences: Dict[str, Dict[str, Union[int, str, bool]]] = {}
2728
# Speech_Language is derived from the folder structures
29+
Speech_DecimalSeparator = ("Auto", ".", ",", "Custom")
2830
Speech_Impairment = ("LearningDisability", "Blindness", "LowVision")
2931
# Speech_SpeechStyle is derived from the yaml files under the selected language
3032
Speech_Verbosity = ("Terse", "Medium", "Verbose")
@@ -329,13 +331,18 @@ def GetSpeechStyles(self, this_SpeechStyle: str):
329331
# FIX: when dialog is aware of regional dialects, remove this next line that removes the dialect part
330332
this_language_code = this_language_code.split("-")[0] # grab the first part
331333

332-
this_path = (
334+
this_language_path = (
333335
os.path.expanduser("~")
334336
+ "\\AppData\\Roaming\\nvda\\addons\\MathCAT\\globalPlugins\\MathCAT\\Rules\\Languages\\"
335337
+ this_language_code
336-
+ "\\*_Rules.yaml"
337338
)
339+
this_path = this_language_path + "\\*_Rules.yaml"
338340
# populate the m_choiceSpeechStyle choices
341+
all_style_files = glob.glob(this_path) # works for unzipped dirs
342+
if len(all_style_files) == 0:
343+
# look in the .zip file for the style files
344+
zip_file = ZipFile(f"{this_language_path}\\{this_language_code}.zip", "r")
345+
all_style_files = [name for name in zip_file.namelist() if name.endswith('.jpg')]
339346
for f in glob.glob(this_path):
340347
fname = os.path.basename(f)
341348
self.m_choiceSpeechStyle.Append((fname[: fname.find("_Rules.yaml")]))
@@ -389,6 +396,7 @@ def set_ui_values(self):
389396
"Error when setting SpeechStyle for " + self.m_choiceLanguage.GetStringSelection()
390397
)
391398
# set the rest of the UI elements
399+
self.m_choiceDecimalSeparator.SetSelection(Speech_DecimalSeparator.index(user_preferences["Other"]["DecimalSeparator"]))
392400
self.m_choiceSpeechAmount.SetSelection(Speech_Verbosity.index(user_preferences["Speech"]["Verbosity"]))
393401
self.m_sliderRelativeSpeed.SetValue(user_preferences["Speech"]["MathRate"])
394402
pause_factor = (
@@ -445,6 +453,7 @@ def get_ui_values(self):
445453
# read the values from the UI and update the user preferences dictionary
446454
user_preferences["Speech"]["Impairment"] = Speech_Impairment[self.m_choiceImpairment.GetSelection()]
447455
user_preferences["Speech"]["Language"] = self.GetLanguageCode()
456+
user_preferences["Other"]["DecimalSeparator"] = Speech_DecimalSeparator[self.m_choiceDecimalSeparator.GetSelection()]
448457
user_preferences["Speech"]["SpeechStyle"] = self.m_choiceSpeechStyle.GetStringSelection()
449458
user_preferences["Speech"]["Verbosity"] = Speech_Verbosity[self.m_choiceSpeechAmount.GetSelection()]
450459
user_preferences["Speech"]["MathRate"] = self.m_sliderRelativeSpeed.GetValue()

addon/globalPlugins/MathCAT/MathCATgui.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,46 @@ def __init__(self, parent):
167167

168168
bSizerSpeech.Add(bSizerLanguage, 1, wx.EXPAND, 5)
169169

170+
bSizerDecimalSeparator = wx.BoxSizer(wx.HORIZONTAL)
171+
172+
self.m_staticTextDecimalSeparator = wx.StaticText(
173+
self.m_panelSpeech,
174+
wx.ID_ANY,
175+
# Translators: label for pull down to specify what character to use in numbers as the decimal separator
176+
_("Decimal separator for numbers:"),
177+
wx.DefaultPosition,
178+
wx.DefaultSize,
179+
0,
180+
)
181+
self.m_staticTextDecimalSeparator.Wrap(-1)
182+
183+
bSizerDecimalSeparator.Add(self.m_staticTextDecimalSeparator, 0, wx.ALL, 5)
184+
185+
# Translators: options for decimal separator.
186+
m_choiceDecimalSeparatorChoices = [
187+
# Translators: options for decimal separator -- "Auto" = automatically pick the choice based on the language
188+
_("Auto"),
189+
# options for decimal separator -- use "." (and use ", " for block separators)
190+
("."),
191+
# options for decimal separator -- use "," (and use ". " for block separators)
192+
(","),
193+
# Translators: options for decimal separator -- "Custom" = user sets it
194+
# Currently there is no UI for how it is done yet, but eventually there will be a dialog that pops up to set it
195+
_("Custom"),
196+
]
197+
self.m_choiceDecimalSeparator = wx.Choice(
198+
self.m_panelSpeech,
199+
wx.ID_ANY,
200+
wx.DefaultPosition,
201+
wx.DefaultSize,
202+
m_choiceDecimalSeparatorChoices,
203+
0,
204+
)
205+
self.m_choiceDecimalSeparator.SetSelection(0)
206+
bSizerDecimalSeparator.Add(self.m_choiceDecimalSeparator, 0, wx.ALL, 5)
207+
208+
bSizerSpeech.Add(bSizerDecimalSeparator, 1, wx.EXPAND, 5)
209+
170210
bSizerSpeechStyle = wx.BoxSizer(wx.HORIZONTAL)
171211

172212
self.m_staticTextSpeechStyle = wx.StaticText(

0 commit comments

Comments
 (0)