Skip to content

Commit c277d9b

Browse files
authored
Merge pull request #182 from jchanvfx/node_text_updates
refactored logic in NodeTextItem
2 parents a7f7cab + 247211d commit c277d9b

File tree

8 files changed

+208
-64
lines changed

8 files changed

+208
-64
lines changed

NodeGraphQt/base/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/python
2+
from .utils import minimize_node_ref_count
23
from .. import QtWidgets
34
from ..constants import IN_PORT, OUT_PORT
4-
from .utils import minimize_node_ref_count
55

66

77
class PropertyChangedCmd(QtWidgets.QUndoCommand):

NodeGraphQt/base/graph.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3+
import gc
34
import json
45
import os
56
import re
7+
68
import copy
7-
import gc
8-
from .. import QtCore, QtWidgets, QtGui
9+
910
from .commands import (NodeAddedCmd,
1011
NodeRemovedCmd,
1112
NodeMovedCmd,
@@ -15,14 +16,15 @@
1516
from .model import NodeGraphModel
1617
from .node import NodeObject, BaseNode
1718
from .port import Port
19+
from .. import QtCore, QtWidgets, QtGui
1820
from ..constants import (DRAG_DROP_ID,
1921
PIPE_LAYOUT_CURVED,
2022
PIPE_LAYOUT_STRAIGHT,
2123
PIPE_LAYOUT_ANGLE,
2224
IN_PORT, OUT_PORT,
2325
VIEWER_GRID_LINES)
24-
from ..widgets.viewer import NodeViewer
2526
from ..widgets.node_space_bar import node_space_bar
27+
from ..widgets.viewer import NodeViewer
2628

2729

2830
class QWidgetDrops(QtWidgets.QWidget):
@@ -179,9 +181,10 @@ def _wire_signals(self):
179181
self._viewer.connection_changed.connect(self._on_connection_changed)
180182
self._viewer.moved_nodes.connect(self._on_nodes_moved)
181183
self._viewer.node_double_clicked.connect(self._on_node_double_clicked)
184+
self._viewer.node_name_changed.connect(self._on_node_name_changed)
182185
self._viewer.insert_node.connect(self._insert_node)
183186

184-
# pass through signals.
187+
# pass through translated signals.
185188
self._viewer.node_selected.connect(self._on_node_selected)
186189
self._viewer.node_selection_changed.connect(
187190
self._on_node_selection_changed)
@@ -254,6 +257,21 @@ def _on_property_bin_changed(self, node_id, prop_name, prop_value):
254257
value = copy.deepcopy(prop_value)
255258
node.set_property(prop_name, value)
256259

260+
def _on_node_name_changed(self, node_id, name):
261+
"""
262+
called when a node text qgraphics item in the viewer is edited.
263+
(sets the name through the node object so undo commands are registered.)
264+
265+
Args:
266+
node_id (str): node id emitted by the viewer.
267+
name (str): new node name.
268+
"""
269+
node = self.get_node_by_id(node_id)
270+
node.set_name(name)
271+
272+
# TODO: not sure about redrawing the node here.
273+
node.view.draw_node()
274+
257275
def _on_node_double_clicked(self, node_id):
258276
"""
259277
called when a node in the viewer is double click.

NodeGraphQt/base/node.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .commands import PropertyChangedCmd
33
from .model import NodeModel
44
from .port import Port
5+
from .utils import update_node_down_stream
56
from ..constants import (NODE_PROP,
67
NODE_PROP_QLINEEDIT,
78
NODE_PROP_QTEXTEDIT,
@@ -23,7 +24,6 @@
2324
NodeIntEdit,
2425
NodeCheckBox,
2526
NodeFilePath)
26-
from .utils import update_node_down_stream
2727

2828

2929
class classproperty(object):
@@ -528,7 +528,6 @@ def __init__(self):
528528
self._inputs = []
529529
self._outputs = []
530530
self._has_draw = False
531-
self._view.text_item.editingFinished.connect(self.set_name)
532531

533532
def draw(self, force=True):
534533
"""

NodeGraphQt/pkg_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3-
__version__ = '0.1.2'
3+
__version__ = '0.1.1'
44
__status__ = 'Work in Progress'
55
__license__ = 'MIT'
66

NodeGraphQt/qgraphics/node_abstract.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ def visible(self, visible=False):
162162
def xy_pos(self):
163163
"""
164164
return the item scene postion.
165-
("node.pos" conflicted with "QGraphicsItem.pos()" so it was refactored to "xy_pos".)
165+
("node.pos" conflicted with "QGraphicsItem.pos()"
166+
so it was refactored to "xy_pos".)
166167
167168
Returns:
168169
list[float]: x, y scene position.
@@ -173,7 +174,8 @@ def xy_pos(self):
173174
def xy_pos(self, pos=None):
174175
"""
175176
set the item scene postion.
176-
("node.pos" conflicted with "QGraphicsItem.pos()" so it was refactored to "xy_pos".)
177+
("node.pos" conflicted with "QGraphicsItem.pos()"
178+
so it was refactored to "xy_pos".)
177179
178180
Args:
179181
pos (list[float]): x, y scene position.
@@ -231,7 +233,8 @@ def from_dict(self, node_dict):
231233
node_attrs = list(self._properties.keys()) + ['width', 'height', 'pos']
232234
for name, value in node_dict.items():
233235
if name in node_attrs:
234-
# "node.pos" conflicted with "QGraphicsItem.pos()" so it's refactored to "xy_pos".
236+
# "node.pos" conflicted with "QGraphicsItem.pos()"
237+
# so it's refactored to "xy_pos".
235238
if name == 'pos':
236239
name = 'xy_pos'
237240
setattr(self, name, value)

0 commit comments

Comments
 (0)