From 658895df22bd81986addc9326a7cc0f51c142bca Mon Sep 17 00:00:00 2001 From: Johnny Chan Date: Wed, 24 Jan 2024 11:43:58 +1300 Subject: [PATCH 1/4] text input placeholder text --- NodeGraphQt/nodes/base_node.py | 8 +++++--- NodeGraphQt/widgets/node_widgets.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/NodeGraphQt/nodes/base_node.py b/NodeGraphQt/nodes/base_node.py index 5aa56d7d..2c505b41 100644 --- a/NodeGraphQt/nodes/base_node.py +++ b/NodeGraphQt/nodes/base_node.py @@ -237,7 +237,8 @@ def add_combo_menu(self, name, label='', items=None, tooltip=None, #: redraw node to address calls outside the "__init__" func. self.view.draw_node() - def add_text_input(self, name, label='', text='', tooltip=None, tab=None): + def add_text_input(self, name, label='', text='', placeholder_text='', + tooltip=None, tab=None): """ Creates a custom property with the :meth:`NodeObject.create_property` function and embeds a :class:`PySide2.QtWidgets.QLineEdit` widget @@ -250,7 +251,8 @@ def add_text_input(self, name, label='', text='', tooltip=None, tab=None): Args: name (str): name for the custom property. label (str): label to be displayed. - text (str): pre filled text. + text (str): pre-filled text. + placeholder_text (str): placeholder text. tooltip (str): widget tooltip. tab (str): name of the widget tab to display in. """ @@ -261,7 +263,7 @@ def add_text_input(self, name, label='', text='', tooltip=None, tab=None): widget_tooltip=tooltip, tab=tab ) - widget = NodeLineEdit(self.view, name, label, text) + widget = NodeLineEdit(self.view, name, label, text, placeholder_text) widget.setToolTip(tooltip or '') widget.value_changed.connect(lambda k, v: self.set_property(k, v)) self.view.add_widget(widget) diff --git a/NodeGraphQt/widgets/node_widgets.py b/NodeGraphQt/widgets/node_widgets.py index eaf9f5be..39bd7c8c 100644 --- a/NodeGraphQt/widgets/node_widgets.py +++ b/NodeGraphQt/widgets/node_widgets.py @@ -326,7 +326,7 @@ class NodeLineEdit(NodeBaseWidget): :meth:`NodeGraphQt.BaseNode.add_text_input` """ - def __init__(self, parent=None, name='', label='', text=''): + def __init__(self, parent=None, name='', label='', text='', placeholder_text=''): super(NodeLineEdit, self).__init__(parent, name, label) bg_color = ViewerEnum.BACKGROUND_COLOR.value text_color = tuple(map(lambda i, j: i - j, (255, 255, 255), @@ -352,6 +352,7 @@ def __init__(self, parent=None, name='', label='', text=''): stylesheet += style ledit = QtWidgets.QLineEdit() ledit.setText(text) + ledit.setPlaceholderText(placeholder_text) ledit.setStyleSheet(stylesheet) ledit.setAlignment(QtCore.Qt.AlignCenter) ledit.editingFinished.connect(self.on_value_changed) From 9863b10e44af9eba5bfde77a31f35a00533cc268 Mon Sep 17 00:00:00 2001 From: Johnny Chan Date: Wed, 24 Jan 2024 11:48:07 +1300 Subject: [PATCH 2/4] version bump --- NodeGraphQt/pkg_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NodeGraphQt/pkg_info.py b/NodeGraphQt/pkg_info.py index b83a8bce..1b18a567 100644 --- a/NodeGraphQt/pkg_info.py +++ b/NodeGraphQt/pkg_info.py @@ -1,6 +1,6 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -__version__ = '0.6.34' +__version__ = '0.6.35' __status__ = 'Work in Progress' __license__ = 'MIT' From 48a5cf1f03427bc4f8a10303da84fcf2056113b0 Mon Sep 17 00:00:00 2001 From: Johnny Chan Date: Wed, 24 Jan 2024 11:48:44 +1300 Subject: [PATCH 3/4] node drawing deserialize bug fix. --- NodeGraphQt/base/node.py | 3 --- NodeGraphQt/qgraphics/node_abstract.py | 13 +++++++++++-- NodeGraphQt/qgraphics/node_backdrop.py | 9 ++++++++- NodeGraphQt/qgraphics/node_base.py | 9 +++++---- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/NodeGraphQt/base/node.py b/NodeGraphQt/base/node.py index fc1f016b..9a5593b0 100644 --- a/NodeGraphQt/base/node.py +++ b/NodeGraphQt/base/node.py @@ -204,9 +204,6 @@ def update(self): """ settings = self.model.to_dict[self.model.id] settings['id'] = self.model.id - if settings.get('custom'): - settings['widgets'] = settings.pop('custom') - self.view.from_dict(settings) def serialize(self): diff --git a/NodeGraphQt/qgraphics/node_abstract.py b/NodeGraphQt/qgraphics/node_abstract.py index 29dfcf18..e2fb2418 100644 --- a/NodeGraphQt/qgraphics/node_abstract.py +++ b/NodeGraphQt/qgraphics/node_abstract.py @@ -55,6 +55,15 @@ def setSelected(self, selected): self._properties['selected'] = selected super(AbstractNodeItem, self).setSelected(selected) + def draw_node(self): + """ + Re-draw the node item in the scene with proper + calculated size and widgets aligned. + + (this is called from the builtin custom widgets.) + """ + return + def pre_init(self, viewer, pos=None): """ Called before node has been added into the scene. @@ -63,7 +72,7 @@ def pre_init(self, viewer, pos=None): viewer (NodeGraphQt.widgets.viewer.NodeViewer): main viewer. pos (tuple): the cursor pos if node is called with tab search. """ - pass + return def post_init(self, viewer, pos=None): """ @@ -73,7 +82,7 @@ def post_init(self, viewer, pos=None): viewer (NodeGraphQt.widgets.viewer.NodeViewer): main viewer pos (tuple): the cursor pos if node is called with tab search. """ - pass + return @property def id(self): diff --git a/NodeGraphQt/qgraphics/node_backdrop.py b/NodeGraphQt/qgraphics/node_backdrop.py index 02990ab6..9ccf0ca9 100644 --- a/NodeGraphQt/qgraphics/node_backdrop.py +++ b/NodeGraphQt/qgraphics/node_backdrop.py @@ -67,7 +67,7 @@ def mouseReleaseEvent(self, event): def paint(self, painter, option, widget): """ - Draws the backdrop sizer on the bottom right corner. + Draws the backdrop sizer in the bottom right corner. Args: painter (QtGui.QPainter): painter used for drawing the item. @@ -302,3 +302,10 @@ def width(self, width=0.0): def height(self, height=0.0): AbstractNodeItem.height.fset(self, height) self._sizer.set_pos(self._width, self._height) + + def from_dict(self, node_dict): + super().from_dict(node_dict) + custom_props = node_dict.get('custom') or {} + for prop_name, value in custom_props.items(): + if prop_name == 'backdrop_text': + self.backdrop_text = value diff --git a/NodeGraphQt/qgraphics/node_base.py b/NodeGraphQt/qgraphics/node_base.py index f35ad9da..9d57ae84 100644 --- a/NodeGraphQt/qgraphics/node_base.py +++ b/NodeGraphQt/qgraphics/node_base.py @@ -1049,7 +1049,8 @@ def has_widget(self, name): def from_dict(self, node_dict): super(NodeItem, self).from_dict(node_dict) - widgets = node_dict.pop('widgets', {}) - for name, value in widgets.items(): - if self._widgets.get(name): - self._widgets[name].set_value(value) + custom_prop = node_dict.pop('custom') or {} + for prop_name, value in custom_prop.items(): + prop_widget = self._widgets.get(prop_name) + if prop_widget: + prop_widget.set_value(value) From 41c89b1b2408ad28dc4f92e1cfe8e84e9cf39a8d Mon Sep 17 00:00:00 2001 From: Johnny Chan Date: Wed, 24 Jan 2024 11:56:38 +1300 Subject: [PATCH 4/4] clean up fix. --- NodeGraphQt/base/commands.py | 2 +- NodeGraphQt/qgraphics/node_base.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NodeGraphQt/base/commands.py b/NodeGraphQt/base/commands.py index 67e382b0..fffdb4ce 100644 --- a/NodeGraphQt/base/commands.py +++ b/NodeGraphQt/base/commands.py @@ -36,7 +36,7 @@ def set_node_property(self, name, value): # view widgets. if hasattr(view, 'widgets') and name in view.widgets.keys(): # check if previous value is identical to current value, - # prevent signals from causing a infinite loop. + # prevent signals from causing an infinite loop. if view.widgets[name].get_value() != value: view.widgets[name].set_value(value) diff --git a/NodeGraphQt/qgraphics/node_base.py b/NodeGraphQt/qgraphics/node_base.py index 9d57ae84..3f0e8864 100644 --- a/NodeGraphQt/qgraphics/node_base.py +++ b/NodeGraphQt/qgraphics/node_base.py @@ -1049,7 +1049,7 @@ def has_widget(self, name): def from_dict(self, node_dict): super(NodeItem, self).from_dict(node_dict) - custom_prop = node_dict.pop('custom') or {} + custom_prop = node_dict.get('custom') or {} for prop_name, value in custom_prop.items(): prop_widget = self._widgets.get(prop_name) if prop_widget: