Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NodeGraphQt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self):
from .widgets.node_widgets import NodeBaseWidget
from .custom_widgets.nodes_tree import NodesTreeWidget
from .custom_widgets.nodes_palette import NodesPaletteWidget
from .custom_widgets.properties_bin import PropertiesBinWidget
from .custom_widgets.properties_bin.node_property_widgets import PropertiesBinWidget


__version__ = VERSION
Expand Down
56 changes: 27 additions & 29 deletions NodeGraphQt/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
import json
from collections import defaultdict

from NodeGraphQt.constants import (
LayoutDirectionEnum,
NODE_PROP,
NODE_PROP_QLABEL,
NODE_PROP_QLINEEDIT,
NODE_PROP_QCHECKBOX,
NODE_PROP_COLORPICKER
)
from NodeGraphQt.constants import LayoutDirectionEnum, NodePropWidgetEnum
from NodeGraphQt.errors import NodePropertyError


Expand Down Expand Up @@ -97,40 +90,41 @@ def __init__(self):
# temp store the property widget types.
# (deleted when node is added to the graph)
self._TEMP_property_widget_types = {
'type_': NODE_PROP_QLABEL,
'id': NODE_PROP_QLABEL,
'icon': NODE_PROP,
'name': NODE_PROP_QLINEEDIT,
'color': NODE_PROP_COLORPICKER,
'border_color': NODE_PROP,
'text_color': NODE_PROP_COLORPICKER,
'disabled': NODE_PROP_QCHECKBOX,
'selected': NODE_PROP,
'width': NODE_PROP,
'height': NODE_PROP,
'pos': NODE_PROP,
'layout_direction': NODE_PROP,
'inputs': NODE_PROP,
'outputs': NODE_PROP,
'type_': NodePropWidgetEnum.QLABEL.value,
'id': NodePropWidgetEnum.QLABEL.value,
'icon': NodePropWidgetEnum.HIDDEN.value,
'name': NodePropWidgetEnum.QLINE_EDIT.value,
'color': NodePropWidgetEnum.COLOR_PICKER.value,
'border_color': NodePropWidgetEnum.HIDDEN.value,
'text_color': NodePropWidgetEnum.COLOR_PICKER.value,
'disabled': NodePropWidgetEnum.QCHECK_BOX.value,
'selected': NodePropWidgetEnum.HIDDEN.value,
'width': NodePropWidgetEnum.HIDDEN.value,
'height': NodePropWidgetEnum.HIDDEN.value,
'pos': NodePropWidgetEnum.HIDDEN.value,
'layout_direction': NodePropWidgetEnum.HIDDEN.value,
'inputs': NodePropWidgetEnum.HIDDEN.value,
'outputs': NodePropWidgetEnum.HIDDEN.value,
}

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

def add_property(self, name, value, items=None, range=None,
widget_type=NODE_PROP, tab=None):
widget_type=None, tab=None):
"""
add custom property.

Args:
name (str): name of the property.
value (object): data.
items (list[str]): items used by widget type NODE_PROP_QCOMBO.
range (tuple)): min, max values used by NODE_PROP_SLIDER.
range (tuple): min, max values used by NODE_PROP_SLIDER.
widget_type (int): widget type flag.
tab (str): widget tab name.
"""
widget_type = widget_type or NodePropWidgetEnum.HIDDEN.value
tab = tab or 'Properties'

if name in self.properties.keys():
Expand All @@ -150,10 +144,14 @@ def add_property(self, name, value, items=None, range=None,
if range:
self._TEMP_property_attrs[name]['range'] = range
else:
attrs = {self.type_: {name: {
'widget_type': widget_type,
'tab': tab
}}}
attrs = {
self.type_: {
name: {
'widget_type': widget_type,
'tab': tab
}
}
}
if items:
attrs[self.type_][name]['items'] = items
if range:
Expand Down
34 changes: 10 additions & 24 deletions NodeGraphQt/base/node.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
from NodeGraphQt.base.commands import PropertyChangedCmd
from NodeGraphQt.base.model import NodeModel
from NodeGraphQt.constants import NODE_PROP
from NodeGraphQt.constants import NodePropWidgetEnum


class _ClassProperty(object):
Expand Down Expand Up @@ -294,7 +294,7 @@ def set_selected(self, selected=True):
self.set_property('selected', selected)

def create_property(self, name, value, items=None, range=None,
widget_type=NODE_PROP, tab=None):
widget_type=None, tab=None):
"""
Creates a custom property to the node.

Expand All @@ -303,34 +303,21 @@ def create_property(self, name, value, items=None, range=None,
:class:`NodeGraphQt.PropertiesBinWidget`

Hint:
Here are some constants variables used to define the node
widget type in the ``PropertiesBinWidget``.

- :attr:`NodeGraphQt.constants.NODE_PROP`
- :attr:`NodeGraphQt.constants.NODE_PROP_QLABEL`
- :attr:`NodeGraphQt.constants.NODE_PROP_QLINEEDIT`
- :attr:`NodeGraphQt.constants.NODE_PROP_QTEXTEDIT`
- :attr:`NodeGraphQt.constants.NODE_PROP_QCOMBO`
- :attr:`NodeGraphQt.constants.NODE_PROP_QCHECKBOX`
- :attr:`NodeGraphQt.constants.NODE_PROP_QSPINBOX`
- :attr:`NodeGraphQt.constants.NODE_PROP_COLORPICKER`
- :attr:`NodeGraphQt.constants.NODE_PROP_FILE`
- :attr:`NodeGraphQt.constants.NODE_PROP_VECTOR2`
- :attr:`NodeGraphQt.constants.NODE_PROP_VECTOR3`
- :attr:`NodeGraphQt.constants.NODE_PROP_VECTOR4`
- :attr:`NodeGraphQt.constants.NODE_PROP_FLOAT`
- :attr:`NodeGraphQt.constants.NODE_PROP_INT`
- :attr:`NodeGraphQt.constants.NODE_PROP_BUTTON`
To see all the available property widget types to display in
the ``PropertiesBinWidget`` widget checkout
:attr:`NodeGraphQt.constants.NodePropWidgetEnum`.

Args:
name (str): name of the property.
value (object): data.
items (list[str]): items used by widget type ``NODE_PROP_QCOMBO``
range (tuple or list): ``(min, max)`` values used by ``NODE_PROP_SLIDER``
items (list[str]): items used by widget type attr:`NodePropWidgetEnum.QCOMBO_BOX`
range (tuple or list): ``(min, max)`` values used by :attr:`NodePropWidgetEnum.SLIDER`
widget_type (int): widget flag to display in the
:class:`NodeGraphQt.PropertiesBinWidget`
tab (str): name of the widget tab to display in the properties bin.
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)

def properties(self):
Expand Down Expand Up @@ -494,4 +481,3 @@ def set_layout_direction(self, value=0):
"""
self.model.layout_direction = value
self.view.layout_direction = value

