Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions NodeGraphQt/base/commands.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
from Qt import QtWidgets

from NodeGraphQt.constants import IN_PORT, OUT_PORT
from NodeGraphQt.constants import PortTypeEnum


class PropertyChangedCmd(QtWidgets.QUndoCommand):
Expand Down Expand Up @@ -158,7 +158,7 @@ class NodeInputConnectedCmd(QtWidgets.QUndoCommand):

def __init__(self, src_port, trg_port):
QtWidgets.QUndoCommand.__init__(self)
if src_port.type_() == IN_PORT:
if src_port.type_() == PortTypeEnum.IN.value:
self.source = src_port
self.target = trg_port
else:
Expand All @@ -185,7 +185,7 @@ class NodeInputDisconnectedCmd(QtWidgets.QUndoCommand):

def __init__(self, src_port, trg_port):
QtWidgets.QUndoCommand.__init__(self)
if src_port.type_() == IN_PORT:
if src_port.type_() == PortTypeEnum.IN.value:
self.source = src_port
self.target = trg_port
else:
Expand Down Expand Up @@ -355,9 +355,9 @@ def set_visible(self, visible):
self.port.view.setVisible(visible)
node_view = self.port.node().view
text_item = None
if self.port.type_() == IN_PORT:
if self.port.type_() == PortTypeEnum.IN.value:
text_item = node_view.get_input_text_item(self.port.view)
elif self.port.type_() == OUT_PORT:
elif self.port.type_() == PortTypeEnum.OUT.value:
text_item = node_view.get_output_text_item(self.port.view)
if text_item:
text_item.setVisible(visible)
Expand Down
63 changes: 39 additions & 24 deletions NodeGraphQt/base/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import re

from Qt import QtCore, QtWidgets, QtGui
from Qt import QtCore, QtWidgets

