yayachiken / PyMorsetrainer

Simple Morsetrainer written in Python for the Koch method with Farnsworth timing.
GNU General Public License v3.0
5 stars 2 forks source link

Fails on OSX due to Qsettings.allKeys() behavior #3

Open KM4YRI opened 3 years ago

KM4YRI commented 3 years ago

Gives the following error on a clean install, in OSX:

Traceback (most recent call last):
  File "/usr/local/bin/pymorsetrainer", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/site-packages/pymorsetrainer/__main__.py", line 28, in main
    mw = MainWindow()
  File "/usr/local/lib/python3.8/site-packages/pymorsetrainer/pymorsetrainer.py", line 53, in __init__
    self.initUI()
  File "/usr/local/lib/python3.8/site-packages/pymorsetrainer/pymorsetrainer.py", line 98, in initUI
    lessonCombo.setCurrentIndex(int(self.settings.value("currentLesson"))-1)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

This is an OSX quirk. self.settings.allKeys() will always return truthy on OSX, even on the first startup. OSX shoves in all sorts of parameters like com/apple/trackpad/twoFingerDoubleTapGesture and com/apple/TimeZonePref/Last_Selected_City. And in your case, the settings.setValue() calls never get called. A proposed fix would be to test if any of those five values return None, and if so, write them.