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
12 changes: 5 additions & 7 deletions NodeGraphQt/base/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def register_node(self, node, alias=None):

Args:
node (Node): node item
alias (str): custom alias for the node (optional).
alias (str): custom alias for the node identifier (optional).
"""
if node is None:
return
Expand All @@ -64,12 +64,10 @@ def register_node(self, node, alias=None):
.format(node_type))
self.__nodes[node_type] = node

if self.__names.get(node_type):
raise NodeRegistrationError(
'Node Name: {} already exists!'
'Please specify a new node name for node: {}'
.format(name, node_type))
self.__names[name] = node_type
if self.__names.get(name):
self.__names[name].append(node_type)
else:
self.__names[name] = [node_type]

if alias:
if self.__aliases.get(alias):
Expand Down
1 change: 1 addition & 0 deletions NodeGraphQt/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self):
# store the property attributes.
# (deleted when node is added to the graph)
self._TEMP_property_attrs = {}

# temp store the property widget types.
# (deleted when node is added to the graph)
self._TEMP_property_widget_types = {
Expand Down
30 changes: 20 additions & 10 deletions NodeGraphQt/base/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
NODE_PROP_QCHECKBOX,
IN_PORT, OUT_PORT)
from NodeGraphQt.errors import PortRegistrationError
from NodeGraphQt.widgets.node_backdrop import BackdropNodeItem
from NodeGraphQt.widgets.node_base import NodeItem
from NodeGraphQt.qgraphics.node_backdrop import BackdropNodeItem
from NodeGraphQt.qgraphics.node_base import NodeItem
from NodeGraphQt.widgets.node_property import (NodeComboBox,
NodeLineEdit,
NodeCheckBox)


class classproperty(object):
Expand Down Expand Up @@ -392,7 +395,8 @@ def icon(self):

def add_combo_menu(self, name='', label='', items=None, tab=None):
"""
Embed a :class:`PySide2.QtWidgets.QComboBox` widget into the node.
Create a custom property and embed a
:class:`PySide2.QtWidgets.QComboBox` widget into the node.

Args:
name (str): name for the custom property.
Expand All @@ -403,12 +407,15 @@ def add_combo_menu(self, name='', label='', items=None, tab=None):
items = items or []
self.create_property(
name, items[0], items=items, widget_type=NODE_PROP_QCOMBO, tab=tab)
widget = self.view.add_combo_menu(name, label, items)

widget = NodeComboBox(self.view, name, label, items)
widget.value_changed.connect(lambda k, v: self.set_property(k, v))
self.view.add_widget(widget)

def add_text_input(self, name='', label='', text='', tab=None):
"""
Embed a :class:`PySide2.QtWidgets.QLineEdit` widget into the node.
Create a custom property and embed a
:class:`PySide2.QtWidgets.QLineEdit` widget into the node.

Args:
name (str): name for the custom property.
Expand All @@ -418,12 +425,14 @@ def add_text_input(self, name='', label='', text='', tab=None):
"""
self.create_property(
name, text, widget_type=NODE_PROP_QLINEEDIT, tab=tab)
widget = self.view.add_text_input(name, label, text)
widget = NodeLineEdit(self.view, name, label, text)
widget.value_changed.connect(lambda k, v: self.set_property(k, v))
self.view.add_widget(widget)

def add_checkbox(self, name='', label='', text='', state=False, tab=None):
"""
Embed a :class:`PySide2.QtWidgets.QCheckBox` widget into the node.
Create a custom property and embed a
:class:`PySide2.QtWidgets.QCheckBox` widget into the node.

Args:
name (str): name for the custom property.
Expand All @@ -434,8 +443,9 @@ def add_checkbox(self, name='', label='', text='', state=False, tab=None):
"""
self.create_property(
name, state, widget_type=NODE_PROP_QCHECKBOX, tab=tab)
widget = self.view.add_checkbox(name, label, text, state)
widget = NodeCheckBox(self.view, name, label, text, state)
widget.value_changed.connect(lambda k, v: self.set_property(k, v))
self.view.add_widget(widget)