77 changes: 43 additions & 34 deletions NodeGraphQt/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,37 +203,46 @@ class PipeLayoutEnum(Enum):

# === PROPERTY BIN WIDGET ===

#: Property type will hidden in the properties bin (default).
NODE_PROP = 0
#: Property type represented with a QLabel widget in the properties bin.
NODE_PROP_QLABEL = 2
#: Property type represented with a QLineEdit widget in the properties bin.
NODE_PROP_QLINEEDIT = 3
#: Property type represented with a QTextEdit widget in the properties bin.
NODE_PROP_QTEXTEDIT = 4
#: Property type represented with a QComboBox widget in the properties bin.
NODE_PROP_QCOMBO = 5
#: Property type represented with a QCheckBox widget in the properties bin.
NODE_PROP_QCHECKBOX = 6
#: Property type represented with a QSpinBox widget in the properties bin.
NODE_PROP_QSPINBOX = 7
#: Property type represented with a ColorPicker widget in the properties bin.
NODE_PROP_COLORPICKER = 8
#: Property type represented with a Slider widget in the properties bin.
NODE_PROP_SLIDER = 9
#: Property type represented with a file selector widget in the properties bin.
NODE_PROP_FILE = 10
#: Property type represented with a file save widget in the properties bin.
NODE_PROP_FILE_SAVE = 11
#: Property type represented with a vector2 widget in the properties bin.
NODE_PROP_VECTOR2 = 12
#: Property type represented with vector3 widget in the properties bin.
NODE_PROP_VECTOR3 = 13
#: Property type represented with vector4 widget in the properties bin.
NODE_PROP_VECTOR4 = 14
#: Property type represented with float widget in the properties bin.
NODE_PROP_FLOAT = 15
#: Property type represented with int widget in the properties bin.
NODE_PROP_INT = 16
#: Property type represented with button widget in the properties bin.
NODE_PROP_BUTTON = 17
class NodePropWidgetEnum(Enum):
"""
Mapping used for the :class:`NodeGraphQt.PropertiesBinWidget` to display a
node property in the specified widget type.

:py:mod:`NodeGraphQt.constants.NodePropWidgetEnum`
"""
#: Node property will be hidden in the ``PropertiesBinWidget`` (default).
HIDDEN = 0
#: Node property represented with a ``QLabel`` widget.
QLABEL = 2
#: Node property represented with a ``QLineEdit`` widget.
QLINE_EDIT = 3
#: Node property represented with a ``QTextEdit`` widget.
QTEXT_EDIT = 4
#: Node property represented with a ``QComboBox`` widget.
QCOMBO_BOX = 5
#: Node property represented with a ``QCheckBox`` widget.
QCHECK_BOX = 6
#: Node property represented with a ``QSpinBox`` widget.
QSPIN_BOX = 7
#: Node property represented with a ``QDoubleSpinBox`` widget.
QDOUBLESPIN_BOX = 8
#: Node property represented with a ColorPicker widget.
COLOR_PICKER = 9
#: Node property represented with a Slider widget.
SLIDER = 10
#: Node property represented with a file selector widget.
FILE_OPEN = 11
#: Node property represented with a file save widget.
FILE_SAVE = 12
#: Node property represented with a vector2 widget.
VECTOR2 = 13
#: Node property represented with vector3 widget.
VECTOR3 = 14
#: Node property represented with vector4 widget.
VECTOR4 = 15
#: Node property represented with float line edit widget.
FLOAT = 16
#: Node property represented with int line edit widget.
INT = 17
#: Node property represented with button widget.
BUTTON = 18
Loading