Skip to content

Commit

Permalink
exposed node border color controls and property widget bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jchanvfx committed Sep 22, 2023
1 parent 972971d commit d60f9d3
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 39 deletions.
2 changes: 1 addition & 1 deletion NodeGraphQt/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self):
'icon': NodePropWidgetEnum.HIDDEN.value,
'name': NodePropWidgetEnum.QLINE_EDIT.value,
'color': NodePropWidgetEnum.COLOR_PICKER.value,
'border_color': NodePropWidgetEnum.HIDDEN.value,
'border_color': NodePropWidgetEnum.COLOR_PICKER.value,
'text_color': NodePropWidgetEnum.COLOR_PICKER.value,
'disabled': NodePropWidgetEnum.QCHECK_BOX.value,
'selected': NodePropWidgetEnum.HIDDEN.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, parent=None):
def _on_vector_changed(self, _, value):
self._color = tuple(value)
self._update_color()
self.value_changed.emit(self.toolTip(), value)
self.value_changed.emit(self.get_name(), value)

def _on_select_color(self):
current_color = QtGui.QColor(*self.get_value())
Expand Down Expand Up @@ -74,7 +74,7 @@ def set_value(self, value):
self._color = value
self._update_color()
self._update_vector()
self.value_changed.emit(self.toolTip(), value)
self.value_changed.emit(self.get_name(), value)


class PropColorPickerRGBA(PropColorPickerRGB):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _on_value_change(self, value=None):
if value is None:
value = self._ledit.text()
self.set_file_directory(value)
self.value_changed.emit(self.toolTip(), value)
self.value_changed.emit(self.get_name(), value)

def set_file_ext(self, ext=None):
self._ext = ext or '*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ def _on_slider_mouse_press(self, event):

def _on_slider_mouse_release(self, event):
if not self._realtime_update:
self.value_changed.emit(self.toolTip(), self.get_value())
self.value_changed.emit(self.get_name(), self.get_value())
self._block = False

def _on_slider_changed(self, value):
self._spinbox.setValue(value)
if self._realtime_update:
self.value_changed.emit(self.toolTip(), self.get_value())
self.value_changed.emit(self.get_name(), self.get_value())

def _on_spnbox_changed(self, value):
if value != self._slider.value():
self._slider.setValue(value)
if not self._block:
self.value_changed.emit(self.toolTip(), self.get_value())
self.value_changed.emit(self.get_name(), self.get_value())

def get_value(self):
return self._spinbox.value()
Expand All @@ -70,7 +70,7 @@ def set_value(self, value):
if value != self.get_value():
self._block = True
self._spinbox.setValue(value)
self.value_changed.emit(self.toolTip(), value)
self.value_changed.emit(self.get_name(), value)
self._block = False

def set_min(self, value=0):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _on_value_change(self, value=None, index=None):
if index is not None:
self._value = list(self._value)
self._value[index] = value
self.value_changed.emit(self.toolTip(), self._value)
self.value_changed.emit(self.get_name(), self._value)

def _update_items(self):
if not isinstance(self._value, (list, tuple)):
Expand Down
41 changes: 29 additions & 12 deletions NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ def add_widget(self, name, widget, value, label=None, tooltip=None):
label (str): custom label to display.
tooltip (str): custom tooltip.
"""
label = label or name
label_widget = QtWidgets.QLabel(label)
if tooltip:
widget.setToolTip('{}\n{}'.format(name, tooltip))
label_widget.setToolTip('{}\n{}'.format(name, tooltip))
else:
widget.setToolTip(name)
label_widget.setToolTip(name)
widget.set_value(value)
if label is None:
label = name
row = self.__layout.rowCount()
if row > 0:
row += 1
Expand All @@ -120,7 +122,7 @@ def add_widget(self, name, widget, value, label=None, tooltip=None):
if widget.__class__.__name__ == 'PropTextEdit':
label_flags = label_flags | QtCore.Qt.AlignTop

self.__layout.addWidget(QtWidgets.QLabel(label), row, 0, label_flags)
self.__layout.addWidget(label_widget, row, 0, label_flags)
self.__layout.addWidget(widget, row, 1)

def get_widget(self, name):
Expand Down Expand Up @@ -330,13 +332,16 @@ def __init__(self, parent=None, node=None):
close_btn.clicked.connect(self._on_close)

self.name_wgt = PropLineEdit()
self.name_wgt.setToolTip('name')
self.name_wgt.set_name('name')
self.name_wgt.setToolTip('name\nSet the node name.')
self.name_wgt.set_value(node.name())
self.name_wgt.value_changed.connect(self._on_property_changed)

self.type_wgt = QtWidgets.QLabel(node.type_)
self.type_wgt.setAlignment(QtCore.Qt.AlignRight)
self.type_wgt.setToolTip('type_')
self.type_wgt.setToolTip(
'type_\nNode type identifier followed by the class name.'
)
font = self.type_wgt.font()
font.setPointSize(10)
self.type_wgt.setFont(font)
Expand Down Expand Up @@ -416,8 +421,10 @@ def _read_node(self, node):
if wid_type == 0:
continue

tooltip = None
widget = widget_factory.get_widget(wid_type)
widget.set_name(prop_name)

tooltip = None
if prop_name in common_props.keys():
if 'items' in common_props[prop_name].keys():
widget.set_items(common_props[prop_name]['items'])
Expand All @@ -438,15 +445,25 @@ def _read_node(self, node):

# add "Node" tab properties. (default props)
self.add_tab('Node')
default_props = ['color', 'text_color', 'disabled', 'id']
default_props = {
'color': 'Node base color.',
'text_color': 'Node text color.',
'border_color': 'Node border color.',
'disabled': 'Disable/Enable node state.',
'id': 'Unique identifier string to the node.'
}
prop_window = self.__tab_windows['Node']
for prop_name in default_props:
for prop_name, tooltip in default_props.items():
wid_type = model.get_widget_type(prop_name)
widget = widget_factory.get_widget(wid_type)
prop_window.add_widget(prop_name,
widget,
model.get_property(prop_name),
prop_name.replace('_', ' '))
widget.set_name(prop_name)
prop_window.add_widget(
name=prop_name,
widget=widget,
value=model.get_property(prop_name),
label=prop_name.replace('_', ' '),
tooltip=tooltip
)

widget.value_changed.connect(self._on_property_changed)

Expand Down
27 changes: 20 additions & 7 deletions NodeGraphQt/custom_widgets/properties_bin/prop_widgets_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,38 @@ class BaseProperty(QtWidgets.QWidget):

value_changed = QtCore.Signal(str, object)

def __init__(self, parent=None):
super(BaseProperty, self).__init__(parent)
self._name = None

def __repr__(self):
return '<{}() object at {}>'.format(
self.__class__.__name__, hex(id(self)))

def get_value(self):
def get_name(self):
"""
Returns:
str: property name matching the node property.
"""
return self._name

def set_name(self, name):
"""
Args:
name (str): property name matching the node property.
"""
self._name = name

def get_value(self):
"""
Returns:
object:
object: widgets current value.
"""
raise NotImplementedError

def set_value(self, value):
"""
Args:
value (object):
Returns:
object:
value (object): property value to update the widget.
"""
raise NotImplementedError
Loading

0 comments on commit d60f9d3

Please sign in to comment.