44from Qt import QtCore , QtGui , QtWidgets
55
66from NodeGraphQt .constants import (
7- PIPE_DEFAULT_COLOR , PIPE_ACTIVE_COLOR ,
8- PIPE_HIGHLIGHT_COLOR , PIPE_DISABLED_COLOR ,
9- PIPE_STYLE_DASHED , PIPE_STYLE_DEFAULT , PIPE_STYLE_DOTTED ,
10- PIPE_LAYOUT_STRAIGHT , PIPE_WIDTH , IN_PORT , OUT_PORT , Z_VAL_PIPE ,
7+ PIPE_STYLING , PIPE_LAYOUT , IN_PORT , OUT_PORT , Z_VAL_PIPE ,
118 Z_VAL_NODE_WIDGET ,
12- PIPE_LAYOUT_ANGLE , PIPE_LAYOUT_CURVED ,
139 ITEM_CACHE_MODE ,
1410 NODE_LAYOUT_VERTICAL , NODE_LAYOUT_HORIZONTAL ,
15- NODE_LAYOUT_DIRECTION )
11+ NODE_LAYOUT_DIRECTION
12+ )
1613from NodeGraphQt .qgraphics .port import PortItem
1714
1815PIPE_STYLES = {
19- PIPE_STYLE_DEFAULT : QtCore .Qt .SolidLine ,
20- PIPE_STYLE_DASHED : QtCore .Qt .DashLine ,
21- PIPE_STYLE_DOTTED : QtCore .Qt .DotLine
16+ PIPE_STYLING . DRAW_TYPE_DEFAULT . value : QtCore .Qt .SolidLine ,
17+ PIPE_STYLING . DRAW_TYPE_DASHED . value : QtCore .Qt .DashLine ,
18+ PIPE_STYLING . DRAW_TYPE_DOTTED . value : QtCore .Qt .DotLine
2219}
2320
2421
@@ -32,8 +29,8 @@ def __init__(self, input_port=None, output_port=None):
3229 self .setZValue (Z_VAL_PIPE )
3330 self .setAcceptHoverEvents (True )
3431 self .setFlag (QtWidgets .QGraphicsItem .ItemIsSelectable )
35- self ._color = PIPE_DEFAULT_COLOR
36- self ._style = PIPE_STYLE_DEFAULT
32+ self ._color = PIPE_STYLING . COLOR . value
33+ self ._style = PIPE_STYLING . DRAW_TYPE_DEFAULT . value
3734 self ._active = False
3835 self ._highlight = False
3936 self ._input_port = input_port
@@ -76,22 +73,22 @@ def paint(self, painter, option, widget):
7673 """
7774 color = QtGui .QColor (* self ._color )
7875 pen_style = PIPE_STYLES .get (self .style )
79- pen_width = PIPE_WIDTH
76+ pen_width = PIPE_STYLING . WIDTH . value
8077 if self ._active :
81- color = QtGui .QColor (* PIPE_ACTIVE_COLOR )
78+ color = QtGui .QColor (* PIPE_STYLING . ACTIVE_COLOR . value )
8279 if pen_style == QtCore .Qt .DashDotDotLine :
8380 pen_width += 1
8481 else :
8582 pen_width += 0.35
8683 elif self ._highlight :
87- color = QtGui .QColor (* PIPE_HIGHLIGHT_COLOR )
88- pen_style = PIPE_STYLES .get (PIPE_STYLE_DEFAULT )
84+ color = QtGui .QColor (* PIPE_STYLING . HIGHLIGHT_COLOR . value )
85+ pen_style = PIPE_STYLES .get (PIPE_STYLING . DRAW_TYPE_DEFAULT . value )
8986
9087 if self .disabled ():
9188 if not self ._active :
92- color = QtGui .QColor (* PIPE_DISABLED_COLOR )
89+ color = QtGui .QColor (* PIPE_STYLING . DISABLED_COLOR . value )
9390 pen_width += 0.2
94- pen_style = PIPE_STYLES .get (PIPE_STYLE_DOTTED )
91+ pen_style = PIPE_STYLES .get (PIPE_STYLING . DRAW_TYPE_DOTTED . value )
9592
9693 pen = QtGui .QPen (color , pen_width , pen_style )
9794 pen .setCapStyle (QtCore .Qt .RoundCap )
@@ -154,7 +151,7 @@ def __draw_path_vertical(self, start_port, pos1, pos2, path):
154151 pos2 (QPointF): end port position.
155152 path (QPainterPath): path to draw.
156153 """
157- if self .viewer_pipe_layout () == PIPE_LAYOUT_CURVED :
154+ if self .viewer_pipe_layout () == PIPE_LAYOUT . CURVED . value :
158155 ctr_offset_y1 , ctr_offset_y2 = pos1 .y (), pos2 .y ()
159156 tangent = abs (ctr_offset_y1 - ctr_offset_y2 )
160157
@@ -171,7 +168,7 @@ def __draw_path_vertical(self, start_port, pos1, pos2, path):
171168 ctr_point2 = QtCore .QPointF (pos2 .x (), ctr_offset_y2 )
172169 path .cubicTo (ctr_point1 , ctr_point2 , pos2 )
173170 self .setPath (path )
174- elif self .viewer_pipe_layout () == PIPE_LAYOUT_ANGLE :
171+ elif self .viewer_pipe_layout () == PIPE_LAYOUT . ANGLE . value :
175172 ctr_offset_y1 , ctr_offset_y2 = pos1 .y (), pos2 .y ()
176173 distance = abs (ctr_offset_y1 - ctr_offset_y2 )/ 2
177174 if start_port .port_type == IN_PORT :
@@ -198,7 +195,7 @@ def __draw_path_horizontal(self, start_port, pos1, pos2, path):
198195 pos2 (QPointF): end port position.
199196 path (QPainterPath): path to draw.
200197 """
201- if self .viewer_pipe_layout () == PIPE_LAYOUT_CURVED :
198+ if self .viewer_pipe_layout () == PIPE_LAYOUT . CURVED . value :
202199 ctr_offset_x1 , ctr_offset_x2 = pos1 .x (), pos2 .x ()
203200 tangent = abs (ctr_offset_x1 - ctr_offset_x2 )
204201
@@ -215,7 +212,7 @@ def __draw_path_horizontal(self, start_port, pos1, pos2, path):
215212 ctr_point2 = QtCore .QPointF (ctr_offset_x2 , pos2 .y ())
216213 path .cubicTo (ctr_point1 , ctr_point2 , pos2 )
217214 self .setPath (path )
218- elif self .viewer_pipe_layout () == PIPE_LAYOUT_ANGLE :
215+ elif self .viewer_pipe_layout () == PIPE_LAYOUT . ANGLE . value :
219216 ctr_offset_x1 , ctr_offset_x2 = pos1 .x (), pos2 .x ()
220217 distance = abs (ctr_offset_x1 - ctr_offset_x2 ) / 2
221218 if start_port .port_type == IN_PORT :
@@ -260,7 +257,7 @@ def draw_path(self, start_port, end_port=None, cursor_pos=None):
260257 path = QtGui .QPainterPath ()
261258 path .moveTo (line .x1 (), line .y1 ())
262259
263- if self .viewer_pipe_layout () == PIPE_LAYOUT_STRAIGHT :
260+ if self .viewer_pipe_layout () == PIPE_LAYOUT . STRAIGHT . value :
264261 path .lineTo (pos2 )
265262 self .setPath (path )
266263 return
@@ -298,17 +295,21 @@ def viewer_pipe_layout(self):
298295
299296 def activate (self ):
300297 self ._active = True
301- color = QtGui .QColor (* PIPE_ACTIVE_COLOR )
302- pen = QtGui .QPen (color , 2.5 , PIPE_STYLES .get (PIPE_STYLE_DEFAULT ))
298+ color = QtGui .QColor (* PIPE_STYLING .ACTIVE_COLOR .value )
299+ pen = QtGui .QPen (
300+ color , 2.5 , PIPE_STYLES .get (PIPE_STYLING .DRAW_TYPE_DEFAULT .value )
301+ )
303302 self .setPen (pen )
304303
305304 def active (self ):
306305 return self ._active
307306
308307 def highlight (self ):
309308 self ._highlight = True
310- color = QtGui .QColor (* PIPE_HIGHLIGHT_COLOR )
311- pen = QtGui .QPen (color , 2 , PIPE_STYLES .get (PIPE_STYLE_DEFAULT ))
309+ color = QtGui .QColor (* PIPE_STYLING .HIGHLIGHT_COLOR .value )
310+ pen = QtGui .QPen (
311+ color , 2 , PIPE_STYLES .get (PIPE_STYLING .DRAW_TYPE_DEFAULT .value )
312+ )
312313 self .setPen (pen )
313314
314315 def highlighted (self ):
@@ -409,9 +410,9 @@ def paint(self, painter, option, widget):
409410 used to describe the parameters needed to draw.
410411 widget (QtWidgets.QWidget): not used.
411412 """
412- color = QtGui .QColor (* PIPE_ACTIVE_COLOR )
413- pen_style = PIPE_STYLES .get (PIPE_STYLE_DASHED )
414- pen_width = PIPE_WIDTH + 0.35
413+ color = QtGui .QColor (* PIPE_STYLING . ACTIVE_COLOR . value )
414+ pen_style = PIPE_STYLES .get (PIPE_STYLING . DRAW_TYPE_DASHED . value )
415+ pen_width = PIPE_STYLING . WIDTH . value + 0.35
415416
416417 pen = QtGui .QPen (color , pen_width )
417418 pen .setStyle (pen_style )
0 commit comments