Skip to content

Commit 30b9d79

Browse files
authored
Merge pull request #101 from jchanvfx/restructure_items
Restructure items
2 parents a5aeace + ecaa816 commit 30b9d79

File tree

16 files changed

+64
-74
lines changed

16 files changed

+64
-74
lines changed

NodeGraphQt/base/factory.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def register_node(self, node, alias=None):
4949
5050
Args:
5151
node (Node): node item
52-
alias (str): custom alias for the node (optional).
52+
alias (str): custom alias for the node identifier (optional).
5353
"""
5454
if node is None:
5555
return
@@ -64,12 +64,10 @@ def register_node(self, node, alias=None):
6464
.format(node_type))
6565
self.__nodes[node_type] = node
6666

67-
if self.__names.get(node_type):
68-
raise NodeRegistrationError(
69-
'Node Name: {} already exists!'
70-
'Please specify a new node name for node: {}'
71-
.format(name, node_type))
72-
self.__names[name] = node_type
67+
if self.__names.get(name):
68+
self.__names[name].append(node_type)
69+
else:
70+
self.__names[name] = [node_type]
7371

7472
if alias:
7573
if self.__aliases.get(alias):

NodeGraphQt/base/model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def __init__(self):
7070
# store the property attributes.
7171
# (deleted when node is added to the graph)
7272
self._TEMP_property_attrs = {}
73+
7374
# temp store the property widget types.
7475
# (deleted when node is added to the graph)
7576
self._TEMP_property_widget_types = {

NodeGraphQt/base/node.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
NODE_PROP_QCHECKBOX,
99
IN_PORT, OUT_PORT)
1010
from NodeGraphQt.errors import PortRegistrationError
11-
from NodeGraphQt.widgets.node_backdrop import BackdropNodeItem
12-
from NodeGraphQt.widgets.node_base import NodeItem
11+
from NodeGraphQt.qgraphics.node_backdrop import BackdropNodeItem
12+
from NodeGraphQt.qgraphics.node_base import NodeItem
13+
from NodeGraphQt.widgets.node_property import (NodeComboBox,
14+
NodeLineEdit,
15+
NodeCheckBox)
1316

1417

1518
class classproperty(object):
@@ -392,7 +395,8 @@ def icon(self):
392395

393396
def add_combo_menu(self, name='', label='', items=None, tab=None):
394397
"""
395-
Embed a :class:`PySide2.QtWidgets.QComboBox` widget into the node.
398+
Create a custom property and embed a
399+
:class:`PySide2.QtWidgets.QComboBox` widget into the node.
396400
397401
Args:
398402
name (str): name for the custom property.
@@ -403,12 +407,15 @@ def add_combo_menu(self, name='', label='', items=None, tab=None):
403407
items = items or []
404408
self.create_property(
405409
name, items[0], items=items, widget_type=NODE_PROP_QCOMBO, tab=tab)
406-
widget = self.view.add_combo_menu(name, label, items)
410+
411+
widget = NodeComboBox(self.view, name, label, items)
407412
widget.value_changed.connect(lambda k, v: self.set_property(k, v))
413+
self.view.add_widget(widget)
408414

409415
def add_text_input(self, name='', label='', text='', tab=None):
410416
"""
411-
Embed a :class:`PySide2.QtWidgets.QLineEdit` widget into the node.
417+
Create a custom property and embed a
418+
:class:`PySide2.QtWidgets.QLineEdit` widget into the node.
412419
413420
Args:
414421
name (str): name for the custom property.
@@ -418,12 +425,14 @@ def add_text_input(self, name='', label='', text='', tab=None):
418425
"""
419426
self.create_property(
420427
name, text, widget_type=NODE_PROP_QLINEEDIT, tab=tab)
421-
widget = self.view.add_text_input(name, label, text)
428+
widget = NodeLineEdit(self.view, name, label, text)
422429
widget.value_changed.connect(lambda k, v: self.set_property(k, v))
430+
self.view.add_widget(widget)
423431

