|
13 | 13 | from typing import List, Dict, Union |
14 | 14 | from .MathCAT import ConvertSSMLTextForNVDA |
15 | 15 | from speech import speak |
| 16 | +from zipfile import ZipFile |
16 | 17 |
|
17 | 18 | addonHandler.initTranslation() |
18 | 19 | _ = gettext.gettext |
|
25 | 26 | # initialize the user preferences tuples |
26 | 27 | user_preferences: Dict[str, Dict[str, Union[int, str, bool]]] = {} |
27 | 28 | # Speech_Language is derived from the folder structures |
| 29 | +Speech_DecimalSeparator = ("Auto", ".", ",", "Custom") |
28 | 30 | Speech_Impairment = ("LearningDisability", "Blindness", "LowVision") |
29 | 31 | # Speech_SpeechStyle is derived from the yaml files under the selected language |
30 | 32 | Speech_Verbosity = ("Terse", "Medium", "Verbose") |
@@ -329,13 +331,18 @@ def GetSpeechStyles(self, this_SpeechStyle: str): |
329 | 331 | # FIX: when dialog is aware of regional dialects, remove this next line that removes the dialect part |
330 | 332 | this_language_code = this_language_code.split("-")[0] # grab the first part |
331 | 333 |
|
332 | | - this_path = ( |
| 334 | + this_language_path = ( |
333 | 335 | os.path.expanduser("~") |
334 | 336 | + "\\AppData\\Roaming\\nvda\\addons\\MathCAT\\globalPlugins\\MathCAT\\Rules\\Languages\\" |
335 | 337 | + this_language_code |
336 | | - + "\\*_Rules.yaml" |
337 | 338 | ) |
| 339 | + this_path = this_language_path + "\\*_Rules.yaml" |
338 | 340 | # 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')] |
339 | 346 | for f in glob.glob(this_path): |
340 | 347 | fname = os.path.basename(f) |
341 | 348 | self.m_choiceSpeechStyle.Append((fname[: fname.find("_Rules.yaml")])) |
@@ -389,6 +396,7 @@ def set_ui_values(self): |
389 | 396 | "Error when setting SpeechStyle for " + self.m_choiceLanguage.GetStringSelection() |
390 | 397 | ) |
391 | 398 | # set the rest of the UI elements |
| 399 | + self.m_choiceDecimalSeparator.SetSelection(Speech_DecimalSeparator.index(user_preferences["Other"]["DecimalSeparator"])) |
392 | 400 | self.m_choiceSpeechAmount.SetSelection(Speech_Verbosity.index(user_preferences["Speech"]["Verbosity"])) |
393 | 401 | self.m_sliderRelativeSpeed.SetValue(user_preferences["Speech"]["MathRate"]) |
394 | 402 | pause_factor = ( |
@@ -445,6 +453,7 @@ def get_ui_values(self): |
445 | 453 | # read the values from the UI and update the user preferences dictionary |
446 | 454 | user_preferences["Speech"]["Impairment"] = Speech_Impairment[self.m_choiceImpairment.GetSelection()] |
447 | 455 | user_preferences["Speech"]["Language"] = self.GetLanguageCode() |
| 456 | + user_preferences["Other"]["DecimalSeparator"] = Speech_DecimalSeparator[self.m_choiceDecimalSeparator.GetSelection()] |
448 | 457 | user_preferences["Speech"]["SpeechStyle"] = self.m_choiceSpeechStyle.GetStringSelection() |
449 | 458 | user_preferences["Speech"]["Verbosity"] = Speech_Verbosity[self.m_choiceSpeechAmount.GetSelection()] |
450 | 459 | user_preferences["Speech"]["MathRate"] = self.m_sliderRelativeSpeed.GetValue() |
|
0 commit comments