diff --git a/NodeGraphQt/base/model.py b/NodeGraphQt/base/model.py index 0621a7d3..83c4e948 100644 --- a/NodeGraphQt/base/model.py +++ b/NodeGraphQt/base/model.py @@ -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, diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_color_picker.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_color_picker.py index a0004496..b622ba66 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_color_picker.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_color_picker.py @@ -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()) @@ -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): diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_file_paths.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_file_paths.py index 51b811ee..349bc5d1 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_file_paths.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_file_paths.py @@ -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 '*' diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_slider.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_slider.py index 66193ed2..781dd3b9 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_slider.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_slider.py @@ -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() @@ -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): diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_vectors.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_vectors.py index b13f23d0..26f13b98 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_vectors.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_vectors.py @@ -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)): diff --git a/NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py b/NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py index 5bcbbee6..e3a14116 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py +++ b/NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py @@ -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 @@ -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): @@ -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) @@ -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']) @@ -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) diff --git a/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_abstract.py b/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_abstract.py index 86974647..b78b9c7e 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_abstract.py +++ b/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_abstract.py @@ -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 diff --git a/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_base.py b/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_base.py index 040458c5..acd8f55c 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_base.py +++ b/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_base.py @@ -9,17 +9,27 @@ class PropLabel(QtWidgets.QLabel): value_changed = QtCore.Signal(str, object) + def __init__(self, parent=None): + super(PropLabel, self).__init__(parent) + self._name = None + def __repr__(self): return '<{}() object at {}>'.format( self.__class__.__name__, hex(id(self))) + def get_name(self): + return self._name + + def set_name(self, name): + self._name = name + def get_value(self): return self.text() def set_value(self, value): if value != self.get_value(): self.setText(str(value)) - self.value_changed.emit(self.toolTip(), value) + self.value_changed.emit(self.get_name(), value) class PropLineEdit(QtWidgets.QLineEdit): @@ -32,6 +42,7 @@ class PropLineEdit(QtWidgets.QLineEdit): def __init__(self, parent=None): super(PropLineEdit, self).__init__(parent) + self._name = None self.editingFinished.connect(self._on_editing_finished) def __repr__(self): @@ -39,7 +50,13 @@ def __repr__(self): self.__class__.__name__, hex(id(self))) def _on_editing_finished(self): - self.value_changed.emit(self.toolTip(), self.text()) + self.value_changed.emit(self.get_name(), self.text()) + + def get_name(self): + return self._name + + def set_name(self, name): + self._name = name def get_value(self): return self.text() @@ -48,7 +65,7 @@ def set_value(self, value): _value = str(value) if _value != self.get_value(): self.setText(_value) - self.value_changed.emit(self.toolTip(), _value) + self.value_changed.emit(self.get_name(), _value) class PropTextEdit(QtWidgets.QTextEdit): @@ -61,6 +78,7 @@ class PropTextEdit(QtWidgets.QTextEdit): def __init__(self, parent=None): super(PropTextEdit, self).__init__(parent) + self._name = None self._prev_text = '' def __repr__(self): @@ -74,9 +92,15 @@ def focusInEvent(self, event): def focusOutEvent(self, event): super(PropTextEdit, self).focusOutEvent(event) if self._prev_text != self.toPlainText(): - self.value_changed.emit(self.toolTip(), self.toPlainText()) + self.value_changed.emit(self.get_name(), self.toPlainText()) self._prev_text = '' + def get_name(self): + return self._name + + def set_name(self, name): + self._name = name + def get_value(self): return self.toPlainText() @@ -84,7 +108,7 @@ def set_value(self, value): _value = str(value) if _value != self.get_value(): self.setPlainText(_value) - self.value_changed.emit(self.toolTip(), _value) + self.value_changed.emit(self.get_name(), _value) class PropComboBox(QtWidgets.QComboBox): @@ -97,6 +121,7 @@ class PropComboBox(QtWidgets.QComboBox): def __init__(self, parent=None): super(PropComboBox, self).__init__(parent) + self._name = None self.currentIndexChanged.connect(self._on_index_changed) def __repr__(self): @@ -104,7 +129,7 @@ def __repr__(self): self.__class__.__name__, hex(id(self))) def _on_index_changed(self): - self.value_changed.emit(self.toolTip(), self.get_value()) + self.value_changed.emit(self.get_name(), self.get_value()) def items(self): """ @@ -125,6 +150,12 @@ def set_items(self, items): self.clear() self.addItems(items) + def get_name(self): + return self._name + + def set_name(self, name): + self._name = name + def get_value(self): return self.currentText() @@ -133,7 +164,7 @@ def set_value(self, value): idx = self.findText(value, QtCore.Qt.MatchExactly) self.setCurrentIndex(idx) if idx >= 0: - self.value_changed.emit(self.toolTip(), value) + self.value_changed.emit(self.get_name(), value) class PropCheckBox(QtWidgets.QCheckBox): @@ -146,6 +177,7 @@ class PropCheckBox(QtWidgets.QCheckBox): def __init__(self, parent=None): super(PropCheckBox, self).__init__(parent) + self._name = None self.clicked.connect(self._on_clicked) def __repr__(self): @@ -153,7 +185,13 @@ def __repr__(self): self.__class__.__name__, hex(id(self))) def _on_clicked(self): - self.value_changed.emit(self.toolTip(), self.get_value()) + self.value_changed.emit(self.get_name(), self.get_value()) + + def get_name(self): + return self._name + + def set_name(self, name): + self._name = name def get_value(self): return self.isChecked() @@ -162,7 +200,7 @@ def set_value(self, value): _value = bool(value) if _value != self.get_value(): self.setChecked(_value) - self.value_changed.emit(self.toolTip(), _value) + self.value_changed.emit(self.get_name(), _value) class PropSpinBox(QtWidgets.QSpinBox): @@ -174,6 +212,7 @@ class PropSpinBox(QtWidgets.QSpinBox): def __init__(self, parent=None): super(PropSpinBox, self).__init__(parent) + self._name = None self.setButtonSymbols(self.NoButtons) self.valueChanged.connect(self._on_value_change) @@ -182,7 +221,13 @@ def __repr__(self): self.__class__.__name__, hex(id(self))) def _on_value_change(self, value): - self.value_changed.emit(self.toolTip(), value) + self.value_changed.emit(self.get_name(), value) + + def get_name(self): + return self._name + + def set_name(self, name): + self._name = name def get_value(self): return self.value() @@ -202,6 +247,7 @@ class PropDoubleSpinBox(QtWidgets.QDoubleSpinBox): def __init__(self, parent=None): super(PropDoubleSpinBox, self).__init__(parent) + self._name = None self.setButtonSymbols(self.NoButtons) self.valueChanged.connect(self._on_value_change) @@ -210,7 +256,13 @@ def __repr__(self): self.__class__.__name__, hex(id(self))) def _on_value_change(self, value): - self.value_changed.emit(self.toolTip(), value) + self.value_changed.emit(self.get_name(), value) + + def get_name(self): + return self._name + + def set_name(self, name): + self._name = name def get_value(self): return self.value() @@ -231,6 +283,7 @@ def set_value(self, value): # # def __init__(self, parent=None): # super(PropPushButton, self).__init__(parent) +# self._name = None # self.clicked.connect(self.button_clicked.emit) # # def set_on_click_func(self, func, node):