from NodeGraphQt.base.commands import (NodeAddedCmd,
NodeRemovedCmd,
Expand All @@ -18,10 +18,10 @@
from NodeGraphQt.base.port import Port
from NodeGraphQt.constants import (
NODE_LAYOUT_DIRECTION, NODE_LAYOUT_HORIZONTAL, NODE_LAYOUT_VERTICAL,
PIPE_LAYOUT_CURVED, PIPE_LAYOUT_STRAIGHT, PIPE_LAYOUT_ANGLE,
PipeLayoutEnum,
URI_SCHEME, URN_SCHEME,
IN_PORT, OUT_PORT,
VIEWER_GRID_LINES
PortTypeEnum,
ViewerEnum
)
from NodeGraphQt.nodes.backdrop_node import BackdropNode
from NodeGraphQt.nodes.base_node import BaseNode
Expand Down Expand Up @@ -369,7 +369,8 @@ def _on_connection_changed(self, disconnected, connected):
return

label = 'connect node(s)' if connected else 'disconnect node(s)'
ptypes = {IN_PORT: 'inputs', OUT_PORT: 'outputs'}
ptypes = {PortTypeEnum.IN.value: 'inputs',
PortTypeEnum.OUT.value: 'outputs'}

self._undo_stack.beginMacro(label)
for p1_view, p2_view in disconnected:
Expand All @@ -396,7 +397,8 @@ def _on_connection_sliced(self, ports):
"""
if not ports:
return
ptypes = {IN_PORT: 'inputs', OUT_PORT: 'outputs'}
ptypes = {PortTypeEnum.IN.value: 'inputs',
PortTypeEnum.OUT.value: 'outputs'}
self._undo_stack.beginMacro('slice connections')
for p1_view, p2_view in ports:
node1 = self._model.nodes[p1_view.node.id]
Expand Down Expand Up @@ -553,7 +555,7 @@ def set_grid_color(self, r, g, b):
self.scene().grid_color = (r, g, b)
self._viewer.force_update()

def set_grid_mode(self, mode=VIEWER_GRID_LINES):
def set_grid_mode(self, mode=None):
"""
Set node graph grid mode.

Expand All @@ -562,13 +564,20 @@ def set_grid_mode(self, mode=VIEWER_GRID_LINES):

Node graph background types:

* :attr:`NodeGraphQt.constants.VIEWER_GRID_NONE`
* :attr:`NodeGraphQt.constants.VIEWER_GRID_DOTS`
* :attr:`NodeGraphQt.constants.VIEWER_GRID_LINES`
* :attr:`NodeGraphQt.constants.ViewerEnum.GRID_DISPLAY_NONE.value`
* :attr:`NodeGraphQt.constants.ViewerEnum.GRID_DISPLAY_DOTS.value`
* :attr:`NodeGraphQt.constants.ViewerEnum.GRID_DISPLAY_LINES.value`

Args:
mode (int): background style.
"""
display_types = [
ViewerEnum.GRID_DISPLAY_NONE.value,
ViewerEnum.GRID_DISPLAY_DOTS.value,
ViewerEnum.GRID_DISPLAY_LINES.value
]
if mode not in display_types:
mode = ViewerEnum.GRID_DISPLAY_LINES.value
self.scene().grid_mode = mode
self._viewer.force_update()

Expand Down Expand Up @@ -752,7 +761,7 @@ def set_pipe_collision(self, mode=True):
self._model.pipe_collision = mode
self._viewer.pipe_collision = mode

def set_pipe_style(self, style=PIPE_LAYOUT_CURVED):
def set_pipe_style(self, style=PipeLayoutEnum.CURVED.value):
"""
Set node graph pipes to be drawn as straight, curved or angled.

Expand All @@ -764,17 +773,17 @@ def set_pipe_style(self, style=PIPE_LAYOUT_CURVED):

Pipe Layout Styles:

* :attr:`NodeGraphQt.constants.PIPE_LAYOUT_CURVED`
* :attr:`NodeGraphQt.constants.PIPE_LAYOUT_STRAIGHT`
* :attr:`NodeGraphQt.constants.PIPE_LAYOUT_ANGLE`
* :attr:`NodeGraphQt.constants.PipeLayoutEnum.CURVED.value`
* :attr:`NodeGraphQt.constants.PipeLayoutEnum.STRAIGHT.value`
* :attr:`NodeGraphQt.constants.PipeLayoutEnum.ANGLE.value`

Args:
style (int): pipe layout style.
"""
pipe_max = max([PIPE_LAYOUT_CURVED,
PIPE_LAYOUT_STRAIGHT,
PIPE_LAYOUT_ANGLE])
style = style if 0 <= style <= pipe_max else PIPE_LAYOUT_CURVED
pipe_max = max([PipeLayoutEnum.CURVED.value,
PipeLayoutEnum.STRAIGHT.value,
PipeLayoutEnum.ANGLE.value])
style = style if 0 <= style <= pipe_max else PipeLayoutEnum.CURVED.value
self._viewer.set_pipe_layout(style)

def fit_to_selection(self):
Expand Down Expand Up @@ -1246,16 +1255,20 @@ def _serialize(self, nodes):
for pname, conn_data in inputs.items():
for conn_id, prt_names in conn_data.items():
for conn_prt in prt_names:
pipe = {IN_PORT: [n_id, pname],
OUT_PORT: [conn_id, conn_prt]}
pipe = {
PortTypeEnum.IN.value: [n_id, pname],
PortTypeEnum.OUT.value: [conn_id, conn_prt]
}
if pipe not in serial_data['connections']:
serial_data['connections'].append(pipe)

for pname, conn_data in outputs.items():
for conn_id, prt_names in conn_data.items():
for conn_prt in prt_names:
pipe = {OUT_PORT: [n_id, pname],
IN_PORT: [conn_id, conn_prt]}
pipe = {
PortTypeEnum.OUT.value: [n_id, pname],
PortTypeEnum.IN.value: [conn_id, conn_prt]
}
if pipe not in serial_data['connections']:
serial_data['connections'].append(pipe)

Expand Down Expand Up @@ -2362,8 +2375,10 @@ def get_node_by_port(self, port):
Returns:
PortInputNode or PortOutputNode: port node object.
"""
func_type = {IN_PORT: self.get_input_port_nodes,
OUT_PORT: self.get_output_port_nodes}
func_type = {
PortTypeEnum.IN.value: self.get_input_port_nodes,
PortTypeEnum.OUT.value: self.get_output_port_nodes
}
for n in func_type.get(port.type_(), []):
if port == n.parent_port:
return n
24 changes: 12 additions & 12 deletions NodeGraphQt/base/graph_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,48 +256,48 @@ def _curved_pipe(graph):
"""
Set node graph pipes layout as curved.
"""
from NodeGraphQt.constants import PIPE_LAYOUT_CURVED
graph.set_pipe_style(PIPE_LAYOUT_CURVED)
from NodeGraphQt.constants import PipeLayoutEnum
graph.set_pipe_style(PipeLayoutEnum.CURVED.value)


def _straight_pipe(graph):
"""
Set node graph pipes layout as straight.
"""
from NodeGraphQt.constants import PIPE_LAYOUT_STRAIGHT
graph.set_pipe_style(PIPE_LAYOUT_STRAIGHT)
from NodeGraphQt.constants import PipeLayoutEnum
graph.set_pipe_style(PipeLayoutEnum.STRAIGHT.value)


def _angle_pipe(graph):
"""
Set node graph pipes layout as angled.
"""
from NodeGraphQt.constants import PIPE_LAYOUT_ANGLE
graph.set_pipe_style(PIPE_LAYOUT_ANGLE)
from NodeGraphQt.constants import PipeLayoutEnum
graph.set_pipe_style(PipeLayoutEnum.ANGLE.value)


def _bg_grid_none(graph):
"""
Turn off the background patterns.
"""
from NodeGraphQt.constants import VIEWER_GRID_NONE
graph.set_grid_mode(VIEWER_GRID_NONE)
from NodeGraphQt.constants import ViewerEnum
graph.set_grid_mode(ViewerEnum.GRID_DISPLAY_NONE.value)


def _bg_grid_dots(graph):
"""
Set background node graph background with grid dots.
"""
from NodeGraphQt.constants import VIEWER_GRID_DOTS
graph.set_grid_mode(VIEWER_GRID_DOTS)
from NodeGraphQt.constants import ViewerEnum
graph.set_grid_mode(ViewerEnum.GRID_DISPLAY_DOTS.value)


def _bg_grid_lines(graph):
"""
Set background node graph background with grid lines.
"""
from NodeGraphQt.constants import VIEWER_GRID_LINES
graph.set_grid_mode(VIEWER_GRID_LINES)
from NodeGraphQt.constants import ViewerEnum
graph.set_grid_mode(ViewerEnum.GRID_DISPLAY_LINES.value)


def _layout_graph_down(graph):
Expand Down
12 changes: 7 additions & 5 deletions NodeGraphQt/base/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
NodeInputDisconnectedCmd
)
from NodeGraphQt.base.model import PortModel
from NodeGraphQt.constants import IN_PORT, OUT_PORT
from NodeGraphQt.constants import PortTypeEnum
from NodeGraphQt.errors import PortError


