Skip to content

Commit 84853f4

Browse files
committed
Updated PORT constant vars to enums.
1 parent 66dfe98 commit 84853f4

File tree

11 files changed

+133
-97
lines changed

11 files changed

+133
-97
lines changed

NodeGraphQt/base/commands.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/python
22
from Qt import QtWidgets
33

4-
from NodeGraphQt.constants import IN_PORT, OUT_PORT
4+
from NodeGraphQt.constants import PORT_TYPE
55

66

77
class PropertyChangedCmd(QtWidgets.QUndoCommand):
@@ -158,7 +158,7 @@ class NodeInputConnectedCmd(QtWidgets.QUndoCommand):
158158

159159
def __init__(self, src_port, trg_port):
160160
QtWidgets.QUndoCommand.__init__(self)
161-
if src_port.type_() == IN_PORT:
161+
if src_port.type_() == PORT_TYPE.IN.value:
162162
self.source = src_port
163163
self.target = trg_port
164164
else:
@@ -185,7 +185,7 @@ class NodeInputDisconnectedCmd(QtWidgets.QUndoCommand):
185185

186186
def __init__(self, src_port, trg_port):
187187
QtWidgets.QUndoCommand.__init__(self)
188-
if src_port.type_() == IN_PORT:
188+
if src_port.type_() == PORT_TYPE.IN.value:
189189
self.source = src_port
190190
self.target = trg_port
191191
else:
@@ -355,9 +355,9 @@ def set_visible(self, visible):
355355
self.port.view.setVisible(visible)
356356
node_view = self.port.node().view
357357
text_item = None
358-
if self.port.type_() == IN_PORT:
358+
if self.port.type_() == PORT_TYPE.IN.value:
359359
text_item = node_view.get_input_text_item(self.port.view)
360-
elif self.port.type_() == OUT_PORT:
360+
elif self.port.type_() == PORT_TYPE.OUT.value:
361361
text_item = node_view.get_output_text_item(self.port.view)
362362
if text_item:
363363
text_item.setVisible(visible)

NodeGraphQt/base/graph.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
NODE_LAYOUT_DIRECTION, NODE_LAYOUT_HORIZONTAL, NODE_LAYOUT_VERTICAL,
2121
PIPE_LAYOUT,
2222
URI_SCHEME, URN_SCHEME,
23-
IN_PORT, OUT_PORT,
23+
PORT_TYPE,
2424
VIEWER_GRID_LINES
2525
)
2626
from NodeGraphQt.nodes.backdrop_node import BackdropNode
@@ -369,7 +369,7 @@ def _on_connection_changed(self, disconnected, connected):
369369
return
370370

371371
label = 'connect node(s)' if connected else 'disconnect node(s)'
372-
ptypes = {IN_PORT: 'inputs', OUT_PORT: 'outputs'}
372+
ptypes = {PORT_TYPE.IN.value: 'inputs', PORT_TYPE.OUT.value: 'outputs'}
373373

374374
self._undo_stack.beginMacro(label)
375375
for p1_view, p2_view in disconnected:
@@ -396,7 +396,7 @@ def _on_connection_sliced(self, ports):
396396
"""
397397
if not ports:
398398
return
399-
ptypes = {IN_PORT: 'inputs', OUT_PORT: 'outputs'}
399+
ptypes = {PORT_TYPE.IN.value: 'inputs', PORT_TYPE.OUT.value: 'outputs'}
400400
self._undo_stack.beginMacro('slice connections')
401401
for p1_view, p2_view in ports:
402402
node1 = self._model.nodes[p1_view.node.id]
@@ -1246,16 +1246,20 @@ def _serialize(self, nodes):
12461246
for pname, conn_data in inputs.items():
12471247
for conn_id, prt_names in conn_data.items():
12481248
for conn_prt in prt_names:
1249-
pipe = {IN_PORT: [n_id, pname],
1250-
OUT_PORT: [conn_id, conn_prt]}
1249+
pipe = {
1250+
PORT_TYPE.IN.value: [n_id, pname],
1251+
PORT_TYPE.OUT.value: [conn_id, conn_prt]
1252+
}
12511253
if pipe not in serial_data['connections']:
12521254
serial_data['connections'].append(pipe)
12531255

12541256
for pname, conn_data in outputs.items():
12551257
for conn_id, prt_names in conn_data.items():
12561258
for conn_prt in prt_names:
1257-
pipe = {OUT_PORT: [n_id, pname],
1258-
IN_PORT: [conn_id, conn_prt]}
1259+
pipe = {
1260+
PORT_TYPE.OUT.value: [n_id, pname],
1261+
PORT_TYPE.IN.value: [conn_id, conn_prt]
1262+
}
12591263
if pipe not in serial_data['connections']:
12601264
serial_data['connections'].append(pipe)
12611265

@@ -2362,8 +2366,10 @@ def get_node_by_port(self, port):
23622366
Returns:
23632367
PortInputNode or PortOutputNode: port node object.
23642368
"""
2365-
func_type = {IN_PORT: self.get_input_port_nodes,
2366-
OUT_PORT: self.get_output_port_nodes}
2369+
func_type = {
2370+
PORT_TYPE.IN.value: self.get_input_port_nodes,
2371+
PORT_TYPE.OUT.value: self.get_output_port_nodes
2372+
}
23672373
for n in func_type.get(port.type_(), []):
23682374
if port == n.parent_port:
23692375
return n

