Skip to content

Commit 8f83e36

Browse files
authored
Merge branch 'jchanvfx:master' into master
2 parents 8e974a6 + 227594c commit 8f83e36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+890
-490
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ venv/*
44

55
# sphinx documentation
66
docs/_build/
7-
api
7+
api/doctrees
88

99
# python stuff
1010
*.pyc

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
include NodeGraphQt/widgets/icons/down_arrow.png
21
include NodeGraphQt/widgets/icons/node_base.png

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 PortTypeEnum
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_() == PortTypeEnum.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_() == PortTypeEnum.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_() == PortTypeEnum.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_() == PortTypeEnum.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: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import re
77

8-
from Qt import QtCore, QtWidgets, QtGui
8+
from Qt import QtCore, QtWidgets
99

1010
from NodeGraphQt.base.commands import (NodeAddedCmd,
1111
NodeRemovedCmd,
@@ -18,10 +18,10 @@
1818
from NodeGraphQt.base.port import Port
1919
from NodeGraphQt.constants import (
2020
NODE_LAYOUT_DIRECTION, NODE_LAYOUT_HORIZONTAL, NODE_LAYOUT_VERTICAL,
21-
PIPE_LAYOUT_CURVED, PIPE_LAYOUT_STRAIGHT, PIPE_LAYOUT_ANGLE,
21+
PipeLayoutEnum,
2222
URI_SCHEME, URN_SCHEME,
23-
IN_PORT, OUT_PORT,
24-
VIEWER_GRID_LINES
23+
PortTypeEnum,
24+
ViewerEnum
2525
)
2626
from NodeGraphQt.nodes.backdrop_node import BackdropNode
2727
from NodeGraphQt.nodes.base_node import BaseNode
@@ -164,13 +164,6 @@ def _wire_signals(self):
164164
"""
165165
Connect up all the signals and slots here.
166166
"""
167-
# TODO: refactor hard coded tab search logic into
168-
# "graph_actions.py" module.
169-
# hard coded tab search.
170-
tab = QtWidgets.QShortcut(
171-
QtGui.QKeySequence(QtCore.Qt.Key_Tab), self._viewer)
172-
tab.activated.connect(self._toggle_tab_search)
173-
self._viewer.show_tab_search.connect(self._toggle_tab_search)
174167

175168
# internal signals.
176169
self._viewer.search_triggered.connect(self._on_search_triggered)
@@ -221,14 +214,6 @@ def _on_insert_node(self, pipe, node_id, prev_node_pos):
221214
self._on_nodes_moved(prev_node_pos)
222215
self._undo_stack.endMacro()
223216

224-
def _toggle_tab_search(self):
225-
"""
226-
toggle the tab search widget.
227-
"""
228-
if self._viewer.underMouse():
229-
self._viewer.tab_search_set_nodes(self._node_factory.names)
230-
self._viewer.tab_search_toggle()
231-
232217
def _on_property_bin_changed(self, node_id, prop_name, prop_value):
233218
"""
234219
called when a property widget has changed in a properties bin.
@@ -384,7 +369,8 @@ def _on_connection_changed(self, disconnected, connected):
384369
return
385370

386371
label = 'connect node(s)' if connected else 'disconnect node(s)'
387-
ptypes = {IN_PORT: 'inputs', OUT_PORT: 'outputs'}
372+
ptypes = {PortTypeEnum.IN.value: 'inputs',
373+
PortTypeEnum.OUT.value: 'outputs'}
388374

389375
self._undo_stack.beginMacro(label)
390376
for p1_view, p2_view in disconnected:
@@ -411,7 +397,8 @@ def _on_connection_sliced(self, ports):
411397
"""
412398
if not ports:
413399
return
414-
ptypes = {IN_PORT: 'inputs', OUT_PORT: 'outputs'}
400+
ptypes = {PortTypeEnum.IN.value: 'inputs',
401+
PortTypeEnum.OUT.value: 'outputs'}
415402
self._undo_stack.beginMacro('slice connections')
416403
for p1_view, p2_view in ports:
417404
node1 = self._model.nodes[p1_view.node.id]
@@ -477,6 +464,14 @@ def undo_view(self):
477464
self._undo_view.setWindowTitle('Undo History')
478465
return self._undo_view
479466

467+
def toggle_node_search(self):
468+
"""
469+
toggle the node search widget visibility.
470+
"""
471+
if self._viewer.underMouse():
472+
self._viewer.tab_search_set_nodes(self._node_factory.names)
473+
self._viewer.tab_search_toggle()
474+
480475
def show(self):
481476
"""
482477
Show node graph widget this is just a convenience
@@ -560,7 +555,7 @@ def set_grid_color(self, r, g, b):
560555
self.scene().grid_color = (r, g, b)
561556
self._viewer.force_update()
562557

563-
def set_grid_mode(self, mode=VIEWER_GRID_LINES):
558+
def set_grid_mode(self, mode=None):
564559
"""
565560
Set node graph grid mode.
566561
@@ -569,13 +564,20 @@ def set_grid_mode(self, mode=VIEWER_GRID_LINES):
569564
570565
Node graph background types:
571566
572-
* :attr:`NodeGraphQt.constants.VIEWER_GRID_NONE`
573-
* :attr:`NodeGraphQt.constants.VIEWER_GRID_DOTS`
574-
* :attr:`NodeGraphQt.constants.VIEWER_GRID_LINES`
567+
* :attr:`NodeGraphQt.constants.ViewerEnum.GRID_DISPLAY_NONE.value`
568+
* :attr:`NodeGraphQt.constants.ViewerEnum.GRID_DISPLAY_DOTS.value`
569+
* :attr:`NodeGraphQt.constants.ViewerEnum.GRID_DISPLAY_LINES.value`
575570
576571
Args:
577572
mode (int): background style.
578573
"""
574+
display_types = [
575+
ViewerEnum.GRID_DISPLAY_NONE.value,
576+
ViewerEnum.GRID_DISPLAY_DOTS.value,
577+
ViewerEnum.GRID_DISPLAY_LINES.value
578+
]
579+
if mode not in display_types:
580+
mode = ViewerEnum.GRID_DISPLAY_LINES.value
579581
self.scene().grid_mode = mode
580582
self._viewer.force_update()
581583

@@ -736,7 +738,7 @@ def pipe_collision(self):
736738
737739
See Also:
738740
To enable/disable pipe collision
739-
:meth:`NodeGraph.set_pipe_collision_enabled`
741+
:meth:`NodeGraph.set_pipe_collision`
740742
741743
Returns:
742744
bool: True if pipe collision is enabled.
@@ -759,7 +761,7 @@ def set_pipe_collision(self, mode=True):
759761
self._model.pipe_collision = mode
760762
self._viewer.pipe_collision = mode
761763

762-
def set_pipe_style(self, style=PIPE_LAYOUT_CURVED):
764+
def set_pipe_style(self, style=PipeLayoutEnum.CURVED.value):
763765
"""
764766
Set node graph pipes to be drawn as straight, curved or angled.
765767
@@ -771,17 +773,17 @@ def set_pipe_style(self, style=PIPE_LAYOUT_CURVED):
771773
772774
Pipe Layout Styles:
773775
774-
* :attr:`NodeGraphQt.constants.PIPE_LAYOUT_CURVED`
775-
* :attr:`NodeGraphQt.constants.PIPE_LAYOUT_STRAIGHT`
776-
* :attr:`NodeGraphQt.constants.PIPE_LAYOUT_ANGLE`
776+
* :attr:`NodeGraphQt.constants.PipeLayoutEnum.CURVED.value`
777+
* :attr:`NodeGraphQt.constants.PipeLayoutEnum.STRAIGHT.value`
778+
* :attr:`NodeGraphQt.constants.PipeLayoutEnum.ANGLE.value`
777779
778780
Args:
779781
style (int): pipe layout style.
780782
"""
781-
pipe_max = max([PIPE_LAYOUT_CURVED,
782-
PIPE_LAYOUT_STRAIGHT,
783-
PIPE_LAYOUT_ANGLE])
784-
style = style if 0 <= style <= pipe_max else PIPE_LAYOUT_CURVED
783+
pipe_max = max([PipeLayoutEnum.CURVED.value,
784+
PipeLayoutEnum.STRAIGHT.value,
785+
PipeLayoutEnum.ANGLE.value])
786+
style = style if 0 <= style <= pipe_max else PipeLayoutEnum.CURVED.value
785787
self._viewer.set_pipe_layout(style)
786788

787789
def fit_to_selection(self):
@@ -1253,16 +1255,20 @@ def _serialize(self, nodes):
12531255
for pname, conn_data in inputs.items():
12541256
for conn_id, prt_names in conn_data.items():
12551257
for conn_prt in prt_names:
1256-
pipe = {IN_PORT: [n_id, pname],
1257-
OUT_PORT: [conn_id, conn_prt]}
1258+
pipe = {
1259+
PortTypeEnum.IN.value: [n_id, pname],
1260+
PortTypeEnum.OUT.value: [conn_id, conn_prt]
1261+
}
12581262
if pipe not in serial_data['connections']:
12591263
serial_data['connections'].append(pipe)
12601264

12611265
for pname, conn_data in outputs.items():
12621266
for conn_id, prt_names in conn_data.items():
12631267
for conn_prt in prt_names:
1264-
pipe = {OUT_PORT: [n_id, pname],
1265-
IN_PORT: [conn_id, conn_prt]}
1268+
pipe = {
1269+
PortTypeEnum.OUT.value: [n_id, pname],
1270+
PortTypeEnum.IN.value: [conn_id, conn_prt]
1271+
}
12661272
if pipe not in serial_data['connections']:
12671273
serial_data['connections'].append(pipe)
12681274

@@ -2369,8 +2375,10 @@ def get_node_by_port(self, port):
23692375
Returns:
23702376
PortInputNode or PortOutputNode: port node object.
23712377
"""
2372-
func_type = {IN_PORT: self.get_input_port_nodes,
2373-
OUT_PORT: self.get_output_port_nodes}
2378+
func_type = {
2379+
PortTypeEnum.IN.value: self.get_input_port_nodes,
2380+
PortTypeEnum.OUT.value: self.get_output_port_nodes
2381+
}
23742382
for n in func_type.get(port.type_(), []):
23752383
if port == n.parent_port:
23762384
return n

NodeGraphQt/base/graph_actions.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def build_context_menu(graph):
6363
# "Node" menu.
6464
# --------------------------------------------------------------------------
6565
node_menu = graph_menu.add_menu('&Nodes')
66+
node_menu.add_command('Node Search', _toggle_node_search, 'Tab')
67+
node_menu.add_separator()
6668
node_menu.add_command(
6769
'Auto Layout Up Stream', _layout_graph_up, 'L')
6870
node_menu.add_command(
@@ -230,8 +232,8 @@ def _expand_group_node(graph):
230232
Expand selected group node.
231233
"""
232234
selected_nodes = graph.selected_nodes()
233-
if len(selected_nodes) > 1:
234-
graph.message_dialog('Please select a single "GroupNode" to expand.')
235+
if not selected_nodes:
236+
graph.message_dialog('Please select a "GroupNode" to expand.')
235237
return
236238
graph.expand_group_node(selected_nodes[0])
237239

@@ -254,48 +256,48 @@ def _curved_pipe(graph):
254256
"""
255257
Set node graph pipes layout as curved.
256258
"""
257-
from NodeGraphQt.constants import PIPE_LAYOUT_CURVED
258-
graph.set_pipe_style(PIPE_LAYOUT_CURVED)
259+
from NodeGraphQt.constants import PipeLayoutEnum
260+
graph.set_pipe_style(PipeLayoutEnum.CURVED.value)
259261

260262

261263
def _straight_pipe(graph):
262264
"""
263265
Set node graph pipes layout as straight.
264266
"""
265-
from NodeGraphQt.constants import PIPE_LAYOUT_STRAIGHT
266-
graph.set_pipe_style(PIPE_LAYOUT_STRAIGHT)
267+
from NodeGraphQt.constants import PipeLayoutEnum
268+
graph.set_pipe_style(PipeLayoutEnum.STRAIGHT.value)
267269

268270

269271
def _angle_pipe(graph):
270272
"""
271273
Set node graph pipes layout as angled.
272274
"""
273-
from NodeGraphQt.constants import PIPE_LAYOUT_ANGLE
274-
graph.set_pipe_style(PIPE_LAYOUT_ANGLE)
275+
from NodeGraphQt.constants import PipeLayoutEnum
276+
graph.set_pipe_style(PipeLayoutEnum.ANGLE.value)
275277

276278

277279
def _bg_grid_none(graph):
278280
"""
279281
Turn off the background patterns.
280282
"""
281-
from NodeGraphQt.constants import VIEWER_GRID_NONE
282-
graph.set_grid_mode(VIEWER_GRID_NONE)
283+
from NodeGraphQt.constants import ViewerEnum
284+
graph.set_grid_mode(ViewerEnum.GRID_DISPLAY_NONE.value)
283285

284286

285287
def _bg_grid_dots(graph):
286288
"""
287289
Set background node graph background with grid dots.
288290
"""
289-
from NodeGraphQt.constants import VIEWER_GRID_DOTS
290-
graph.set_grid_mode(VIEWER_GRID_DOTS)
291+
from NodeGraphQt.constants import ViewerEnum
292+
graph.set_grid_mode(ViewerEnum.GRID_DISPLAY_DOTS.value)
291293

292294

293295
def _bg_grid_lines(graph):
294296
"""
295297
Set background node graph background with grid lines.
296298
"""
297-
from NodeGraphQt.constants import VIEWER_GRID_LINES
298-
graph.set_grid_mode(VIEWER_GRID_LINES)
299+
from NodeGraphQt.constants import ViewerEnum
300+
graph.set_grid_mode(ViewerEnum.GRID_DISPLAY_LINES.value)
299301

300302

301303
def _layout_graph_down(graph):
@@ -312,3 +314,10 @@ def _layout_graph_up(graph):
312314
"""
313315
nodes = graph.selected_nodes() or graph.all_nodes()
314316
graph.auto_layout_nodes(nodes=nodes, down_stream=False)
317+
318+
319+
def _toggle_node_search(graph):
320+
"""
321+
show/hide the node search widget.
322+
"""
323+
graph.toggle_node_search()

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 PortTypeEnum
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_() == PortTypeEnum.IN.value:
200200
ports.append(node.outputs()[port_name])
201-
elif self.type_() == OUT_PORT:
201+
elif self.type_() == PortTypeEnum.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[PortTypeEnum.IN.value],
288+
ports[PortTypeEnum.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[PortTypeEnum.IN.value],
320+
ports[PortTypeEnum.OUT.value])
319321

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

0 commit comments

Comments
 (0)