1616}
1717
1818
19+ class PipeArrow (QtWidgets .QGraphicsPolygonItem ):
20+ """
21+ Base pipe arrow item for indicating pipe direction.
22+ """
23+
24+ def __init__ (self , parent = None , size = 5.0 ):
25+ super (PipeArrow , self ).__init__ (parent )
26+ self .set_size (size )
27+
28+ def set_size (self , size = 5.0 ):
29+ triangle = QtGui .QPolygonF ()
30+ triangle .append (QtCore .QPointF (- size , size ))
31+ triangle .append (QtCore .QPointF (0.0 , - size ))
32+ triangle .append (QtCore .QPointF (size , size ))
33+ self .setPolygon (triangle )
34+
35+
1936class Pipe (QtWidgets .QGraphicsPathItem ):
2037 """
2138 Base Pipe item used for drawing node connections.
@@ -31,6 +48,8 @@ def __init__(self, input_port=None, output_port=None):
3148 self ._highlight = False
3249 self ._input_port = input_port
3350 self ._output_port = output_port
51+ self .__arrow = PipeArrow (self )
52+ self .reset ()
3453
3554 def __str__ (self ):
3655 in_name = self ._input_port .name if self ._input_port else ''
@@ -137,7 +156,7 @@ def draw_path(self, start_port, end_port, cursor_pos=None):
137156 if start_port .port_type == IN_PORT :
138157 ctr_offset_x1 -= tangent
139158 ctr_offset_x2 += tangent
140- elif start_port . port_type == OUT_PORT :
159+ else :
141160 ctr_offset_x1 += tangent
142161 ctr_offset_x2 -= tangent
143162
@@ -146,6 +165,14 @@ def draw_path(self, start_port, end_port, cursor_pos=None):
146165 path .cubicTo (ctr_point1 , ctr_point2 , pos2 )
147166 self .setPath (path )
148167
168+ # Draw Arrow
169+ loc_pt = self .path ().pointAtPercent (0.49 )
170+ tgt_pt = self .path ().pointAtPercent (0.51 )
171+ radians = math .atan2 (tgt_pt .y () - loc_pt .y (), tgt_pt .x () - loc_pt .x ())
172+ degrees = math .degrees (radians ) - 90
173+ self .__arrow .setPos (self .path ().pointAtPercent (0.5 ))
174+ self .__arrow .setRotation (degrees )
175+
149176 def calc_distance (self , p1 , p2 ):
150177 x = math .pow ((p2 .x () - p1 .x ()), 2 )
151178 y = math .pow ((p2 .y () - p1 .y ()), 2 )
@@ -169,28 +196,34 @@ def viewer_pipe_layout(self):
169196
170197 def activate (self ):
171198 self ._active = True
172- pen = QtGui .QPen ( QtGui . QColor (* PIPE_ACTIVE_COLOR ), 2 )
173- pen . setStyle ( PIPE_STYLES .get (PIPE_STYLE_DEFAULT ))
199+ color = QtGui .QColor (* PIPE_ACTIVE_COLOR )
200+ pen = QtGui . QPen ( color , 2 , PIPE_STYLES .get (PIPE_STYLE_DEFAULT ))
174201 self .setPen (pen )
202+ self .__arrow .setBrush (QtGui .QBrush (color .darker (200 )))
203+ self .__arrow .setPen (QtGui .QPen (color , 0.8 ))
175204
176205 def active (self ):
177206 return self ._active
178207
179208 def highlight (self ):
180209 self ._highlight = True
181- pen = QtGui .QPen ( QtGui . QColor (* PIPE_HIGHLIGHT_COLOR ), 2 )
182- pen . setStyle ( PIPE_STYLES .get (PIPE_STYLE_DEFAULT ))
210+ color = QtGui .QColor (* PIPE_HIGHLIGHT_COLOR )
211+ pen = QtGui . QPen ( color , 2 , PIPE_STYLES .get (PIPE_STYLE_DEFAULT ))
183212 self .setPen (pen )
213+ self .__arrow .setBrush (QtGui .QBrush (color .darker (200 )))
214+ self .__arrow .setPen (QtGui .QPen (color , 0.8 ))
184215
185216 def highlighted (self ):
186217 return self ._highlight
187218
188219 def reset (self ):
189220 self ._active = False
190221 self ._highlight = False
191- pen = QtGui .QPen ( QtGui . QColor (* self .color ), 2 )
192- pen . setStyle ( PIPE_STYLES .get (self .style ))
222+ color = QtGui .QColor (* self .color )
223+ pen = QtGui . QPen ( color , 2 , PIPE_STYLES .get (self .style ))
193224 self .setPen (pen )
225+ self .__arrow .setBrush (QtGui .QBrush (color .darker (130 )))
226+ self .__arrow .setPen (QtGui .QPen (color , 0.6 ))
194227
195228 def set_connections (self , port1 , port2 ):
196229 ports = {
0 commit comments