NodeGraphQt/base/graph_actions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,24 +256,24 @@ def _curved_pipe(graph):
256256
"""
257257
Set node graph pipes layout as curved.
258258
"""
259-
from NodeGraphQt.constants import PIPE_LAYOUT_CURVED
260-
graph.set_pipe_style(PIPE_LAYOUT_CURVED)
259+
from NodeGraphQt.constants import PIPE_LAYOUT
260+
graph.set_pipe_style(PIPE_LAYOUT.CURVED.value)
261261

262262

263263
def _straight_pipe(graph):
264264
"""
265265
Set node graph pipes layout as straight.
266266
"""
267-
from NodeGraphQt.constants import PIPE_LAYOUT_STRAIGHT
268-
graph.set_pipe_style(PIPE_LAYOUT_STRAIGHT)
267+
from NodeGraphQt.constants import PIPE_LAYOUT
268+
graph.set_pipe_style(PIPE_LAYOUT.STRAIGHT.value)
269269

270270

271271
def _angle_pipe(graph):
272272
"""
273273
Set node graph pipes layout as angled.
274274
"""
275-
from NodeGraphQt.constants import PIPE_LAYOUT_ANGLE
276-
graph.set_pipe_style(PIPE_LAYOUT_ANGLE)
275+
from NodeGraphQt.constants import PIPE_LAYOUT
276+
graph.set_pipe_style(PIPE_LAYOUT.ANGLE.value)
277277

278278

279279
def _bg_grid_none(graph):

NodeGraphQt/base/port.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
NodeInputDisconnectedCmd
1010
)
1111
from NodeGraphQt.base.model import PortModel
12-
from NodeGraphQt.constants import IN_PORT, OUT_PORT
12+
from NodeGraphQt.constants import PORT_TYPE
1313
from NodeGraphQt.errors import PortError
1414

1515

@@ -196,9 +196,9 @@ def connected_ports(self):
196196
for node_id, port_names in self.model.connected_ports.items():
197197
for port_name in port_names:
198198
node = graph.get_node_by_id(node_id)
199-
if self.type_() == IN_PORT:
199+
if self.type_() == PORT_TYPE.IN.value:
200200
ports.append(node.outputs()[port_name])
201-
elif self.type_() == OUT_PORT:
201+
elif self.type_() == PORT_TYPE.OUT.value:
202202
ports.append(node.inputs()[port_name])
203203
return ports
204204

@@ -284,7 +284,8 @@ def connect_to(self, port=None, push_undo=True):
284284

285285
# emit "port_connected" signal from the parent graph.
286286
ports = {p.type_(): p for p in [self, port]}
287-
graph.port_connected.emit(ports[IN_PORT], ports[OUT_PORT])
287+
graph.port_connected.emit(ports[PORT_TYPE.IN.value],
288+
ports[PORT_TYPE.OUT.value])
288289

289290
def disconnect_from(self, port=None, push_undo=True):
290291
"""
@@ -315,7 +316,8 @@ def disconnect_from(self, port=None, push_undo=True):
315316

316317
# emit "port_disconnected" signal from the parent graph.
317318
ports = {p.type_(): p for p in [self, port]}
318-
graph.port_disconnected.emit(ports[IN_PORT], ports[OUT_PORT])
319+
graph.port_disconnected.emit(ports[PORT_TYPE.IN.value],
320+
ports[PORT_TYPE.OUT.value])
319321

320322
def clear_connections(self, push_undo=True):
321323
"""