def add_input(self, name='input', multi_input=False, display_name=True):
"""
Expand All @@ -451,7 +461,7 @@ def add_input(self, name='input', multi_input=False, display_name=True):
"""
if name in self.inputs().keys():
raise PortRegistrationError(
'port name "{}" already taken.'.format(name))
'port name "{}" already registered.'.format(name))
view = self.view.add_input(name, multi_input, display_name)
port = Port(self, view)
port.model.type_ = IN_PORT
Expand All @@ -476,7 +486,7 @@ def add_output(self, name='output', multi_output=True, display_name=True):
"""
if name in self.outputs().keys():
raise PortRegistrationError(
'port name "{}" already taken.'.format(name))
'port name "{}" already registered.'.format(name))
view = self.view.add_output(name, multi_output, display_name)
port = Port(self, view)
port.model.type_ = OUT_PORT
Expand Down
3 changes: 2 additions & 1 deletion NodeGraphQt/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
PIPE_STYLE_DEFAULT = 'line'
PIPE_STYLE_DASHED = 'dashed'
PIPE_STYLE_DOTTED = 'dotted'
PIPE_DEFAULT_COLOR = (146, 69, 39, 255)
PIPE_DEFAULT_COLOR = (150, 80, 40, 255)
PIPE_DISABLED_COLOR = (190, 20, 20, 255)
PIPE_ACTIVE_COLOR = (70, 255, 220, 255)
PIPE_HIGHLIGHT_COLOR = (232, 184, 13, 255)
#: The draw the connection pipes as straight lines.
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class AbstractNodeItem(QtWidgets.QGraphicsItem):
"""
The abstract base class of a node item.
The base class of all node qgraphics item.
"""

def __init__(self, name='node', parent=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from NodeGraphQt.constants import (Z_VAL_PIPE,
NODE_SEL_COLOR,
NODE_SEL_BORDER_COLOR)
from NodeGraphQt.widgets.node_abstract import AbstractNodeItem
from NodeGraphQt.widgets.pipe import Pipe
from NodeGraphQt.widgets.port import PortItem
from NodeGraphQt.qgraphics.node_abstract import AbstractNodeItem
from NodeGraphQt.qgraphics.pipe import Pipe
from NodeGraphQt.qgraphics.port import PortItem


class BackdropSizer(QtWidgets.QGraphicsItem):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
NODE_SEL_COLOR, NODE_SEL_BORDER_COLOR,
Z_VAL_NODE, Z_VAL_NODE_WIDGET)
from NodeGraphQt.errors import NodeWidgetError
from NodeGraphQt.widgets.node_abstract import AbstractNodeItem
from NodeGraphQt.widgets.node_widgets import (NodeBaseWidget,
NodeComboBox,
NodeLineEdit,
NodeCheckBox)
from NodeGraphQt.widgets.port import PortItem
from NodeGraphQt.qgraphics.node_abstract import AbstractNodeItem
from NodeGraphQt.qgraphics.port import PortItem


class XDisabledItem(QtWidgets.QGraphicsItem):
Expand Down Expand Up @@ -663,32 +659,10 @@ def get_output_text_item(self, port_item):

@property
def widgets(self):
return dict(self._widgets)

def add_combo_menu(self, name='', label='', items=None, tooltip=''):
items = items or []
widget = NodeComboBox(self, name, label, items)
widget.setToolTip(tooltip)
self.add_widget(widget)
return widget

def add_text_input(self, name='', label='', text='', tooltip=''):
widget = NodeLineEdit(self, name, label, text)
widget.setToolTip(tooltip)
self.add_widget(widget)
return widget

def add_checkbox(self, name='', label='', text='', state=False, tooltip=''):
widget = NodeCheckBox(self, name, label, text, state)
widget.setToolTip(tooltip)
self.add_widget(widget)
return widget
return self._widgets.copy()

def add_widget(self, widget):
if isinstance(widget, NodeBaseWidget):
self._widgets[widget.name] = widget
else:
raise NodeWidgetError('{} is not an instance of a node widget.')
self._widgets[widget.name] = widget

def get_widget(self, name):
widget = self._widgets.get(name)
Expand Down
23 changes: 13 additions & 10 deletions NodeGraphQt/widgets/pipe.py → NodeGraphQt/qgraphics/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

from NodeGraphQt import QtCore, QtGui, QtWidgets
from NodeGraphQt.constants import (
PIPE_DEFAULT_COLOR, PIPE_ACTIVE_COLOR, PIPE_HIGHLIGHT_COLOR,
PIPE_DEFAULT_COLOR, PIPE_ACTIVE_COLOR,
PIPE_HIGHLIGHT_COLOR, PIPE_DISABLED_COLOR,
PIPE_STYLE_DASHED, PIPE_STYLE_DEFAULT, PIPE_STYLE_DOTTED,
PIPE_LAYOUT_STRAIGHT, PIPE_WIDTH, IN_PORT, OUT_PORT, Z_VAL_PIPE
)
from NodeGraphQt.widgets.port import PortItem
from NodeGraphQt.qgraphics.port import PortItem

PIPE_STYLES = {
PIPE_STYLE_DEFAULT: QtCore.Qt.SolidLine,
Expand All @@ -31,10 +32,10 @@ def __init__(self, input_port=None, output_port=None):
self._highlight = False
self._input_port = input_port
self._output_port = output_port
size = 5.0
size = 6.0
self._arrow = QtGui.QPolygonF()
self._arrow.append(QtCore.QPointF(-size, size))
self._arrow.append(QtCore.QPointF(0.0, -size * 2))
self._arrow.append(QtCore.QPointF(0.0, -size * 1.5))
self._arrow.append(QtCore.QPointF(size, size))

def __repr__(self):
Expand All @@ -48,10 +49,11 @@ def hoverEnterEvent(self, event):

def hoverLeaveEvent(self, event):
self.reset()
if self.input_port.node.selected:
self.highlight()
elif self.output_port.node.selected:
self.highlight()
if self.input_port and self.output_port:
if self.input_port.node.selected:
self.highlight()
elif self.output_port.node.selected:
self.highlight()

def paint(self, painter, option, widget):
"""
Expand All @@ -77,7 +79,8 @@ def paint(self, painter, option, widget):
pen_style = PIPE_STYLES.get(PIPE_STYLE_DEFAULT)

