5
5
# Released under GPL 2.0
6
6
#globalPlugins/enhancedPhoneticReading.py
7
7
8
- import characterProcessing , config , controlTypes , globalPluginHandler , gui , addonHandler , six , speech , textInfos , threading , wx
8
+ import characterProcessing , config , controlTypes , core , globalPluginHandler , gui , addonHandler , six , speech , textInfos , threading , wx
9
9
from globalCommands import SCRCAT_SPEECH
10
10
11
11
addonHandler .initTranslation ()
@@ -43,9 +43,20 @@ def cancelSpeech():
43
43
origCancelSpeech ()
44
44
cancelTimer ()
45
45
46
+ class _FakeTextInfo ():
47
+ """
48
+ this class is used to preserve the information of the old object that contain the text. Its useful to use with delayed descriptions.
49
+ """
50
+
51
+ def __init__ (self , origTextInfo : textInfos .TextInfo ):
52
+ self .text = origTextInfo .text
53
+ self .fields = origTextInfo .getTextWithFields ({})
54
+
55
+ def getTextWithFields (self , _ = None ):
56
+ return self .fields
57
+
46
58
#saves the original speakTextInfo function
47
59
origSpeakTextInfo = speech .speakTextInfo
48
-
49
60
instantDescriptions = False
50
61
# alternate function to speakTextInfo. We determine here if a delayed description is needed base on textInfos.UNIT_CHARACTER.
51
62
def speakTextInfo (* args , ** kwargs ):
@@ -54,18 +65,22 @@ def speakTextInfo(*args, **kwargs):
54
65
if instantDescriptions and kwargs .get ('unit' ) == textInfos .UNIT_CHARACTER : return speech .spellTextInfo (info , True )
55
66
tmp = origSpeakTextInfo (* args , ** kwargs )
56
67
if config .conf ['enhancedPhoneticReading' ]['delayedDescriptions' ] and kwargs .get ('unit' ) == textInfos .UNIT_CHARACTER :
57
- characterDescriptionTimer = wx . CallLater (config .conf ['enhancedPhoneticReading' ]['delay' ], speakDescription , info . text , info . getTextWithFields ({} ))
68
+ characterDescriptionTimer = core . callLater (config .conf ['enhancedPhoneticReading' ]['delay' ], speakDelayedDescription , _FakeTextInfo ( info ))
58
69
return tmp
59
70
60
- def speakDescription (text , fields ):
61
- curLanguage = speech .getCurrentLanguage ()
62
- if not config .conf ['speech' ]['autoLanguageSwitching' ] and characterProcessing .getCharacterDescription (curLanguage , text .lower ()):
63
- return speakSpelling (text , curLanguage , useCharacterDescriptions = True )
64
- for field in fields :
65
- if isinstance (field , six .string_types ) and characterProcessing .getCharacterDescription (curLanguage , field .lower ()):
66
- speakSpelling (field ,curLanguage ,useCharacterDescriptions = True )
67
- elif isinstance (field ,textInfos .FieldCommand ) and field .command == "formatChange" :
68
- curLanguage = field .field .get ('language' , curLanguage ) or curLanguage
71
+ def speakDelayedDescription (info : _FakeTextInfo ):
72
+ """
73
+ this function is used to announce the delayed descriptions, we can't call spellTextInfo directly because we need to check if the description is available first.
74
+ """
75
+ if info .text .strip () == "" : return
76
+ curLang = speech .getCurrentLanguage ()
77
+ if config .conf ['speech' ]['autoLanguageSwitching' ]:
78
+ for k in info .fields :
79
+ if isinstance (k , textInfos .FieldCommand ) and k .command == "formatChange" :
80
+ curLang = k .field .get ('language' , curLang )
81
+ _ , description = speech .getCharDescListFromText (info .text , locale = curLang )[0 ]
82
+ if description :
83
+ speech .spellTextInfo (info , useCharacterDescriptions = True )
69
84
70
85
class EnhancedPhoneticReadingPanel (gui .SettingsPanel ):
71
86
# Translators: This is the label for the Enhanced phonetic reading settings category in NVDA Settings screen.
0 commit comments