424432
def add_checkbox(self, name='', label='', text='', state=False, tab=None):
425433
"""
426-
Embed a :class:`PySide2.QtWidgets.QCheckBox` widget into the node.
434+
Create a custom property and embed a
435+
:class:`PySide2.QtWidgets.QCheckBox` widget into the node.
427436
428437
Args:
429438
name (str): name for the custom property.
@@ -434,8 +443,9 @@ def add_checkbox(self, name='', label='', text='', state=False, tab=None):
434443
"""
435444
self.create_property(
436445
name, state, widget_type=NODE_PROP_QCHECKBOX, tab=tab)
437-
widget = self.view.add_checkbox(name, label, text, state)
446+
widget = NodeCheckBox(self.view, name, label, text, state)
438447
widget.value_changed.connect(lambda k, v: self.set_property(k, v))
448+
self.view.add_widget(widget)
439449

440450
def add_input(self, name='input', multi_input=False, display_name=True):
441451
"""
@@ -451,7 +461,7 @@ def add_input(self, name='input', multi_input=False, display_name=True):
451461
"""
452462
if name in self.inputs().keys():
453463
raise PortRegistrationError(
454-
'port name "{}" already taken.'.format(name))
464+
'port name "{}" already registered.'.format(name))
455465
view = self.view.add_input(name, multi_input, display_name)
456466
port = Port(self, view)
457467
port.model.type_ = IN_PORT
@@ -476,7 +486,7 @@ def add_output(self, name='output', multi_output=True, display_name=True):
476486
"""
477487
if name in self.outputs().keys():
478488
raise PortRegistrationError(
479-
'port name "{}" already taken.'.format(name))
489+
'port name "{}" already registered.'.format(name))
480490
view = self.view.add_output(name, multi_output, display_name)
481491
port = Port(self, view)
482492
port.model.type_ = OUT_PORT

NodeGraphQt/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
PIPE_STYLE_DEFAULT = 'line'
1010
PIPE_STYLE_DASHED = 'dashed'
1111
PIPE_STYLE_DOTTED = 'dotted'
12-
PIPE_DEFAULT_COLOR = (146, 69, 39, 255)
12+
PIPE_DEFAULT_COLOR = (150, 80, 40, 255)
13+
PIPE_DISABLED_COLOR = (190, 20, 20, 255)
1314
PIPE_ACTIVE_COLOR = (70, 255, 220, 255)
1415
PIPE_HIGHLIGHT_COLOR = (232, 184, 13, 255)
1516
#: The draw the connection pipes as straight lines.

NodeGraphQt/qgraphics/__init__.py

Whitespace-only changes.

NodeGraphQt/widgets/node_abstract.py renamed to NodeGraphQt/qgraphics/node_abstract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class AbstractNodeItem(QtWidgets.QGraphicsItem):
88
"""
9-
The abstract base class of a node item.
9+
The base class of all node qgraphics item.
1010
"""
1111

1212
def __init__(self, name='node', parent=None):

NodeGraphQt/widgets/node_backdrop.py renamed to NodeGraphQt/qgraphics/node_backdrop.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from NodeGraphQt.constants import (Z_VAL_PIPE,
55
NODE_SEL_COLOR,
66
NODE_SEL_BORDER_COLOR)
7-
from NodeGraphQt.widgets.node_abstract import AbstractNodeItem
8-
from NodeGraphQt.widgets.pipe import Pipe
9-
from NodeGraphQt.widgets.port import PortItem
7+
from NodeGraphQt.qgraphics.node_abstract import AbstractNodeItem
8+
from NodeGraphQt.qgraphics.pipe import Pipe
9+
from NodeGraphQt.qgraphics.port import PortItem
1010

1111

1212
class BackdropSizer(QtWidgets.QGraphicsItem):

NodeGraphQt/widgets/node_base.py renamed to NodeGraphQt/qgraphics/node_base.py

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77
NODE_SEL_COLOR, NODE_SEL_BORDER_COLOR,
88
Z_VAL_NODE, Z_VAL_NODE_WIDGET)
99
from NodeGraphQt.errors import NodeWidgetError
10-
from NodeGraphQt.widgets.node_abstract import AbstractNodeItem
11-
from NodeGraphQt.widgets.node_widgets import (NodeBaseWidget,
12-
NodeComboBox,
13-
NodeLineEdit,
14-
NodeCheckBox)
15-
from NodeGraphQt.widgets.port import PortItem
10+
from NodeGraphQt.qgraphics.node_abstract import AbstractNodeItem
11+
from NodeGraphQt.qgraphics.port import PortItem
1612

1713

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

664660
@property
665661
def widgets(self):
666-
return dict(self._widgets)
667-
668-
def add_combo_menu(self, name='', label='', items=None, tooltip=''):
669-
items = items or []
670-
widget = NodeComboBox(self, name, label, items)
671-
widget.setToolTip(tooltip)
672-
self.add_widget(widget)
673-
return widget
674-
675-
def add_text_input(self, name='', label='', text='', tooltip=''):
676-
widget = NodeLineEdit(self, name, label, text)
677-
widget.setToolTip(tooltip)
678-
self.add_widget(widget)
679-
return widget
680-
681-
def add_checkbox(self, name='', label='', text='', state=False, tooltip=''):
682-
widget = NodeCheckBox(self, name, label, text, state)
683-
widget.setToolTip(tooltip)
684-
self.add_widget(widget)
685-
return widget
662+
return self._widgets.copy()
686663

687664
def add_widget(self, widget):
688-
if isinstance(widget, NodeBaseWidget):
689-
self._widgets[widget.name] = widget
690-
else:
691-
raise NodeWidgetError('{} is not an instance of a node widget.')
665+
self._widgets[widget.name] = widget
692666

693667
def get_widget(self, name):
694668
widget = self._widgets.get(name)

NodeGraphQt/widgets/pipe.py renamed to NodeGraphQt/qgraphics/pipe.py

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

44
from NodeGraphQt import QtCore, QtGui, QtWidgets
55
from NodeGraphQt.constants import (
6-
PIPE_DEFAULT_COLOR, PIPE_ACTIVE_COLOR, PIPE_HIGHLIGHT_COLOR,
6+
PIPE_DEFAULT_COLOR, PIPE_ACTIVE_COLOR,
7+
PIPE_HIGHLIGHT_COLOR, PIPE_DISABLED_COLOR,
78
PIPE_STYLE_DASHED, PIPE_STYLE_DEFAULT, PIPE_STYLE_DOTTED,
89
PIPE_LAYOUT_STRAIGHT, PIPE_WIDTH, IN_PORT, OUT_PORT, Z_VAL_PIPE
910
)
10-
from NodeGraphQt.widgets.port import PortItem
11+
from NodeGraphQt.qgraphics.port import PortItem
1112

1213
PIPE_STYLES = {
1314
PIPE_STYLE_DEFAULT: QtCore.Qt.SolidLine,
@@ -31,10 +32,10 @@ def __init__(self, input_port=None, output_port=None):
3132
self._highlight = False
3233
self._input_port = input_port
3334
self._output_port = output_port
34-
size = 5.0
35+
size = 6.0
3536
self._arrow = QtGui.QPolygonF()
3637
self._arrow.append(QtCore.QPointF(-size, size))
37-
self._arrow.append(QtCore.QPointF(0.0, -size * 2))
38+
self._arrow.append(QtCore.QPointF(0.0, -size * 1.5))
3839
self._arrow.append(QtCore.QPointF(size, size))
3940

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

4950
def hoverLeaveEvent(self, event):
5051
self.reset()
51-
if self.input_port.node.selected:
52-
self.highlight()
53-
elif self.output_port.node.selected:
54-
self.highlight()
52+
if self.input_port and self.output_port:
53+
if self.input_port.node.selected:
54+
self.highlight()
55+
elif self.output_port.node.selected:
56+
self.highlight()
5557

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

7981
if self.disabled():
80-
color.setAlpha(200)
82+
if not self._active:
83+
color = QtGui.QColor(*PIPE_DISABLED_COLOR)
8184
pen_width += 0.2
8285
pen_style = PIPE_STYLES.get(PIPE_STYLE_DOTTED)
8386

@@ -108,7 +111,7 @@ def paint(self, painter, option, widget):
108111
elif self._active or self.disabled():
109112
painter.setBrush(QtGui.QBrush(color.darker(200)))
110113
else:
111-
painter.setBrush(QtGui.QBrush(color))
114+
painter.setBrush(QtGui.QBrush(color.darker(130)))
112115

113116
pen_width = 0.6
114117
if dist < 1.0:
File renamed without changes.

0 commit comments

Comments
 (0)