NodeGraphQt/constants.py

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@
2222

2323
class PIPE_STYLING(Enum):
2424
"""
25-
Pipe Constant.
25+
Pipe styling layout:
26+
``NodeGraphQt.constants.PIPE_STYLING``
2627
"""
27-
#: pipe width.
28+
#: default width.
2829
WIDTH = 1.2
2930
#: default color.
3031
COLOR = (175, 95, 30, 255)
3132
#: pipe color to a node when it's disabled.
3233
DISABLED_COLOR = (190, 20, 20, 255)
33-
#: color when the pipe is selected or mouse hovered.
34+
#: pipe color when selected or mouse over.
3435
ACTIVE_COLOR = (70, 255, 220, 255)
3536
#: pipe color to a node when it's selected.
3637
HIGHLIGHT_COLOR = (232, 184, 13, 255)
@@ -44,41 +45,63 @@ class PIPE_STYLING(Enum):
4445

4546
class PIPE_SLICER_STYLING(Enum):
4647
"""
47-
Slicer Pipe Constant.
48+
Slicer Pipe styling layout:
49+
``NodeGraphQt.constants.PIPE_SLICER_STYLING``
4850
"""
49-
#: pipe width.
51+
#: default width.
5052
WIDTH = 1.5
5153
#: default color.
5254
COLOR = (255, 50, 75)
5355

5456

5557
class PIPE_LAYOUT(Enum):
5658
"""
57-
Pipe layout constant.
59+
Pipe connection drawing layout:
60+
``NodeGraphQt.constants.PIPE_LAYOUT``
5861
"""
59-
#: draw the connection pipes as straight lines.
62+
#: draw straight lines for pipe connections.
6063
STRAIGHT = 0
61-
#: draw the connection pipes as curved lines.
64+
#: draw curved lines for pipe connections.
6265
CURVED = 1
63-
#: draw the connection pipes as angled lines.
66+
#: draw angled lines for pipe connections.
6467
ANGLE = 2
6568

66-
6769
# ==================================== PORT ====================================
6870

69-
#: Connection type for input ports.
70-
IN_PORT = 'in'
71-
#: Connection type for output ports.
72-
OUT_PORT = 'out'
73-
74-
PORT_DEFAULT_SIZE = 22.0
75-
PORT_DEFAULT_COLOR = (49, 115, 100, 255)
76-
PORT_DEFAULT_BORDER_COLOR = (29, 202, 151, 255)
77-
PORT_ACTIVE_COLOR = (14, 45, 59, 255)
78-
PORT_ACTIVE_BORDER_COLOR = (107, 166, 193, 255)
79-
PORT_HOVER_COLOR = (17, 43, 82, 255)
80-
PORT_HOVER_BORDER_COLOR = (136, 255, 35, 255)
81-
PORT_FALLOFF = 15.0
71+
72+
class PORT_STYLING(Enum):
73+
"""
74+
Port styling layout:
75+
``NodeGraphQt.constants.PORT_STYLING``
76+
"""
77+
#: default port size.
78+
SIZE = 22.0
79+
#: default port color. (r, g, b, a)
80+
COLOR = (49, 115, 100, 255)
81+
#: default port border color.
82+
BORDER_COLOR = (29, 202, 151, 255)
83+
#: port color when selected.
84+
ACTIVE_COLOR = (14, 45, 59, 255)
85+
#: port border color when selected.
86+
ACTIVE_BORDER_COLOR = (107, 166, 193, 255)
87+
#: port color on mouse over.
88+
HOVER_COLOR = (17, 43, 82, 255)
89+
#: port border color on mouse over.
90+
HOVER_BORDER_COLOR = (136, 255, 35, 255)
91+
#: threshold for selecting a port.
92+
CLICK_FALLOFF = 15.0
93+
94+
95+
class PORT_TYPE(Enum):
96+
"""
97+
Port connection types:
98+
``NodeGraphQt.constants.PORT_TYPE``
99+
"""
100+
#: Connection type for input ports.
101+
IN = 'in'
102+
#: Connection type for output ports.
103+
OUT = 'out'
104+
82105

83106
# ==================================== NODE ====================================
84107

