8282
8383# try to get around espeak bug where voice slows down (for other voices, just a waste of time)
8484# we use a global that gets set at a time when the rate is probably good (SetMathML)
85- _synthesizer_rate : int | None = None
85+ _synthesizerRate : int | None = None
8686
8787
8888def getLanguageToUse (mathMl : str = "" ) -> str :
@@ -135,14 +135,14 @@ def ConvertSSMLTextForNVDA(text: str) -> list:
135135 # At "50" espeak finished in 46 sec, sapi in 75 sec, and one core in 70; at '100' one core was much slower than the others
136136 wpm = 2 * getSynth ()._get_rate ()
137137 breakMulti = 180.0 / wpm
138- supported_commands = synth .supportedCommands
139- use_break = BreakCommand in supported_commands
140- use_pitch = PitchCommand in supported_commands
138+ supportedCommands = synth .supportedCommands
139+ useBreak = BreakCommand in supportedCommands
140+ usePitch = PitchCommand in supportedCommands
141141 # use_rate = RateCommand in supported_commands
142142 # use_volume = VolumeCommand in supported_commands
143- use_phoneme = PhonemeCommand in supported_commands
143+ usePhoneme = PhonemeCommand in supportedCommands
144144 # as of 7/23, oneCore voices do not implement the CharacterModeCommand despite it being in supported_commands
145- use_character = CharacterModeCommand in supported_commands and synth .name != "oneCore"
145+ useCharacter = CharacterModeCommand in supportedCommands and synth .name != "oneCore"
146146 out = []
147147 if mathCATLanguageSetting != language :
148148 # log.info(f"Setting language to {language}")
@@ -158,31 +158,31 @@ def ConvertSSMLTextForNVDA(text: str) -> list:
158158 # log.info(f"\ntext: {text}")
159159 for m in RE_MATHML_SPEECH .finditer (text ):
160160 if m .lastgroup == "break" :
161- if use_break :
161+ if useBreak :
162162 out .append (BreakCommand (time = int (int (m .group ("break" )) * breakMulti )))
163163 elif m .lastgroup == "char" :
164164 ch = m .group ("char" )
165- if use_character :
165+ if useCharacter :
166166 out .extend ((CharacterModeCommand (True ), ch , CharacterModeCommand (False )))
167167 else :
168168 out .extend ((" " , "eigh" if ch == "a" and language .startswith ("en" ) else ch , " " ))
169169 elif m .lastgroup == "beep" :
170170 out .append (BeepCommand (2000 , 50 ))
171171 elif m .lastgroup == "pitch" :
172- if use_pitch :
172+ if usePitch :
173173 out .append (PitchCommand (multiplier = int (m .group (m .lastgroup ))))
174174 resetProsody .append (PitchCommand )
175175 elif m .lastgroup in PROSODY_COMMANDS :
176176 command = PROSODY_COMMANDS [m .lastgroup ]
177- if command in supported_commands :
177+ if command in supportedCommands :
178178 out .append (command (multiplier = int (m .group (m .lastgroup )) / 100.0 ))
179179 resetProsody .append (command )
180180 elif m .lastgroup == "prosodyReset" :
181181 # for command in resetProsody: # only supported commands were added, so no need to check
182182 command = resetProsody .pop ()
183183 out .append (command (multiplier = 1 ))
184184 elif m .lastgroup == "phonemeText" :
185- if use_phoneme :
185+ if usePhoneme :
186186 out .append (PhonemeCommand (m .group ("ipa" ), text = m .group ("phonemeText" )))
187187 else :
188188 out .append (m .group ("phonemeText" ))
@@ -220,15 +220,15 @@ class MathCATInteraction(mathPres.MathInteractionNVDAObject):
220220 def __init__ (self , provider = None , mathMl : Optional [str ] = None ):
221221 super (MathCATInteraction , self ).__init__ (provider = provider , mathMl = mathMl )
222222 if mathMl is None :
223- self .init_mathml = "<math></math>"
223+ self .initMathML = "<math></math>"
224224 else :
225- self .init_mathml = mathMl
225+ self .initMathML = mathMl
226226
227227 def reportFocus (self ):
228228 super (MathCATInteraction , self ).reportFocus ()
229229 # try to get around espeak bug where voice slows down
230- if _synthesizer_rate and getSynth ().name == "espeak" :
231- getSynth ()._set_rate (_synthesizer_rate )
230+ if _synthesizerRate and getSynth ().name == "espeak" :
231+ getSynth ()._set_rate (_synthesizerRate )
232232 try :
233233 text = libmathcat .DoNavigateCommand ("ZoomIn" )
234234 speech .speak (ConvertSSMLTextForNVDA (text ))
@@ -238,9 +238,9 @@ def reportFocus(self):
238238 speech .speakMessage (_ ("Error in starting navigation of math: see NVDA error log for details" ))
239239 finally :
240240 # try to get around espeak bug where voice slows down
241- if _synthesizer_rate and getSynth ().name == "espeak" :
241+ if _synthesizerRate and getSynth ().name == "espeak" :
242242 # log.info(f'reportFocus: reset to {_synthesizer_rate}')
243- getSynth ()._set_rate (_synthesizer_rate )
243+ getSynth ()._set_rate (_synthesizerRate )
244244
245245 def getBrailleRegions (self , review : bool = False ):
246246 # log.info("***MathCAT start getBrailleRegions")
@@ -295,8 +295,8 @@ def getScript(self, gesture: KeyboardInputGesture):
295295 def script_navigate (self , gesture : KeyboardInputGesture ):
296296 try :
297297 # try to get around espeak bug where voice slows down
298- if _synthesizer_rate and getSynth ().name == "espeak" :
299- getSynth ()._set_rate (_synthesizer_rate )
298+ if _synthesizerRate and getSynth ().name == "espeak" :
299+ getSynth ()._set_rate (_synthesizerRate )
300300 if gesture is not None : # == None when initial focus -- handled in reportFocus()
301301 modNames = gesture .modifierNames
302302 text = libmathcat .DoNavigateKeyPress (
@@ -314,20 +314,20 @@ def script_navigate(self, gesture: KeyboardInputGesture):
314314 speech .speakMessage (_ ("Error in navigating math: see NVDA error log for details" ))
315315 finally :
316316 # try to get around espeak bug where voice slows down
317- if _synthesizer_rate and getSynth ().name == "espeak" :
317+ if _synthesizerRate and getSynth ().name == "espeak" :
318318 # log.info(f'script_navigate: reset to {_synthesizer_rate}')
319- getSynth ()._set_rate (_synthesizer_rate )
319+ getSynth ()._set_rate (_synthesizerRate )
320320
321321 if not braille .handler .enabled :
322322 return
323323
324324 try :
325325 # update the braille to reflect the nav position (might be excess code, but it works)
326- nav_node = libmathcat .GetNavigationMathMLId ()
327- braille_chars = libmathcat .GetBraille (nav_node [0 ])
326+ navNode = libmathcat .GetNavigationMathMLId ()
327+ brailleChars = libmathcat .GetBraille (navNode [0 ])
328328 # log.info(f'braille display = {config.conf["braille"]["display"]}, braille_chars: {braille_chars}')
329329 region = braille .Region ()
330- region .rawText = braille_chars
330+ region .rawText = brailleChars
331331 region .focusToHardLeft = True
332332 region .update ()
333333 braille .handler .buffer .regions .append (region )
@@ -350,44 +350,44 @@ def script_navigate(self, gesture: KeyboardInputGesture):
350350 ) # type: ignore
351351 def script_rawdataToClip (self , gesture : KeyboardInputGesture ):
352352 try :
353- copy_as = "mathml" # value used even if "CopyAs" pref is invalid
354- text_to_copy = ""
353+ copyAs = "mathml" # value used even if "CopyAs" pref is invalid
354+ textToCopy = ""
355355 try :
356- copy_as = libmathcat .GetPreference ("CopyAs" ).lower ()
356+ copyAs = libmathcat .GetPreference ("CopyAs" ).lower ()
357357 except Exception as e :
358358 log .exception (f"Not able to get 'CopyAs' preference: { e } " )
359- if copy_as == "asciimath" or copy_as == "latex" :
359+ if copyAs == "asciimath" or copyAs == "latex" :
360360 # save the old braille code, set the new one, get the braille, then reset the code
361- saved_braille_code : str = libmathcat .GetPreference ("BrailleCode" )
362- libmathcat .SetPreference ("BrailleCode" , "LaTeX" if copy_as == "latex" else "ASCIIMath" )
363- text_to_copy = libmathcat .GetNavigationBraille ()
364- libmathcat .SetPreference ("BrailleCode" , saved_braille_code )
365- if copy_as == "asciimath" :
366- copy_as = "ASCIIMath" # speaks better in at least some voices
361+ savedBrailleCode : str = libmathcat .GetPreference ("BrailleCode" )
362+ libmathcat .SetPreference ("BrailleCode" , "LaTeX" if copyAs == "latex" else "ASCIIMath" )
363+ textToCopy = libmathcat .GetNavigationBraille ()
364+ libmathcat .SetPreference ("BrailleCode" , savedBrailleCode )
365+ if copyAs == "asciimath" :
366+ copyAs = "ASCIIMath" # speaks better in at least some voices
367367 else :
368368 mathml = libmathcat .GetNavigationMathML ()[0 ]
369369 if not re .match (self ._startsWithMath , mathml ):
370370 mathml = "<math>\n " + mathml + "</math>" # copy will fix up name spacing
371- elif self .init_mathml != "" :
372- mathml = self .init_mathml
373- if copy_as == "speech" :
371+ elif self .initMathML != "" :
372+ mathml = self .initMathML
373+ if copyAs == "speech" :
374374 # save the old MathML, set the navigation MathML as MathMl, get the speech, then reset the MathML
375- saved_mathml : str = self .init_mathml
376- saved_tts = libmathcat .GetPreference ("TTS" )
377- if saved_mathml == "" : # shouldn't happen
375+ savedMathML : str = self .initMathML
376+ savedTTS = libmathcat .GetPreference ("TTS" )
377+ if savedMathML == "" : # shouldn't happen
378378 raise Exception ("Internal error -- MathML not set for copy" )
379379 libmathcat .SetPreference ("TTS" , "None" )
380380 libmathcat .SetMathML (mathml )
381381 # get the speech text and collapse the whitespace
382- text_to_copy = " " .join (libmathcat .GetSpokenText ().split ())
383- libmathcat .SetPreference ("TTS" , saved_tts )
384- libmathcat .SetMathML (saved_mathml )
382+ textToCopy = " " .join (libmathcat .GetSpokenText ().split ())
383+ libmathcat .SetPreference ("TTS" , savedTTS )
384+ libmathcat .SetMathML (savedMathML )
385385 else :
386- text_to_copy = self ._wrapMathMLForClipBoard (mathml )
386+ textToCopy = self ._wrapMathMLForClipBoard (mathml )
387387
388- self ._copyToClipAsMathML (text_to_copy , copy_as == "mathml" )
388+ self ._copyToClipAsMathML (textToCopy , copyAs == "mathml" )
389389 # Translators: copy to clipboard
390- ui .message (_ ("copy as " ) + copy_as )
390+ ui .message (_ ("copy as " ) + copyAs )
391391 except Exception as e :
392392 log .exception (e )
393393 # Translators: this message directs users to look in the log file
@@ -402,16 +402,16 @@ def script_rawdataToClip(self, gesture: KeyboardInputGesture):
402402 def _wrapMathMLForClipBoard (self , text : str ) -> str :
403403 # cleanup the MathML a little
404404 text = re .sub (self ._hasAddedId , "" , text )
405- mathml_with_ns = re .sub (self ._hasDataAttr , "" , text )
406- if not re .match (self ._mathTagHasNameSpace , mathml_with_ns ):
407- mathml_with_ns = mathml_with_ns .replace (
405+ mathMLWithNS = re .sub (self ._hasDataAttr , "" , text )
406+ if not re .match (self ._mathTagHasNameSpace , mathMLWithNS ):
407+ mathMLWithNS = mathMLWithNS .replace (
408408 "math" ,
409409 "math xmlns='http://www.w3.org/1998/Math/MathML'" ,
410410 1 ,
411411 )
412- return mathml_with_ns
412+ return mathMLWithNS
413413
414- def _copyToClipAsMathML (self , text : str , is_mathml : bool , notify : Optional [bool ] = False ) -> bool :
414+ def _copyToClipAsMathML (self , text : str , isMathML : bool , notify : Optional [bool ] = False ) -> bool :
415415 """Copies the given text to the windows clipboard.
416416 @returns: True if it succeeds, False otherwise.
417417 @param text: the text which will be copied to the clipboard
@@ -424,7 +424,7 @@ def _copyToClipAsMathML(self, text: str, is_mathml: bool, notify: Optional[bool]
424424 try :
425425 with winUser .openClipboard (gui .mainFrame .Handle ):
426426 winUser .emptyClipboard ()
427- if is_mathml :
427+ if isMathML :
428428 self ._setClipboardData (self .CF_MathML , '<?xml version="1.0"?>' + text )
429429 self ._setClipboardData (self .CF_MathML_Presentation , '<?xml version="1.0"?>' + text )
430430 self ._setClipboardData (winUser .CF_UNICODETEXT , text )
@@ -468,23 +468,23 @@ def __init__(self):
468468
469469 try :
470470 # IMPORTANT -- SetRulesDir must be the first call to libmathcat besides GetVersion()
471- rules_dir = path .join (path .dirname (path .abspath (__file__ )), "Rules" )
472- log .info (f"MathCAT { libmathcat .GetVersion ()} installed. Using rules dir: { rules_dir } " )
473- libmathcat .SetRulesDir (rules_dir )
471+ rulesDir = path .join (path .dirname (path .abspath (__file__ )), "Rules" )
472+ log .info (f"MathCAT { libmathcat .GetVersion ()} installed. Using rules dir: { rulesDir } " )
473+ libmathcat .SetRulesDir (rulesDir )
474474 libmathcat .SetPreference ("TTS" , "SSML" )
475475 except Exception as e :
476476 log .exception (e )
477477 # Translators: this message directs users to look in the log file
478478 speech .speakMessage (_ ("MathCAT initialization failed: see NVDA error log for details" ))
479479
480480 def getSpeechForMathMl (self , mathml : str ):
481- global _synthesizer_rate
481+ global _synthesizerRate
482482 synth = getSynth ()
483483 synthConfig = config .conf ["speech" ][synth .name ]
484484 if synth .name == "espeak" :
485- _synthesizer_rate = synthConfig ["rate" ]
485+ _synthesizerRate = synthConfig ["rate" ]
486486 # log.info(f'_synthesizer_rate={_synthesizer_rate}, get_rate()={getSynth()._get_rate()}')
487- getSynth ()._set_rate (_synthesizer_rate )
487+ getSynth ()._set_rate (_synthesizerRate )
488488 # log.info(f'..............get_rate()={getSynth()._get_rate()}, name={synth.name}')
489489 try :
490490 # need to set Language before the MathML for DecimalSeparator canonicalization
@@ -499,7 +499,7 @@ def getSpeechForMathMl(self, mathml: str):
499499 speech .speakMessage (_ ("Illegal MathML found: see NVDA error log for details" ))
500500 libmathcat .SetMathML ("<math></math>" ) # set it to something
501501 try :
502- supported_commands = synth .supportedCommands
502+ supportedCommands = synth .supportedCommands
503503 # Set preferences for capital letters
504504 libmathcat .SetPreference (
505505 "CapitalLetters_Beep" ,
@@ -510,9 +510,9 @@ def getSpeechForMathMl(self, mathml: str):
510510 "true" if synthConfig ["sayCapForCapitals" ] else "false" ,
511511 )
512512 # log.info(f"Speech text: {libmathcat.GetSpokenText()}")
513- if PitchCommand in supported_commands :
513+ if PitchCommand in supportedCommands :
514514 libmathcat .SetPreference ("CapitalLetters_Pitch" , str (synthConfig ["capPitchChange" ]))
515- if self ._add_sounds ():
515+ if self ._addSounds ():
516516 return (
517517 [BeepCommand (800 , 25 )]
518518 + ConvertSSMLTextForNVDA (libmathcat .GetSpokenText ())
@@ -528,11 +528,11 @@ def getSpeechForMathMl(self, mathml: str):
528528 return ["" ]
529529 finally :
530530 # try to get around espeak bug where voice slows down
531- if _synthesizer_rate and getSynth ().name == "espeak" :
531+ if _synthesizerRate and getSynth ().name == "espeak" :
532532 # log.info(f'getSpeechForMathMl: reset to {_synthesizer_rate}')
533- getSynth ()._set_rate (_synthesizer_rate )
533+ getSynth ()._set_rate (_synthesizerRate )
534534
535- def _add_sounds (self ):
535+ def _addSounds (self ):
536536 try :
537537 return libmathcat .GetPreference ("SpeechSound" ) != "None"
538538 except Exception as e :
@@ -572,10 +572,10 @@ def _monkeyPatchESpeak():
572572 return # already patched
573573
574574 CACHED_SYNTH = currentSynth
575- currentSynth .speak = patched_speak .__get__ (currentSynth , type (currentSynth ))
575+ currentSynth .speak = patchedSpeak .__get__ (currentSynth , type (currentSynth ))
576576
577577
578- def patched_speak (self , speechSequence : SpeechSequence ): # noqa: C901
578+ def patchedSpeak (self , speechSequence : SpeechSequence ): # noqa: C901
579579 # log.info(f"\npatched_speak input: {speechSequence}")
580580 textList : List [str ] = []
581581 langChanged = False
0 commit comments