if self.disabled():
color.setAlpha(200)
if not self._active:
color = QtGui.QColor(*PIPE_DISABLED_COLOR)
pen_width += 0.2
pen_style = PIPE_STYLES.get(PIPE_STYLE_DOTTED)

Expand Down Expand Up @@ -108,7 +111,7 @@ def paint(self, painter, option, widget):
elif self._active or self.disabled():
painter.setBrush(QtGui.QBrush(color.darker(200)))
else:
painter.setBrush(QtGui.QBrush(color))
painter.setBrush(QtGui.QBrush(color.darker(130)))

pen_width = 0.6
if dist < 1.0:
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion NodeGraphQt/widgets/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
NODE_PROP_QSPINBOX,
NODE_PROP_COLORPICKER,
NODE_PROP_SLIDER)
from NodeGraphQt.errors import NodePropertyError


class BaseProperty(QtWidgets.QWidget):
Expand Down
2 changes: 1 addition & 1 deletion NodeGraphQt/widgets/properties_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, parent=None):
self._limit.setToolTip('Set node limit to display.')
self._limit.setMaximum(10)
self._limit.setMinimum(0)
self._limit.setValue(10)
self._limit.setValue(5)
self._limit.valueChanged.connect(self.__on_limit_changed)
self.resize(400, 400)

Expand Down
8 changes: 3 additions & 5 deletions NodeGraphQt/widgets/stylesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

from NodeGraphQt.constants import ICON_DOWN_ARROW

# we reformat the icon file path on windows os.
regex = re.compile('(\w:)')
match = regex.match(ICON_DOWN_ARROW)
# Reformat the icon path on Windows OS.
match = re.match('(\\w:)', ICON_DOWN_ARROW)
if match:
match_str = match.group(1)
ICON_DOWN_ARROW = ICON_DOWN_ARROW[len(match_str):]
ICON_DOWN_ARROW = ICON_DOWN_ARROW[len(match.group(1)):]
ICON_DOWN_ARROW = ICON_DOWN_ARROW.replace('\\', '/')

STYLE_QGROUPBOX = '''
Expand Down
8 changes: 7 additions & 1 deletion NodeGraphQt/widgets/tab_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ def mousePressEvent(self, event):
self.completer().complete()

def set_nodes(self, node_dict=None):
self._node_dict = node_dict or {}
self._node_dict = {}
for name, node_types in node_dict.items():
if len(node_types) == 1:
self._node_dict[name] = node_types[0]
continue
for node_id in node_types:
self._node_dict['{} ({})'.format(name, node_id)] = node_id
node_names = sorted(self._node_dict.keys())
self._model.setStringList(node_names)
self._completer.setModel(self._model)
8 changes: 4 additions & 4 deletions NodeGraphQt/widgets/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
PIPE_LAYOUT_STRAIGHT,
PIPE_STYLE_DASHED,
SCENE_AREA)
from NodeGraphQt.widgets.node_abstract import AbstractNodeItem
from NodeGraphQt.widgets.node_backdrop import BackdropNodeItem
from NodeGraphQt.widgets.pipe import Pipe
from NodeGraphQt.widgets.port import PortItem
from NodeGraphQt.qgraphics.node_abstract import AbstractNodeItem
from NodeGraphQt.qgraphics.node_backdrop import BackdropNodeItem
from NodeGraphQt.qgraphics.pipe import Pipe
from NodeGraphQt.qgraphics.port import PortItem
from NodeGraphQt.widgets.scene import NodeScene
from NodeGraphQt.widgets.stylesheet import STYLE_QMENU
from NodeGraphQt.widgets.tab_search import TabSearchWidget
Expand Down