Expand Down Expand Up @@ -196,9 +196,9 @@ def connected_ports(self):
for node_id, port_names in self.model.connected_ports.items():
for port_name in port_names:
node = graph.get_node_by_id(node_id)
if self.type_() == IN_PORT:
if self.type_() == PortTypeEnum.IN.value:
ports.append(node.outputs()[port_name])
elif self.type_() == OUT_PORT:
elif self.type_() == PortTypeEnum.OUT.value:
ports.append(node.inputs()[port_name])
return ports

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

# emit "port_connected" signal from the parent graph.
ports = {p.type_(): p for p in [self, port]}
graph.port_connected.emit(ports[IN_PORT], ports[OUT_PORT])
graph.port_connected.emit(ports[PortTypeEnum.IN.value],
ports[PortTypeEnum.OUT.value])

def disconnect_from(self, port=None, push_undo=True):
"""
Expand Down Expand Up @@ -315,7 +316,8 @@ def disconnect_from(self, port=None, push_undo=True):

# emit "port_disconnected" signal from the parent graph.
ports = {p.type_(): p for p in [self, port]}
graph.port_disconnected.emit(ports[IN_PORT], ports[OUT_PORT])
graph.port_disconnected.emit(ports[PortTypeEnum.IN.value],
ports[PortTypeEnum.OUT.value])

def clear_connections(self, push_undo=True):
"""
Expand Down
Loading