• 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

61.26
/trnsysGUI/segments/segmentItemBase.py
1
from __future__ import annotations
1✔
2

3
import math as _math
1✔
4
import typing as _tp
1✔
5

6
import PyQt5.QtCore as _qtc
1✔
7
import PyQt5.QtGui as _qtg
1✔
8
import PyQt5.QtWidgets as _qtw
1✔
9

10
import trnsysGUI.cornerItem as _ci
1✔
11
import trnsysGUI.segments.node as _node
1✔
12

13
# This is needed to avoid a circular import but still be able to type check
14
if _tp.TYPE_CHECKING:
1✔
15
    import trnsysGUI.connection.connectionBase as _cib
×
16

17

18
def calcDist(p1, p2):
1✔
19
    vec = p1 - p2
×
20
    norm = _math.sqrt(vec.x() ** 2 + vec.y() ** 2)
×
21
    return norm
×
22

23

24
class SegmentItemBase(_qtw.QGraphicsItemGroup):
1✔
25
    def __init__(
1✔
26
        self,
27
        startNode: _node.Node,
28
        endNode: _node.Node,
29
        parent: _cib.ConnectionBase,
30
    ) -> None:
31
        """
32
        A connection is displayed as a chain of segmentItems (stored in Connection.segments)
33
        Parameters.
34
        ----------
35
        startNode
36
        endNode
37
        parent: type(parent): Connection
38
        """
39

40
        super().__init__(parent=parent)
1✔
41
        self.logger = parent.logger
1✔
42

43
        self.setFlag(self.ItemIsSelectable, True)
1✔
44

45
        self.connection = parent
1✔
46

47
        self.linePoints = _qtc.QLineF()
1✔
48

49
        self.startNode = startNode
1✔
50
        self.endNode = endNode
1✔
51

52
        self._insertIntoParentSegments()
1✔
53

54
        self.setToolTip(self.connection.displayName)
1✔
55

56
    def setEndNode(self, newEndNode) -> None:
1✔
57
        self.endNode = newEndNode
×
58
        self.endNode.setPrev(self.startNode)
×
59
        self.startNode.setNext(self.endNode)
×
60

61
    def line(self) -> _qtc.QLineF:
1✔
62
        return self.linePoints
1✔
63

64
    def setLine(self, *args):
1✔
65
        self.setZValue(-1)
1✔
66
        if len(args) == 2:
1✔
67
            p1, p2 = args
1✔
68
            x1 = p1.x()
1✔
69
            y1 = p1.y()
1✔
70
            x2 = p2.x()
1✔
71
            y2 = p2.y()
1✔
72
        else:
73
            x1, y1, x2, y2 = args
1✔
74

75
        self._setLineImpl(x1, y1, x2, y2)
1✔
76

77
    def _setLineImpl(self, x1, y1, x2, y2):
1✔
78
        raise NotImplementedError()
79

80
    def _insertIntoParentSegments(self):
1✔
81
        """
82
        This function inserts the segment in correct order to the segment list of the connection.
83
        Returns
84
        -------
85

86
        """
87
        previousSegment = None
1✔
88

89
        for segment in self.connection.segments:
1✔
90
            if segment.endNode is self.startNode:
1✔
91
                previousSegment = segment
1✔
92

93
        if hasattr(self.startNode.parent, "fromPort"):
1✔
94
            self.connection.segments.insert(0, self)
1✔
95
            return
1✔
96

97
        self.connection.segments.insert(
1✔
98
            self.connection.segments.index(previousSegment) + 1, self
99
        )
100

101
    def isIntermediateSegment(self) -> bool:
1✔
NEW
102
        return isinstance(
×
103
            self.startNode.parent, _ci.CornerItem
104
        ) and isinstance(self.endNode.parent, _ci.CornerItem)
105

106
    def isFirstOrLastSegment(self) -> bool:
1✔
107
        isFirstSegment = self.isFirstSegment()
×
108
        isLastSegment = self.isLastSegment()
×
109
        isFirstOrLastSegment = isFirstSegment or isLastSegment
×
110
        return isFirstOrLastSegment
×
111

112
    def isFirstSegment(self) -> bool:
1✔
NEW
113
        isFirstSegment = (
×
114
            hasattr(self.startNode.parent, "fromPort")
115
            and not self.startNode.prevN()
116
        )
UNCOV
117
        return isFirstSegment
×
118

119
    def isLastSegment(self) -> bool:
1✔
NEW
120
        isLastSegment = (
×
121
            hasattr(self.endNode.parent, "fromPort")
122
            and not self.endNode.nextN()
123
        )
UNCOV
124
        return isLastSegment
×
125

126
    def isVertical(self) -> bool:
1✔
127
        return self.line().p1().x() == self.line().p2().x()
×
128

129
    def isHorizontal(self) -> bool:
1✔
130
        return self.line().p1().y() == self.line().p2().y()
1✔
131

132
    def isZeroLength(self) -> bool:
1✔
133
        return self.line().isNull()
×
134

135
    def renameConn(self):
1✔
136
        self.connection.parent.showSegmentDlg(self)
×
137

138
    def contextMenuEvent(self, event):
1✔
139
        menu = self._getContextMenu()
×
140

141
        menu.exec(event.screenPos())
×
142

143
    def _getContextMenu(self) -> _qtw.QMenu:
1✔
144
        menu = _qtw.QMenu()
×
145
        a1 = menu.addAction("Rename...")
×
146
        a1.triggered.connect(self.renameConn)
×
147
        a2 = menu.addAction("Delete this connection")
×
NEW
148
        a2.triggered.connect(
×
149
            self.connection.createDeleteUndoCommandAndAddToStack
150
        )
151
        a3 = menu.addAction("Invert this connection")
×
152
        a3.triggered.connect(self.connection.invertConnection)
×
153
        a4 = menu.addAction("Toggle name")
×
154
        a4.triggered.connect(self.connection.toggleLabelVisible)
×
155
        a5 = menu.addAction("Toggle mass flow")
×
156
        a5.triggered.connect(self.connection.toggleMassFlowLabelVisible)
×
157
        return menu
×
158

159
    def setColorAndWidthAccordingToMassflow(self, color, width):
1✔
160
        raise NotImplementedError()
161

162
    def resetLinePens(self) -> None:
1✔
163
        if self.connection.isConnectionSelected:
1✔
164
            self._setSelectedLinesPen()
×
165
        else:
166
            self._setStandardLinesPens()
1✔
167

168
    def _setStandardLinesPens(self):
1✔
169
        raise NotImplementedError()
170

171
    def _setSelectedLinesPen(self):
1✔
172
        raise NotImplementedError()
173

174
    def _createSelectedLinesPen(self) -> _qtg.QPen:
1✔
175
        color = _qtg.QColor(125, 242, 189)
×
176
        width = 4
×
177

178
        selectPen = _qtg.QPen(color, width)
×
179

180
        if not self.connection.shallBeSimulated:
×
181
            selectPen.setStyle(_qtc.Qt.DashLine)
×
182

183
        return selectPen
×
184

185
    @_tp.override
1✔
186
    def mousePressEvent(self, event: _qtw.QGraphicsSceneMouseEvent) -> None:
1✔
187
        self.connection.onMousePressed(self, event)
×
188

189
    @_tp.override
1✔
190
    def mouseMoveEvent(self, event: _qtw.QGraphicsSceneMouseEvent) -> None:
1✔
191
        self.connection.onMouseMoved(event)
×
192

193
    @_tp.override
1✔
194
    def mouseReleaseEvent(self, event: _qtw.QGraphicsSceneMouseEvent) -> None:
1✔
195
        self.connection.onMouseReleased(event)
×
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