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

SPF-OST / pytrnsys_gui / 11576810878

29 Oct 2024 03:09PM UTC coverage: 67.508% (-0.08%) from 67.591%
11576810878

push

github

web-flow
Merge pull request #564 from SPF-OST/560-black-change-line-length-to-pep8-standard-of-79-and-check-ci-reaction

changed line length in black to 79

1054 of 1475 new or added lines in 174 files covered. (71.46%)

150 existing lines in 74 files now uncovered.

10399 of 15404 relevant lines covered (67.51%)

0.68 hits per line

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

82.61
/trnsysGUI/dialogs/startupDialog.py
1
import pathlib as _pl
1✔
2

3
import PyQt5.QtCore as _qtc
1✔
4
import PyQt5.QtGui as _qtg
1✔
5
import PyQt5.QtWidgets as _qtw
1✔
6

7
import trnsysGUI.common.cancelled as _ccl
1✔
8
import trnsysGUI.dialogs._UI_startupDialog_generated as _gen
1✔
9
from trnsysGUI import constants
1✔
10
from trnsysGUI.recentProjectsHandler import RecentProjectsHandler
1✔
11

12

13
class StartupDialog(_qtw.QDialog, _gen.Ui_startupDialog):
1✔
14
    signal: _ccl.MaybeCancelled[constants.CreateNewOrOpenExisting | _pl.Path]
1✔
15

16
    def __init__(self) -> None:
1✔
17
        super().__init__()
1✔
18
        self.setupUi(self)
1✔
19
        self.buttonGroup.buttonClicked.connect(self.clickButtonHandler)
1✔
20
        # ===============================================================================
21
        # Must be monospaced font to ensure paths align nicely.
22
        self.listWidget.setFont(_qtg.QFont(constants.DEFAULT_MONOSPACED_FONT))
1✔
23
        # ===============================================================================
24
        self.listWidget.itemDoubleClicked.connect(self.clickButtonHandler)
1✔
25
        RecentProjectsHandler.initWithExistingRecentProjects()
1✔
26
        maxLength = RecentProjectsHandler.getLengthOfLongestFileName()
1✔
27
        for recentProject in RecentProjectsHandler.recentProjects:
1✔
28
            # Padding name to the longest name to nicely align paths.
29
            formattedFileName = recentProject.stem.ljust(maxLength)
1✔
30
            _qtw.QListWidgetItem(
1✔
31
                f"{formattedFileName} {recentProject}", self.listWidget
32
            ).setData(_qtc.Qt.UserRole, recentProject)
33
        self.adjustSizeToContent()
1✔
34

35
    def clickButtonHandler(self, clickedItem):
1✔
36
        if clickedItem is self.cancelButton:
1✔
37
            self.signal = _ccl.CANCELLED
×
38
        if clickedItem is self.createButton:
1✔
39
            self.signal = constants.CreateNewOrOpenExisting.CREATE_NEW
×
40
        if clickedItem is self.openButton:
1✔
41
            self.signal = constants.CreateNewOrOpenExisting.OPEN_EXISTING
×
42
        if isinstance(clickedItem, _qtw.QListWidgetItem):
1✔
43
            self.signal = clickedItem.data(_qtc.Qt.UserRole)
1✔
44
        self.close()
1✔
45

46
    def adjustSizeToContent(self):
1✔
47
        totalHeight = sum(
1✔
48
            self.listWidget.sizeHintForRow(i)
49
            for i in range(self.listWidget.count())
50
        )
51
        maxWidth = max(
1✔
52
            (
53
                self.listWidget.fontMetrics().width(
54
                    self.listWidget.item(i).text()
55
                )
56
                for i in range(self.listWidget.count())
57
            ),
58
            default=0,
59
        )
60

61
        if totalHeight <= 115 and maxWidth <= self.width():
1✔
62
            # Corresponds to minimum size of dialog.
63
            return
×
64

65
        if totalHeight > 115:
1✔
NEW
66
            self.listWidget.setFixedHeight(
×
67
                totalHeight + 2 * self.listWidget.frameWidth()
68
            )
69

70
        if maxWidth > self.width():
1✔
71
            self.listWidget.setFixedWidth(
1✔
72
                maxWidth + 2 * self.listWidget.frameWidth() + 20
73
            )
74

75
    @staticmethod
1✔
76
    def showDialogAndGetResult() -> (
1✔
77
        _ccl.MaybeCancelled[constants.CreateNewOrOpenExisting | _pl.Path]
78
    ):
79
        dialog = StartupDialog()
×
80
        dialog.exec()
×
81
        return dialog.signal
×
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