NSoiffer / MathCATForPython

A Python Interface and NVDA plugin to MathCAT
MIT License
6 stars 6 forks source link

Bad value in prefs.yaml causes MathCAT settings to fail #17

Closed NSoiffer closed 2 years ago

NSoiffer commented 2 years ago

If someone manually edits the yaml file and enters some incorrect value, the dialog has an error on startup and won't popup.

In the case below, I edited the file to set NavVerbosity to Full (should have been Verbose):

ERROR - unhandled exception (12:46:24.767) - MainThread (11892):
Traceback (most recent call last):
  File "C:\Users\neils\AppData\Roaming\nvda\addons\MathCAT\globalPlugins\MathCAT\__init__.py", line 36, in on_settings
    mainFrame._popupSettingsDialog(UserInterface)
  File "gui\__init__.pyc", line 163, in _popupSettingsDialog
  File "C:\Users\neils\AppData\Roaming\nvda\addons\MathCAT\globalPlugins\MathCAT\MathCATPreferences.py", line 57, in __init__
    UserInterface.set_ui_values(self)
  File "C:\Users\neils\AppData\Roaming\nvda\addons\MathCAT\globalPlugins\MathCAT\MathCATPreferences.py", line 104, in set_ui_values
    self.m_choiceSpeechAmountNavigation.SetSelection(Navigation_NavVerbosity.index(user_preferences["Navigation"]["NavVerbosity"]))
ValueError: tuple.index(x): x not in tuple

The code should be more tolerant of errors.

NSoiffer commented 2 years ago

Also, I just notice that NavVerbosity actually has Fullin two spots -- those should be "Verbose". One is in MathCATgui.ftp and the other in the generated file MathCATgui.py

ways2read commented 2 years ago

I have a function that will validate the values and use default values if not. This means the dialog will continue if invalid values are entered in the yaml file, if the tags are changed or deleted, or if the preferences files are deleted or corrupt.

Before I put this in a PR, need to check:

NSoiffer commented 2 years ago

Math rate can be any positive number. But realistically, an integer between 1 and 300 is all that should be accepted. Even those outer values don't make a lot of sense. If you want to restrict it to 20 - 200, that is fine with me.

On Sat, Mar 26, 2022, 3:12 PM Richard Orme @.***> wrote:

I have a function that will validate the values and use default values if not. This means the dialog will continue if invalid values are entered in the yaml file, if the tags are changed or deleted, or if the preferences files are deleted or corrupt.

Before I put this in a PR, need to check:

  • what are the valid values for NavVerbosity
  • what are the valid values for MathRate

— Reply to this email directly, view it on GitHub https://github.com/NSoiffer/MathCATForPython/issues/17#issuecomment-1079784602, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALZM3EZ4WNY7OFVY7UVA6LVB6DVBANCNFSM5RO74WIQ . You are receiving this because you authored the thread.Message ID: @.***>