Skip to content

Commit 9bb7580

Browse files
committed
Changed dialog SpeechStyle getter for when lang is 'Auto' -- rather than not setting the speech style, it uses the current language's speech style. That style might get to be invalid later on, but MathCAT will pick something in the changed language if it isn't valid.
A few more lint fixes
1 parent c3dd50d commit 9bb7580

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

addon/globalPlugins/MathCAT/MathCAT.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
from ctypes import windll # register clipboard formats
3434
from typing import Any, Optional
35+
from speech import getCurrentLanguage
3536

3637
from . import libmathcat
3738

@@ -71,7 +72,7 @@
7172
RE_MATH_LANG = re.compile(r'''<math .*(xml:)?lang=["']([^'"]+)["'].*>''')
7273
def getLanguageToUse(mathMl:str) -> str:
7374
"""Get the language specified in a math tag if the language pref is Auto, else the language preference."""
74-
mathCATLanguageSetting = "Auto"
75+
mathCATLanguageSetting = 'Auto'
7576
try:
7677
# ignore regional differences if the MathCAT language setting doesn't have it.
7778
mathCATLanguageSetting = libmathcat.GetPreference("Language")
@@ -82,7 +83,7 @@ def getLanguageToUse(mathMl:str) -> str:
8283
return mathCATLanguageSetting
8384

8485
languageMatch = RE_MATH_LANG.search(mathMl)
85-
language = languageMatch.group(2) if languageMatch else speech.getCurrentLanguage() # seems to be current voice's language
86+
language = languageMatch.group(2) if languageMatch else getCurrentLanguage() # seems to be current voice's language
8687
language = language.lower().replace("_", "-")
8788
return language
8889

addon/globalPlugins/MathCAT/MathCATPreferences.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ def GetLanguages(self):
249249
languages_dict = UserInterface.LanguagesDict()
250250
#clear the language names in the dialog
251251
self.m_choiceLanguage.Clear()
252-
#populate the available language names in the dialog
253252
self.m_choiceLanguage.Append(_("Use Voice's Language") + " (Auto)")
253+
#populate the available language names in the dialog
254254
for f in os.listdir(UserInterface.path_to_languages_folder()):
255-
if os.path.isdir(UserInterface.path_to_languages_folder()+"\\"+f):
256-
if languages_dict.get(f, 'missing') == 'missing':
257-
self.m_choiceLanguage.Append(f + " (" + f + ")")
258-
else:
255+
if os.path.isdir(UserInterface.path_to_languages_folder()+"\\"+f):
256+
if languages_dict.get(f, 'missing') == 'missing':
257+
self.m_choiceLanguage.Append(f + " (" + f + ")")
258+
else:
259259
self.m_choiceLanguage.Append(languages_dict[f] + " (" + f + ")")
260260

261261
def GetLanguageCode(self):
@@ -264,10 +264,18 @@ def GetLanguageCode(self):
264264
return lang_code
265265

266266
def GetSpeechStyles(self, this_SpeechStyle: str):
267+
from speech import getCurrentLanguage
267268
#clear the SpeechStyle choices
268269
self.m_choiceSpeechStyle.Clear()
269270
#get the currently selected language code
270271
this_language_code = UserInterface.GetLanguageCode(self)
272+
log.info(f"\nthis lang={this_language_code}, getCurrentLanguage = {getCurrentLanguage()}")
273+
274+
if this_language_code == 'Auto':
275+
# list the speech styles for the current voice rather than have none listed
276+
this_language_code = getCurrentLanguage().lower().replace("_", "-")
277+
# FIX: when dialog is aware of regional dialects, remove this next line that removes the dialect part
278+
this_language_code = this_language_code.split('-')[0] # grab the first part
271279

272280
this_path = os.path.expanduser('~')+"\\AppData\\Roaming\\nvda\\addons\\MathCAT\\globalPlugins\\MathCAT\\Rules\\Languages\\"+this_language_code+"\\*_Rules.yaml"
273281
#populate the m_choiceSpeechStyle choices

0 commit comments

Comments
 (0)