• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SPF-OST / pytrnsys_gui / 16883947425

11 Aug 2025 03:03PM UTC coverage: 67.786% (-0.07%) from 67.858%
16883947425

push

github

web-flow
Merge pull request #602 from SPF-OST/crash-without-settings

Don't crash if no settings available.

16 of 45 new or added lines in 5 files covered. (35.56%)

9 existing lines in 4 files now uncovered.

10460 of 15431 relevant lines covered (67.79%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/trnsysGUI/gui.py
NEW
1
from __future__ import annotations
×
2

3
import logging as _log
×
4
import pathlib as _pl
×
5
import sys as _sys
×
NEW
6
import typing as _tp
×
7

8
import PyQt5.QtWidgets as _qtw
×
9

10
import pytrnsys.utils.log as _ulog
×
11
import pytrnsys.utils.result as _res
×
12
import trnsysGUI.arguments as _args
×
13
import trnsysGUI.setup as _setup
×
14
import trnsysGUI.warningsAndErrors as _werrors
×
15

16
if _tp.TYPE_CHECKING:
17
    import trnsysGUI.project as _prj  # pylint: disable=import-outside-toplevel
18

19

NEW
20
def main() -> None:
×
21
    arguments = _args.getArgsOrExit()
×
22

23
    logFilePath = _getLogFilePath()
×
24
    logger = _ulog.getOrCreateCustomLogger(
×
25
        "root", arguments.logLevel, logFilePath
26
    )
27

28
    _registerExceptionHook(logger)
×
29

30
    result = _setup.setup()
×
31
    errorMessage = _res.error(result).message if _res.isError(result) else None
×
32
    if errorMessage:
×
33
        logger.error(errorMessage)
×
34

35
    app = _qtw.QApplication(_sys.argv)
×
36
    app.setApplicationName("Diagram Creator")
×
37

38
    if errorMessage:
×
39
        _werrors.showMessageBox(errorMessage, title="Missing requirements")
×
40
        return
×
41

42
    import trnsysGUI.common.cancelled as _ccl  # pylint: disable=import-outside-toplevel
×
43
    import trnsysGUI.project as _prj  # pylint: disable=import-outside-toplevel
×
NEW
44
    import trnsysGUI.settingsDlg as _sdlg  # pylint: disable=import-outside-toplevel
×
45

NEW
46
    _sdlg.ensureSettingsExist()
×
47

48
    maybeCancelled = _prj.getProject()
×
49
    if _ccl.isCancelled(maybeCancelled):
×
50
        return
×
51

52
    # mypy issue: https://github.com/python/mypy/issues/19640#issuecomment-3174819987
NEW
53
    project: _prj.Project = _ccl.value(maybeCancelled)  # type: ignore[assignment]
×
54

NEW
55
    _createAndShowMainWindow(app, project, logger, arguments.shallTrace)
×
56

57

NEW
58
def _createAndShowMainWindow(
×
59
    app: _qtw.QApplication,
60
    project: _prj.Project,
61
    logger: _log.Logger,
62
    shallTrace: bool,
63
) -> None:
UNCOV
64
    import trnsysGUI.mainWindow as _mw  # pylint: disable=import-outside-toplevel
×
NEW
65
    import trnsysGUI.tracing as trc  # pylint: disable=import-outside-toplevel
×
66

NEW
67
    mainWindow = _mw.MainWindow(logger, project)  # type: ignore[attr-defined]
×
68
    mainWindow.start()
×
69

70
    def _shutdownMainWindowIfRunning() -> None:
×
71
        if mainWindow.isRunning():
×
72
            mainWindow.shutdown()
×
73

74
    app.aboutToQuit.connect(_shutdownMainWindowIfRunning)
×
UNCOV
75
    try:
×
76
        mainWindow.showMaximized()
×
77
        mainWindow.loadTrnsysPath()
×
78

NEW
79
        tracer = trc.createTracer(shallTrace)
×
UNCOV
80
        tracer.run(app.exec)
×
81
    finally:
82
        _shutdownMainWindowIfRunning()
×
83

84

85
def _getLogFilePath():
×
86
    return _pl.Path("pytrnsys-gui.log").absolute()
×
87

88

89
def _registerExceptionHook(logger: _log.Logger) -> None:
×
90
    def exceptionHook(exceptionType, value, traceback):
×
91
        logger.critical(
×
92
            "Uncaught exception", exc_info=(exceptionType, value, traceback)
93
        )
94

95
        for handler in logger.handlers:
×
96
            handler.flush()
×
97

98
        _sys.exit(-1)
×
99

100
    _sys.excepthook = exceptionHook
×
101

102

103
if __name__ == "__main__":
×
104
    main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc