Skip to content

Commit

Permalink
Merge pull request #380 from jchanvfx/node_property_tooltip_379
Browse files Browse the repository at this point in the history
node property widget tooltip and bug fixes. #379
  • Loading branch information
jchanvfx authored Sep 13, 2023
2 parents 710e756 + b931690 commit 44fb644
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 14 deletions.
8 changes: 7 additions & 1 deletion NodeGraphQt/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __repr__(self):
self.__class__.__name__, self.name, self.id)

def add_property(self, name, value, items=None, range=None,
widget_type=None, tab=None):
widget_type=None, widget_tooltip=None, tab=None):
"""
add custom property or raises an error if the property name is already
taken.
Expand All @@ -132,6 +132,7 @@ def add_property(self, name, value, items=None, range=None,
items (list[str]): items used by widget type NODE_PROP_QCOMBO.
range (tuple): min, max values used by NODE_PROP_SLIDER.
widget_type (int): widget type flag.
widget_tooltip (str): custom tooltip for the property widget.
tab (str): widget tab name.
"""
widget_type = widget_type or NodePropWidgetEnum.HIDDEN.value
Expand All @@ -153,6 +154,9 @@ def add_property(self, name, value, items=None, range=None,
self._TEMP_property_attrs[name]['items'] = items
if range:
self._TEMP_property_attrs[name]['range'] = range
if widget_tooltip:
self._TEMP_property_attrs[name]['tooltip'] = widget_tooltip

else:
attrs = {
self.type_: {
Expand All @@ -166,6 +170,8 @@ def add_property(self, name, value, items=None, range=None,
attrs[self.type_][name]['items'] = items
if range:
attrs[self.type_][name]['range'] = range
if widget_tooltip:
attrs[self.type_][name]['tooltip'] = widget_tooltip
self._graph_model.set_node_common_properties(attrs)

def set_property(self, name, value):
Expand Down
8 changes: 6 additions & 2 deletions NodeGraphQt/base/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def set_selected(self, selected=True):
self.set_property('selected', selected)

def create_property(self, name, value, items=None, range=None,
widget_type=None, tab=None):
widget_type=None, widget_tooltip=None, tab=None):
"""
Creates a custom property to the node.
Expand All @@ -347,11 +347,15 @@ def create_property(self, name, value, items=None, range=None,
:attr:`NodeGraphQt.constants.NodePropWidgetEnum.SLIDER`
widget_type (int): widget flag to display in the
:class:`NodeGraphQt.PropertiesBinWidget`
widget_tooltip (str): widget tooltip for the property widget
displayed in the :class:`NodeGraphQt.PropertiesBinWidget`
tab (str): name of the widget tab to display in the
:class:`NodeGraphQt.PropertiesBinWidget`.
"""
widget_type = widget_type or NodePropWidgetEnum.HIDDEN.value
self.model.add_property(name, value, items, range, widget_type, tab)
self.model.add_property(
name, value, items, range, widget_type, widget_tooltip, tab
)

def properties(self):
"""
Expand Down
21 changes: 16 additions & 5 deletions NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __repr__(self):
self.__class__.__name__, hex(id(self))
)

def add_widget(self, name, widget, value, label=None):
def add_widget(self, name, widget, value, label=None, tooltip=None):
"""
Add a property widget to the window.
Expand All @@ -103,8 +103,12 @@ def add_widget(self, name, widget, value, label=None):
widget (BaseProperty): property widget.
value (object): property value.
label (str): custom label to display.
tooltip (str): custom tooltip.
"""
widget.setToolTip(name)
if tooltip:
widget.setToolTip('{}\n{}'.format(name, tooltip))
else:
widget.setToolTip(name)
widget.set_value(value)
if label is None:
label = name
Expand Down Expand Up @@ -412,6 +416,7 @@ def _read_node(self, node):
if wid_type == 0:
continue

tooltip = None
widget = widget_factory.get_widget(wid_type)
if prop_name in common_props.keys():
if 'items' in common_props[prop_name].keys():
Expand All @@ -420,9 +425,15 @@ def _read_node(self, node):
prop_range = common_props[prop_name]['range']
widget.set_min(prop_range[0])
widget.set_max(prop_range[1])

prop_window.add_widget(prop_name, widget, value,
prop_name.replace('_', ' '))
if 'tooltip' in common_props[prop_name].keys():
tooltip = common_props[prop_name]['tooltip']
prop_window.add_widget(
name=prop_name,
widget=widget,
value=value,
label=prop_name.replace('_', ' '),
tooltip=tooltip
)
widget.value_changed.connect(self._on_property_changed)

# add "Node" tab properties. (default props)
Expand Down
17 changes: 14 additions & 3 deletions NodeGraphQt/nodes/base_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def add_custom_widget(self, widget, widget_type=None, tab=None):
#: redraw node to address calls outside the "__init__" func.
self.view.draw_node()

def add_combo_menu(self, name, label='', items=None, tab=None):
def add_combo_menu(self, name, label='', items=None, tooltip=None,
tab=None):
"""
Creates a custom property with the :meth:`NodeObject.create_property`
function and embeds a :class:`PySide2.QtWidgets.QComboBox` widget
Expand All @@ -218,22 +219,25 @@ def add_combo_menu(self, name, label='', items=None, tab=None):
name (str): name for the custom property.
label (str): label to be displayed.
items (list[str]): items to be added into the menu.
tooltip (str): widget tooltip.
tab (str): name of the widget tab to display in.
"""
self.create_property(
name,
value=items[0] if items else None,
items=items or [],
widget_type=NodePropWidgetEnum.QCOMBO_BOX.value,
widget_tooltip=tooltip,
tab=tab
)
widget = NodeComboBox(self.view, name, label, items)
widget.setToolTip(tooltip or '')
widget.value_changed.connect(lambda k, v: self.set_property(k, v))
self.view.add_widget(widget)
#: redraw node to address calls outside the "__init__" func.
self.view.draw_node()

def add_text_input(self, name, label='', text='', tab=None):
def add_text_input(self, name, label='', 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 @@ -247,21 +251,25 @@ def add_text_input(self, name, label='', text='', tab=None):
name (str): name for the custom property.
label (str): label to be displayed.
text (str): pre filled text.
tooltip (str): widget tooltip.
tab (str): name of the widget tab to display in.
"""
self.create_property(
name,
value=text,
widget_type=NodePropWidgetEnum.QLINE_EDIT.value,
widget_tooltip=tooltip,
tab=tab
)
widget = NodeLineEdit(self.view, name, label, text)
widget.setToolTip(tooltip or '')
widget.value_changed.connect(lambda k, v: self.set_property(k, v))
self.view.add_widget(widget)
#: redraw node to address calls outside the "__init__" func.
self.view.draw_node()

def add_checkbox(self, name, label='', text='', state=False, tab=None):
def add_checkbox(self, name, label='', text='', state=False, tooltip=None,
tab=None):
"""
Creates a custom property with the :meth:`NodeObject.create_property`
function and embeds a :class:`PySide2.QtWidgets.QCheckBox` widget
Expand All @@ -276,15 +284,18 @@ def add_checkbox(self, name, label='', text='', state=False, tab=None):
label (str): label to be displayed.
text (str): checkbox text.
state (bool): pre-check.
tooltip (str): widget tooltip.
tab (str): name of the widget tab to display in.
"""
self.create_property(
name,
value=state,
widget_type=NodePropWidgetEnum.QCHECK_BOX.value,
widget_tooltip=tooltip,
tab=tab
)
widget = NodeCheckBox(self.view, name, label, text, state)
widget.setToolTip(tooltip or '')
widget.value_changed.connect(lambda k, v: self.set_property(k, v))
self.view.add_widget(widget)
#: redraw node to address calls outside the "__init__" func.
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.22'
__version__ = '0.6.23'
__status__ = 'Work in Progress'
__license__ = 'MIT'

Expand Down
2 changes: 1 addition & 1 deletion NodeGraphQt/widgets/node_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, parent=None, name=None, label=''):

def setToolTip(self, tooltip):
tooltip = tooltip.replace('\n', '<br/>')
tooltip = '<b>{}</b><br/>{}'.format(self.name, tooltip)
tooltip = '<b>{}</b><br/>{}'.format(self.get_name(), tooltip)
super(NodeBaseWidget, self).setToolTip(tooltip)

def on_value_changed(self, *args, **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion examples/nodes/widget_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def __init__(self):

# create the QComboBox menu.
items = ['item 1', 'item 2', 'item 3']
self.add_combo_menu('my_menu', 'Menu Test', items=items)
self.add_combo_menu('my_menu', 'Menu Test', items=items,
tooltip='example custom tooltip')


class TextInputNode(BaseNode):
Expand Down

0 comments on commit 44fb644

Please sign in to comment.