Skip to content
Snippets Groups Projects
sohstationviewer.py 1.84 KiB
Newer Older
Lan Dam's avatar
Lan Dam committed
#!/usr/bin/env python3
import platform
import os
import traceback

Lan Dam's avatar
Lan Dam committed
from PySide6 import QtWidgets
from PySide6.QtWidgets import QMessageBox, QErrorMessage
from sohstationviewer.view.main_window import MainWindow
from sohstationviewer.conf.config_processor import (
    ConfigProcessor,
    BadConfigError,
)
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)
Lan Dam's avatar
Lan Dam committed
    sys.exit(app.exec())