Skip to content

Commit

Permalink
Merge pull request #401 from jchanvfx/node_drawing_bugfixes
Browse files Browse the repository at this point in the history
Node drawing bugfixes
  • Loading branch information
jchanvfx authored Jan 23, 2024
2 parents 7d84f0d + 41c89b1 commit deaf3b1
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion NodeGraphQt/base/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 0 additions & 3 deletions NodeGraphQt/base/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 5 additions & 3 deletions NodeGraphQt/nodes/base_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
"""
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion NodeGraphQt/pkg_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
__version__ = '0.6.34'
__version__ = '0.6.35'
__status__ = 'Work in Progress'
__license__ = 'MIT'

Expand Down
13 changes: 11 additions & 2 deletions NodeGraphQt/qgraphics/node_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
"""
Expand All @@ -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):
Expand Down
9 changes: 8 additions & 1 deletion NodeGraphQt/qgraphics/node_backdrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
9 changes: 5 additions & 4 deletions NodeGraphQt/qgraphics/node_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.get('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)
3 changes: 2 additions & 1 deletion NodeGraphQt/widgets/node_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down

0 comments on commit deaf3b1

Please sign in to comment.