2424PAUSE_FACTOR_LOG_BASE = 1.4
2525
2626# initialize the user preferences tuples
27- user_preferences : Dict [str , Dict [str , Union [int , str , bool ]]] = {}
27+ userPreferences : Dict [str , Dict [str , Union [int , str , bool ]]] = {}
2828# Speech_Language is derived from the folder structures
2929Speech_DecimalSeparator = ("Auto" , "." , "," , "Custom" )
3030Speech_Impairment = ("LearningDisability" , "Blindness" , "LowVision" )
@@ -49,28 +49,28 @@ def __init__(self, parent):
4949 # load the logo into the dialog
5050 fullPathToLogo = os .path .join (os .path .dirname (os .path .abspath (__file__ )), "logo.png" )
5151 if os .path .exists (fullPathToLogo ):
52- self .m_bitmapLogo .SetBitmap (wx .Bitmap (fullPathToLogo ))
52+ self ._bitmapLogo .SetBitmap (wx .Bitmap (fullPathToLogo ))
5353
5454 # load in the system values followed by the user prefs (if any)
5555 UserInterface .loadDefaultPreferences ()
5656 UserInterface .loadUserPreferences ()
5757
5858 # hack for "CopyAs" because its location in the prefs is not yet fixed
59- if "CopyAs" not in user_preferences ["Navigation" ]:
60- user_preferences ["Navigation" ]["CopyAs" ] = (
61- user_preferences ["Other" ]["CopyAs" ] if "CopyAs" in user_preferences ["Other" ] else "MathML"
59+ if "CopyAs" not in userPreferences ["Navigation" ]:
60+ userPreferences ["Navigation" ]["CopyAs" ] = (
61+ userPreferences ["Other" ]["CopyAs" ] if "CopyAs" in userPreferences ["Other" ] else "MathML"
6262 )
6363 UserInterface .validateUserPreferences ()
6464
65- if "NVDAAddOn" in user_preferences :
65+ if "NVDAAddOn" in userPreferences :
6666 # set the categories selection to what we used on last run
67- self ._listBoxPreferencesTopic .SetSelection (user_preferences ["NVDAAddOn" ]["LastCategory" ])
67+ self ._listBoxPreferencesTopic .SetSelection (userPreferences ["NVDAAddOn" ]["LastCategory" ])
6868 # show the appropriate dialogue page
6969 self ._simplebookPanelsCategories .SetSelection (self ._listBoxPreferencesTopic .GetSelection ())
7070 else :
7171 # set the categories selection to the first item
7272 self ._listBoxPreferencesTopic .SetSelection (0 )
73- user_preferences ["NVDAAddOn" ] = {"LastCategory" : "0" }
73+ userPreferences ["NVDAAddOn" ] = {"LastCategory" : "0" }
7474 # populate the languages and braille codes
7575 UserInterface .GetLanguages (self )
7676 UserInterface .GetBrailleCodes (self )
@@ -418,10 +418,10 @@ def setUIValues(self):
418418 # set the UI elements to the ones read from the preference file(s)
419419 try :
420420 self ._choiceImpairment .SetSelection (
421- Speech_Impairment .index (user_preferences ["Speech" ]["Impairment" ]),
421+ Speech_Impairment .index (userPreferences ["Speech" ]["Impairment" ]),
422422 )
423423 try :
424- langPref = user_preferences ["Speech" ]["Language" ]
424+ langPref = userPreferences ["Speech" ]["Language" ]
425425 self ._choiceLanguage .SetSelection (0 )
426426 i = 1 # no need to test i == 0
427427 while i < self ._choiceLanguage .GetCount ():
@@ -431,65 +431,65 @@ def setUIValues(self):
431431 i += 1
432432 except Exception as e :
433433 log .exception (
434- f"MathCAT: An exception occurred in setUIValues ('{ user_preferences ['Speech' ]['Language' ]} '): { e } " ,
434+ f"MathCAT: An exception occurred in setUIValues ('{ userPreferences ['Speech' ]['Language' ]} '): { e } " ,
435435 )
436436 # the language in the settings file is not in the folder structure, something went wrong,
437437 # set to the first in the list
438438 self ._choiceLanguage .SetSelection (0 )
439439 try :
440440 # now get the available SpeechStyles from the folder structure and set to the preference setting is possible
441- self .GetSpeechStyles (str (user_preferences ["Speech" ]["SpeechStyle" ]))
441+ self .GetSpeechStyles (str (userPreferences ["Speech" ]["SpeechStyle" ]))
442442 except Exception as e :
443443 log .exception (f"MathCAT: An exception occurred in set_ui_values (getting SpeechStyle): { e } " )
444444 self ._choiceSpeechStyle .Append (
445445 "Error when setting SpeechStyle for " + self ._choiceLanguage .GetStringSelection (),
446446 )
447447 # set the rest of the UI elements
448448 self ._choiceDecimalSeparator .SetSelection (
449- Speech_DecimalSeparator .index (user_preferences ["Other" ]["DecimalSeparator" ]),
449+ Speech_DecimalSeparator .index (userPreferences ["Other" ]["DecimalSeparator" ]),
450450 )
451451 self ._choiceSpeechAmount .SetSelection (
452- Speech_Verbosity .index (user_preferences ["Speech" ]["Verbosity" ]),
452+ Speech_Verbosity .index (userPreferences ["Speech" ]["Verbosity" ]),
453453 )
454- self ._sliderRelativeSpeed .SetValue (user_preferences ["Speech" ]["MathRate" ])
454+ self ._sliderRelativeSpeed .SetValue (userPreferences ["Speech" ]["MathRate" ])
455455 pause_factor = (
456456 0
457- if int (user_preferences ["Speech" ]["PauseFactor" ]) <= 1
457+ if int (userPreferences ["Speech" ]["PauseFactor" ]) <= 1
458458 else round (
459459 math .log (
460- int (user_preferences ["Speech" ]["PauseFactor" ]) / PAUSE_FACTOR_SCALE ,
460+ int (userPreferences ["Speech" ]["PauseFactor" ]) / PAUSE_FACTOR_SCALE ,
461461 PAUSE_FACTOR_LOG_BASE ,
462462 ),
463463 )
464464 )
465465 self ._sliderPauseFactor .SetValue (pause_factor )
466- self ._checkBoxSpeechSound .SetValue (user_preferences ["Speech" ]["SpeechSound" ] == "Beep" )
466+ self ._checkBoxSpeechSound .SetValue (userPreferences ["Speech" ]["SpeechSound" ] == "Beep" )
467467 self ._choiceSpeechForChemical .SetSelection (
468- Speech_Chemistry .index (user_preferences ["Speech" ]["Chemistry" ]),
468+ Speech_Chemistry .index (userPreferences ["Speech" ]["Chemistry" ]),
469469 )
470470
471471 self ._choiceNavigationMode .SetSelection (
472- Navigation_NavMode .index (user_preferences ["Navigation" ]["NavMode" ]),
472+ Navigation_NavMode .index (userPreferences ["Navigation" ]["NavMode" ]),
473473 )
474- self ._checkBoxResetNavigationMode .SetValue (user_preferences ["Navigation" ]["ResetNavMode" ])
474+ self ._checkBoxResetNavigationMode .SetValue (userPreferences ["Navigation" ]["ResetNavMode" ])
475475 self ._choiceSpeechAmountNavigation .SetSelection (
476- Navigation_NavVerbosity .index (user_preferences ["Navigation" ]["NavVerbosity" ]),
476+ Navigation_NavVerbosity .index (userPreferences ["Navigation" ]["NavVerbosity" ]),
477477 )
478- if user_preferences ["Navigation" ]["Overview" ]:
478+ if userPreferences ["Navigation" ]["Overview" ]:
479479 self ._choiceNavigationSpeech .SetSelection (1 )
480480 else :
481481 self ._choiceNavigationSpeech .SetSelection (0 )
482- self ._checkBoxResetNavigationSpeech .SetValue (user_preferences ["Navigation" ]["ResetOverview" ])
483- self ._checkBoxAutomaticZoom .SetValue (user_preferences ["Navigation" ]["AutoZoomOut" ])
482+ self ._checkBoxResetNavigationSpeech .SetValue (userPreferences ["Navigation" ]["ResetOverview" ])
483+ self ._checkBoxAutomaticZoom .SetValue (userPreferences ["Navigation" ]["AutoZoomOut" ])
484484 self ._choiceCopyAs .SetSelection (
485- Navigation_CopyAs .index (user_preferences ["Navigation" ]["CopyAs" ]),
485+ Navigation_CopyAs .index (userPreferences ["Navigation" ]["CopyAs" ]),
486486 )
487487
488488 self ._choiceBrailleHighlights .SetSelection (
489- Braille_BrailleNavHighlight .index (user_preferences ["Braille" ]["BrailleNavHighlight" ]),
489+ Braille_BrailleNavHighlight .index (userPreferences ["Braille" ]["BrailleNavHighlight" ]),
490490 )
491491 try :
492- braillePref = user_preferences ["Braille" ]["BrailleCode" ]
492+ braillePref = userPreferences ["Braille" ]["BrailleCode" ]
493493 i = 0
494494 while braillePref != self ._choiceBrailleMathCode .GetString (i ):
495495 i = i + 1
@@ -508,47 +508,47 @@ def setUIValues(self):
508508 print ("Key not found" , err )
509509
510510 def getUIValues (self ):
511- global user_preferences
511+ global userPreferences
512512 # read the values from the UI and update the user preferences dictionary
513- user_preferences ["Speech" ]["Impairment" ] = Speech_Impairment [self ._choiceImpairment .GetSelection ()]
514- user_preferences ["Speech" ]["Language" ] = self .GetLanguageCode ()
515- user_preferences ["Other" ]["DecimalSeparator" ] = Speech_DecimalSeparator [
513+ userPreferences ["Speech" ]["Impairment" ] = Speech_Impairment [self ._choiceImpairment .GetSelection ()]
514+ userPreferences ["Speech" ]["Language" ] = self .GetLanguageCode ()
515+ userPreferences ["Other" ]["DecimalSeparator" ] = Speech_DecimalSeparator [
516516 self ._choiceDecimalSeparator .GetSelection ()
517517 ]
518- user_preferences ["Speech" ]["SpeechStyle" ] = self ._choiceSpeechStyle .GetStringSelection ()
519- user_preferences ["Speech" ]["Verbosity" ] = Speech_Verbosity [self ._choiceSpeechAmount .GetSelection ()]
520- user_preferences ["Speech" ]["MathRate" ] = self ._sliderRelativeSpeed .GetValue ()
518+ userPreferences ["Speech" ]["SpeechStyle" ] = self ._choiceSpeechStyle .GetStringSelection ()
519+ userPreferences ["Speech" ]["Verbosity" ] = Speech_Verbosity [self ._choiceSpeechAmount .GetSelection ()]
520+ userPreferences ["Speech" ]["MathRate" ] = self ._sliderRelativeSpeed .GetValue ()
521521 pfSlider = self ._sliderPauseFactor .GetValue ()
522522 pauseFactor = (
523523 0 if pfSlider == 0 else round (PAUSE_FACTOR_SCALE * math .pow (PAUSE_FACTOR_LOG_BASE , pfSlider ))
524524 ) # avoid log(0)
525- user_preferences ["Speech" ]["PauseFactor" ] = pauseFactor
525+ userPreferences ["Speech" ]["PauseFactor" ] = pauseFactor
526526 if self ._checkBoxSpeechSound .GetValue ():
527- user_preferences ["Speech" ]["SpeechSound" ] = "Beep"
527+ userPreferences ["Speech" ]["SpeechSound" ] = "Beep"
528528 else :
529- user_preferences ["Speech" ]["SpeechSound" ] = "None"
530- user_preferences ["Speech" ]["Chemistry" ] = Speech_Chemistry [
529+ userPreferences ["Speech" ]["SpeechSound" ] = "None"
530+ userPreferences ["Speech" ]["Chemistry" ] = Speech_Chemistry [
531531 self ._choiceSpeechForChemical .GetSelection ()
532532 ]
533- user_preferences ["Navigation" ]["NavMode" ] = Navigation_NavMode [
533+ userPreferences ["Navigation" ]["NavMode" ] = Navigation_NavMode [
534534 self ._choiceNavigationMode .GetSelection ()
535535 ]
536- user_preferences ["Navigation" ]["ResetNavMode" ] = self ._checkBoxResetNavigationMode .GetValue ()
537- user_preferences ["Navigation" ]["NavVerbosity" ] = Navigation_NavVerbosity [
536+ userPreferences ["Navigation" ]["ResetNavMode" ] = self ._checkBoxResetNavigationMode .GetValue ()
537+ userPreferences ["Navigation" ]["NavVerbosity" ] = Navigation_NavVerbosity [
538538 self ._choiceSpeechAmountNavigation .GetSelection ()
539539 ]
540- user_preferences ["Navigation" ]["Overview" ] = self ._choiceNavigationSpeech .GetSelection () != 0
541- user_preferences ["Navigation" ]["ResetOverview" ] = self ._checkBoxResetNavigationSpeech .GetValue ()
542- user_preferences ["Navigation" ]["AutoZoomOut" ] = self ._checkBoxAutomaticZoom .GetValue ()
543- user_preferences ["Navigation" ]["CopyAs" ] = Navigation_CopyAs [self ._choiceCopyAs .GetSelection ()]
540+ userPreferences ["Navigation" ]["Overview" ] = self ._choiceNavigationSpeech .GetSelection () != 0
541+ userPreferences ["Navigation" ]["ResetOverview" ] = self ._checkBoxResetNavigationSpeech .GetValue ()
542+ userPreferences ["Navigation" ]["AutoZoomOut" ] = self ._checkBoxAutomaticZoom .GetValue ()
543+ userPreferences ["Navigation" ]["CopyAs" ] = Navigation_CopyAs [self ._choiceCopyAs .GetSelection ()]
544544
545- user_preferences ["Braille" ]["BrailleNavHighlight" ] = Braille_BrailleNavHighlight [
545+ userPreferences ["Braille" ]["BrailleNavHighlight" ] = Braille_BrailleNavHighlight [
546546 self ._choiceBrailleHighlights .GetSelection ()
547547 ]
548- user_preferences ["Braille" ]["BrailleCode" ] = self ._choiceBrailleMathCode .GetStringSelection ()
549- if "NVDAAddOn" not in user_preferences :
550- user_preferences ["NVDAAddOn" ] = {"LastCategory" : "0" }
551- user_preferences ["NVDAAddOn" ]["LastCategory" ] = self ._listBoxPreferencesTopic .GetSelection ()
548+ userPreferences ["Braille" ]["BrailleCode" ] = self ._choiceBrailleMathCode .GetStringSelection ()
549+ if "NVDAAddOn" not in userPreferences :
550+ userPreferences ["NVDAAddOn" ] = {"LastCategory" : "0" }
551+ userPreferences ["NVDAAddOn" ]["LastCategory" ] = self ._listBoxPreferencesTopic .GetSelection ()
552552
553553 @staticmethod
554554 def pathToDefaultPreferences ():
@@ -566,62 +566,62 @@ def pathToUserPreferences():
566566
567567 @staticmethod
568568 def loadDefaultPreferences ():
569- global user_preferences
569+ global userPreferences
570570 # load default preferences into the user preferences data structure (overwrites existing)
571571 if os .path .exists (UserInterface .pathToDefaultPreferences ()):
572572 with open (
573573 UserInterface .pathToDefaultPreferences (),
574574 encoding = "utf-8" ,
575575 ) as f :
576- user_preferences = yaml .load (f , Loader = yaml .FullLoader )
576+ userPreferences = yaml .load (f , Loader = yaml .FullLoader )
577577
578578 @staticmethod
579579 def loadUserPreferences ():
580- global user_preferences
580+ global userPreferences
581581 # merge user file values into the user preferences data structure
582582 if os .path .exists (UserInterface .pathToUserPreferences ()):
583583 with open (UserInterface .pathToUserPreferences (), encoding = "utf-8" ) as f :
584584 # merge with the default preferences, overwriting with the user's values
585- user_preferences .update (yaml .load (f , Loader = yaml .FullLoader ))
585+ userPreferences .update (yaml .load (f , Loader = yaml .FullLoader ))
586586
587587 @staticmethod
588588 def validate (key1 : str , key2 : str , validValues : List [Union [str , bool ]], defaultValue : Union [str , bool ]):
589- global user_preferences
589+ global userPreferences
590590 try :
591591 if validValues == []:
592592 # any value is valid
593- if user_preferences [key1 ][key2 ] != "" :
593+ if userPreferences [key1 ][key2 ] != "" :
594594 return
595595
596596 else :
597597 # any value in the list is valid
598- if user_preferences [key1 ][key2 ] in validValues :
598+ if userPreferences [key1 ][key2 ] in validValues :
599599 return
600600 except Exception as e :
601601 log .exception (f"MathCAT: An exception occurred in validate: { e } " )
602602 # the preferences entry does not exist
603- if key1 not in user_preferences :
604- user_preferences [key1 ] = {key2 : defaultValue }
603+ if key1 not in userPreferences :
604+ userPreferences [key1 ] = {key2 : defaultValue }
605605 else :
606- user_preferences [key1 ][key2 ] = defaultValue
606+ userPreferences [key1 ][key2 ] = defaultValue
607607
608608 @staticmethod
609609 def validateInt (key1 : str , key2 : str , validValues : List [int ], defaultValue : int ):
610- global user_preferences
610+ global userPreferences
611611 try :
612612 # any value between lower and upper bounds is valid
613613 if (
614- int (user_preferences [key1 ][key2 ]) >= validValues [0 ]
615- and int (user_preferences [key1 ][key2 ]) <= validValues [1 ]
614+ int (userPreferences [key1 ][key2 ]) >= validValues [0 ]
615+ and int (userPreferences [key1 ][key2 ]) <= validValues [1 ]
616616 ):
617617 return
618618 except Exception as e :
619619 log .exception (f"MathCAT: An exception occurred in validateInt: { e } " )
620620 # the preferences entry does not exist
621- if key1 not in user_preferences :
622- user_preferences [key1 ] = {key2 : defaultValue }
621+ if key1 not in userPreferences :
622+ userPreferences [key1 ] = {key2 : defaultValue }
623623 else :
624- user_preferences [key1 ][key2 ] = defaultValue
624+ userPreferences [key1 ][key2 ] = defaultValue
625625
626626 @staticmethod
627627 def validateUserPreferences ():
@@ -683,17 +683,17 @@ def writeUserPreferences():
683683 from . import libmathcat_py as libmathcat
684684
685685 try :
686- libmathcat .SetPreference ("Language" , user_preferences ["Speech" ]["Language" ])
686+ libmathcat .SetPreference ("Language" , userPreferences ["Speech" ]["Language" ])
687687 except Exception as e :
688688 log .exception (
689- f'Error in trying to set MathCAT "Language" preference to "{ user_preferences ["Speech" ]["Language" ]} ": { e } ' ,
689+ f'Error in trying to set MathCAT "Language" preference to "{ userPreferences ["Speech" ]["Language" ]} ": { e } ' ,
690690 )
691691 if not os .path .exists (UserInterface .pathToUserPreferencesFolder ()):
692692 # create a folder for the user preferences
693693 os .mkdir (UserInterface .pathToUserPreferencesFolder ())
694694 with open (UserInterface .pathToUserPreferences (), "w" , encoding = "utf-8" ) as f :
695695 # write values to the user preferences file, NOT the default
696- yaml .dump (user_preferences , stream = f , allow_unicode = True )
696+ yaml .dump (userPreferences , stream = f , allow_unicode = True )
697697
698698 def OnRelativeSpeedChanged (self , event ):
699699 rate = self ._sliderRelativeSpeed .GetValue ()
@@ -707,9 +707,9 @@ def OnRelativeSpeedChanged(self, event):
707707
708708 def OnPauseFactorChanged (self , event ):
709709 rate = self ._sliderRelativeSpeed .GetValue ()
710- pf_slider = self ._sliderPauseFactor .GetValue ()
710+ pfSlider = self ._sliderPauseFactor .GetValue ()
711711 pauseFactor = (
712- 0 if pf_slider == 0 else round (PAUSE_FACTOR_SCALE * math .pow (PAUSE_FACTOR_LOG_BASE , pf_slider ))
712+ 0 if pfSlider == 0 else round (PAUSE_FACTOR_SCALE * math .pow (PAUSE_FACTOR_LOG_BASE , pfSlider ))
713713 )
714714 text = _ (
715715 # Translators: this is a test string that is spoken. Only translate "the fraction with numerator"
0 commit comments