Newer
Older
Garrett Bates
committed
import sys
from PySide2 import QtWidgets
from PySide2.QtWidgets import QMessageBox
from sohstationviewer.view.main_window import MainWindow
from sohstationviewer.conf.config_processor import (
ConfigProcessor,
BadConfigError,
)
Garrett Bates
committed
# Enable Layer-backing for MacOs version >= 11
# Only needed if using the pyside2 library with version>=5.15.
# Layer-backing is always enabled in pyside6.
os_name, version, *_ = platform.platform().split('-')
# if os_name == 'macOS' and version >= '11':
# mac OSX 11.6 appear to be 10.16 when read with python and still required this
# environment variable
if os_name == 'macOS':
os.environ['QT_MAC_WANTS_LAYER'] = '1'
Garrett Bates
committed
def main():
app = QtWidgets.QApplication(sys.argv)
wnd = MainWindow()
config = ConfigProcessor()
config.load_config()
need_reset = False
try:
config.validate_config()
config.apply_config(wnd)
except (BadConfigError, ValueError) as e:
bad_config_dialog = QMessageBox()
bad_config_dialog.setText('Something went wrong when reading the '
'config.')
bad_config_dialog.setDetailedText(traceback.format_exc())
bad_config_dialog.setInformativeText('Do you want to reset the config '
'file?')
bad_config_dialog.setStandardButtons(QMessageBox.Ok |
QMessageBox.Close)
bad_config_dialog.setDefaultButton(QMessageBox.Ok)
bad_config_dialog.setIcon(QMessageBox.Critical)
reset_choice = bad_config_dialog.exec_()
if reset_choice == QMessageBox.Ok:
need_reset = True
else:
sys.exit(1)
if need_reset:
try:
config.reset()
except OSError:
QMessageBox.critical(None, 'Cannot reset config',
'Config file cannot be reset. Please '
'ensure that it is not opened in another '
'program.',
QMessageBox.Close)
sys.exit(1)
config.apply_config(wnd)
Garrett Bates
committed
wnd.show()
Garrett Bates
committed
Garrett Bates
committed
if __name__ == '__main__':
main()