NodeGraphQt/nodes/base_node.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
NODE_PROP_QLINEEDIT,
88
NODE_PROP_QCOMBO,
99
NODE_PROP_QCHECKBOX,
10-
IN_PORT, OUT_PORT,
10+
PORT_TYPE,
1111
NODE_LAYOUT_VERTICAL,
1212
NODE_LAYOUT_HORIZONTAL)
1313
from NodeGraphQt.errors import (PortError,
@@ -261,7 +261,7 @@ def add_input(self, name='input', multi_input=False, display_name=True,
261261
view.border_color = [min([255, max([0, i + 80])]) for i in color]
262262

263263
port = Port(self, view)
264-
port.model.type_ = IN_PORT
264+
port.model.type_ = PORT_TYPE.IN.value
265265
port.model.name = name
266266
port.model.display_name = display_name
267267
port.model.multi_connection = multi_input
@@ -303,7 +303,7 @@ def add_output(self, name='output', multi_output=True, display_name=True,
303303
view.color = color
304304
view.border_color = [min([255, max([0, i + 80])]) for i in color]
305305
port = Port(self, view)
306-
port.model.type_ = OUT_PORT
306+
port.model.type_ = PORT_TYPE.OUT.value
307307
port.model.name = name
308308
port.model.display_name = display_name
309309
port.model.multi_connection = multi_output
@@ -632,4 +632,3 @@ def on_input_disconnected(self, in_port, out_port):
632632
out_port (NodeGraphQt.Port): output port that was disconnected.
633633
"""
634634
return
635-

NodeGraphQt/qgraphics/node_base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
from Qt import QtGui, QtCore, QtWidgets
55

6-
from NodeGraphQt.constants import (IN_PORT, OUT_PORT,
6+
from NodeGraphQt.constants import (PORT_TYPE, PORT_STYLING,
77
NODE_WIDTH, NODE_HEIGHT,
88
NODE_ICON_SIZE, ICON_NODE_BASE,
99
NODE_SEL_COLOR, NODE_SEL_BORDER_COLOR,
10-
PORT_FALLOFF, Z_VAL_NODE,
10+
Z_VAL_NODE,
1111
ITEM_CACHE_MODE)
1212
from NodeGraphQt.errors import NodeWidgetError
1313
from NodeGraphQt.qgraphics.node_abstract import AbstractNodeItem
@@ -384,7 +384,7 @@ def align_ports(self, v_offset=0.0):
384384
v_offset (float): port vertical offset.
385385
"""
386386
width = self._width
387-
txt_offset = PORT_FALLOFF - 2
387+
txt_offset = PORT_STYLING.CLICK_FALLOFF.value - 2
388388
spacing = 1
389389

390390
# adjust input position
@@ -624,9 +624,9 @@ def _add_port(self, port):
624624
text.setFont(text.font())
625625
text.setVisible(port.display_name)
626626
text.setCacheMode(ITEM_CACHE_MODE)
627-
if port.port_type == IN_PORT:
627+
if port.port_type == PORT_TYPE.IN.value:
628628
self._input_items[port] = text
629-
elif port.port_type == OUT_PORT:
629+
elif port.port_type == PORT_TYPE.OUT.value:
630630
self._output_items[port] = text
631631
if self.scene():
632632
self.post_init()
@@ -653,7 +653,7 @@ def add_input(self, name='input', multi_port=False, display_name=True,
653653
else:
654654
port = PortItem(self)
655655
port.name = name
656-
port.port_type = IN_PORT
656+
port.port_type = PORT_TYPE.IN.value
657657
port.multi_connection = multi_port
658658
port.display_name = display_name
659659
port.locked = locked
@@ -680,7 +680,7 @@ def add_output(self, name='output', multi_port=False, display_name=True,
680680
else:
681681
port = PortItem(self)
682682
port.name = name
683-
port.port_type = OUT_PORT
683+
port.port_type = PORT_TYPE.OUT.value
684684
port.multi_connection = multi_port
685685
port.display_name = display_name
686686
port.locked = locked

NodeGraphQt/qgraphics/node_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from NodeGraphQt.constants import (NODE_SEL_BORDER_COLOR,
55
NODE_SEL_COLOR,
6-
PORT_FALLOFF)
6+
PORT_STYLING)
77
from NodeGraphQt.qgraphics.node_base import NodeItem
88

99

@@ -114,7 +114,7 @@ def align_ports(self, v_offset=0.0):
114114
v_offset (float): port vertical offset.
115115
"""
116116
width = self._width
117-
txt_offset = PORT_FALLOFF - 2
117+
txt_offset = PORT_STYLING.CLICK_FALLOFF.value - 2
118118
spacing = 1
119119

120120
# adjust input position

0 commit comments

Comments
 (0)