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

SPF-OST / pytrnsys_gui / 11662562960

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

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

47.17
/trnsysGUI/diagram/fileSystemTreeView.py
1
import os as _os
1✔
2
import pathlib as _pl
1✔
3

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

8
import trnsysGUI.internalPiping as _ip
1✔
9
import trnsysGUI.loadDdckFile as _ld
1✔
10
import trnsysGUI.warningsAndErrors as _warn
1✔
11

12

13
class FileSystemTreeView(_qtw.QTreeView):
1✔
14
    def __init__(
1✔
15
        self,
16
        rootDirPath: _pl.Path,
17
        hasInternalPipingsProvider: _ip.HasInternalPipingsProvider,
18
    ) -> None:
19
        super().__init__(parent=None)
1✔
20

21
        self._ddckLoader = _ld.DdckFileLoader(hasInternalPipingsProvider)
1✔
22

23
        rootFolder = str(rootDirPath)
1✔
24

25
        self._model = _qtw.QFileSystemModel()
1✔
26
        self._model.setRootPath(rootFolder)
1✔
27

28
        self.setModel(self._model)
1✔
29

30
        rootModelIndex = self._model.index(rootFolder)
1✔
31
        self.setRootIndex(rootModelIndex)
1✔
32

33
    def mouseDoubleClickEvent(  # pylint: disable=unused-argument
1✔
34
        self, event: _qtg.QMouseEvent
35
    ) -> None:
UNCOV
36
        self._openCurrentFileOrNoOp()
×
37

38
    def contextMenuEvent(self, event):
1✔
39
        menu = _qtw.QMenu()
×
40

41
        load = menu.addAction("Load")
×
42
        load.triggered.connect(self._loadFileIntoFolder)
×
43

44
        delete = menu.addAction("Delete")
×
45
        delete.triggered.connect(self._deleteCurrentFile)
×
46

47
        menu.exec(event.globalPos())
×
48

49
    def _openCurrentFileOrNoOp(self) -> None:
1✔
50
        path = self._getCurrentPath()
×
51
        if not path.is_file():
×
52
            return
×
53

54
        try:
×
55
            _os.startfile(path)
×
56
        except OSError:
×
NEW
57
            _warn.showMessageBox(
×
58
                "Could not open file {path}: no program is associated with its file type."
59
            )
60

61
    def _loadFileIntoFolder(self) -> None:
1✔
62
        currentPath = self._getCurrentPath()
×
NEW
63
        targetDirPath = (
×
64
            currentPath if currentPath.is_dir() else currentPath.parent
65
        )
UNCOV
66
        self._ddckLoader.loadDdckFile(targetDirPath)
×
67

68
    def _deleteCurrentFile(self) -> None:
1✔
69
        path = self._getCurrentPath()
×
70
        if path.is_dir():
×
71
            return
×
72

73
        try:
×
74
            path.unlink()
×
75
        except OSError as error:
×
76
            _warn.showMessageBox(f"Could not delete file `{path}`: {error}.")
×
77

78
    def _getCurrentPath(self) -> _pl.Path:
1✔
79
        index = self.currentIndex()
×
80
        return self._getPath(index)
×
81

82
    def _getPath(self, index: _qtc.QModelIndex) -> _pl.Path:
1✔
83
        filePathString = self._model.filePath(index)
×
84
        return _pl.Path(filePathString)
×
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