Skip to content

Commit 07feca6

Browse files
authored
Merge pull request #286 from jchanvfx/properties_bin_clean_up
Properties bin clean up
2 parents 34c9356 + 85cdc92 commit 07feca6

21 files changed

+1575
-1520
lines changed

NodeGraphQt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self):
6161
from .widgets.node_widgets import NodeBaseWidget
6262
from .custom_widgets.nodes_tree import NodesTreeWidget
6363
from .custom_widgets.nodes_palette import NodesPaletteWidget
64-
from .custom_widgets.properties_bin import PropertiesBinWidget
64+
from .custom_widgets.properties_bin.node_property_widgets import PropertiesBinWidget
6565

6666

6767
__version__ = VERSION

NodeGraphQt/base/model.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
import json
33
from collections import defaultdict
44

5-
from NodeGraphQt.constants import (
6-
LayoutDirectionEnum,
7-
NODE_PROP,
8-
NODE_PROP_QLABEL,
9-
NODE_PROP_QLINEEDIT,
10-
NODE_PROP_QCHECKBOX,
11-
NODE_PROP_COLORPICKER
12-
)
5+
from NodeGraphQt.constants import LayoutDirectionEnum, NodePropWidgetEnum
136
from NodeGraphQt.errors import NodePropertyError
147

158

@@ -97,40 +90,41 @@ def __init__(self):
9790
# temp store the property widget types.
9891
# (deleted when node is added to the graph)
9992
self._TEMP_property_widget_types = {
100-
'type_': NODE_PROP_QLABEL,
101-
'id': NODE_PROP_QLABEL,
102-
'icon': NODE_PROP,
103-
'name': NODE_PROP_QLINEEDIT,
104-
'color': NODE_PROP_COLORPICKER,
105-
'border_color': NODE_PROP,
106-
'text_color': NODE_PROP_COLORPICKER,
107-
'disabled': NODE_PROP_QCHECKBOX,
108-
'selected': NODE_PROP,
109-
'width': NODE_PROP,
110-
'height': NODE_PROP,
111-
'pos': NODE_PROP,
112-
'layout_direction': NODE_PROP,
113-
'inputs': NODE_PROP,
114-
'outputs': NODE_PROP,
93+
'type_': NodePropWidgetEnum.QLABEL.value,
94+
'id': NodePropWidgetEnum.QLABEL.value,
95+
'icon': NodePropWidgetEnum.HIDDEN.value,
96+
'name': NodePropWidgetEnum.QLINE_EDIT.value,
97+
'color': NodePropWidgetEnum.COLOR_PICKER.value,
98+
'border_color': NodePropWidgetEnum.HIDDEN.value,
99+
'text_color': NodePropWidgetEnum.COLOR_PICKER.value,
100+
'disabled': NodePropWidgetEnum.QCHECK_BOX.value,
101+
'selected': NodePropWidgetEnum.HIDDEN.value,
102+
'width': NodePropWidgetEnum.HIDDEN.value,
103+
'height': NodePropWidgetEnum.HIDDEN.value,
104+
'pos': NodePropWidgetEnum.HIDDEN.value,
105+
'layout_direction': NodePropWidgetEnum.HIDDEN.value,
106+
'inputs': NodePropWidgetEnum.HIDDEN.value,
107+
'outputs': NodePropWidgetEnum.HIDDEN.value,
115108
}
116109

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

121114
def add_property(self, name, value, items=None, range=None,
122-
widget_type=NODE_PROP, tab=None):
115+
widget_type=None, tab=None):
123116
"""
124117
add custom property.
125118
126119
Args:
127120
name (str): name of the property.
128121
value (object): data.
129122
items (list[str]): items used by widget type NODE_PROP_QCOMBO.
130-
range (tuple)): min, max values used by NODE_PROP_SLIDER.
123+
range (tuple): min, max values used by NODE_PROP_SLIDER.
131124
widget_type (int): widget type flag.
132125
tab (str): widget tab name.
133126
"""
127+
widget_type = widget_type or NodePropWidgetEnum.HIDDEN.value
134128
tab = tab or 'Properties'
135129

136130
if name in self.properties.keys():
@@ -150,10 +144,14 @@ def add_property(self, name, value, items=None, range=None,
150144
if range:
151145
self._TEMP_property_attrs[name]['range'] = range
152146
else:
153-
attrs = {self.type_: {name: {
154-
'widget_type': widget_type,
155-
'tab': tab
156-
}}}
147+
attrs = {
148+
self.type_: {
149+
name: {
150+
'widget_type': widget_type,
151+
'tab': tab
152+
}
153+
}
154+
}
157155
if items:
158156
attrs[self.type_][name]['items'] = items
159157
if range:

NodeGraphQt/base/node.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/python
22
from NodeGraphQt.base.commands import PropertyChangedCmd
33
from NodeGraphQt.base.model import NodeModel
4-
from NodeGraphQt.constants import NODE_PROP
4+
from NodeGraphQt.constants import NodePropWidgetEnum
55

66

77
class _ClassProperty(object):
@@ -294,7 +294,7 @@ def set_selected(self, selected=True):
294294
self.set_property('selected', selected)
295295

296296
def create_property(self, name, value, items=None, range=None,
297-
widget_type=NODE_PROP, tab=None):
297+
widget_type=None, tab=None):
298298
"""
299299
Creates a custom property to the node.
300300
@@ -303,34 +303,21 @@ def create_property(self, name, value, items=None, range=None,
303303
:class:`NodeGraphQt.PropertiesBinWidget`
304304
305305
Hint:
306-
Here are some constants variables used to define the node
307-
widget type in the ``PropertiesBinWidget``.
308-
309-
- :attr:`NodeGraphQt.constants.NODE_PROP`
310-
- :attr:`NodeGraphQt.constants.NODE_PROP_QLABEL`
311-
- :attr:`NodeGraphQt.constants.NODE_PROP_QLINEEDIT`
312-
- :attr:`NodeGraphQt.constants.NODE_PROP_QTEXTEDIT`
313-
- :attr:`NodeGraphQt.constants.NODE_PROP_QCOMBO`
314-
- :attr:`NodeGraphQt.constants.NODE_PROP_QCHECKBOX`
315-
- :attr:`NodeGraphQt.constants.NODE_PROP_QSPINBOX`
316-
- :attr:`NodeGraphQt.constants.NODE_PROP_COLORPICKER`
317-
- :attr:`NodeGraphQt.constants.NODE_PROP_FILE`
318-
- :attr:`NodeGraphQt.constants.NODE_PROP_VECTOR2`
319-
- :attr:`NodeGraphQt.constants.NODE_PROP_VECTOR3`
320-
- :attr:`NodeGraphQt.constants.NODE_PROP_VECTOR4`
321-
- :attr:`NodeGraphQt.constants.NODE_PROP_FLOAT`
322-
- :attr:`NodeGraphQt.constants.NODE_PROP_INT`
323-
- :attr:`NodeGraphQt.constants.NODE_PROP_BUTTON`
306+
To see all the available property widget types to display in
307+
the ``PropertiesBinWidget`` widget checkout
308+
:attr:`NodeGraphQt.constants.NodePropWidgetEnum`.
324309
325310
Args:
326311
name (str): name of the property.
327312
value (object): data.
328-
items (list[str]): items used by widget type ``NODE_PROP_QCOMBO``
329-
range (tuple or list): ``(min, max)`` values used by ``NODE_PROP_SLIDER``
313+
items (list[str]): items used by widget type attr:`NodePropWidgetEnum.QCOMBO_BOX`
314+
range (tuple or list): ``(min, max)`` values used by :attr:`NodePropWidgetEnum.SLIDER`
330315
widget_type (int): widget flag to display in the
331316
:class:`NodeGraphQt.PropertiesBinWidget`
332-
tab (str): name of the widget tab to display in the properties bin.
317+
tab (str): name of the widget tab to display in the
318+
:class:`NodeGraphQt.PropertiesBinWidget`.
333319
"""
320+
widget_type = widget_type or NodePropWidgetEnum.HIDDEN.value
334321
self.model.add_property(name, value, items, range, widget_type, tab)
335322

336323
def properties(self):
@@ -494,4 +481,3 @@ def set_layout_direction(self, value=0):
494481
"""
495482
self.model.layout_direction = value
496483
self.view.layout_direction = value
497-

NodeGraphQt/constants.py

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -203,37 +203,46 @@ class PipeLayoutEnum(Enum):
203203

204204
# === PROPERTY BIN WIDGET ===
205205

206-
#: Property type will hidden in the properties bin (default).
207-
NODE_PROP = 0
208-
#: Property type represented with a QLabel widget in the properties bin.
209-
NODE_PROP_QLABEL = 2
210-
#: Property type represented with a QLineEdit widget in the properties bin.
211-
NODE_PROP_QLINEEDIT = 3
212-
#: Property type represented with a QTextEdit widget in the properties bin.
213-
NODE_PROP_QTEXTEDIT = 4
214-
#: Property type represented with a QComboBox widget in the properties bin.
215-
NODE_PROP_QCOMBO = 5
216-
#: Property type represented with a QCheckBox widget in the properties bin.
217-
NODE_PROP_QCHECKBOX = 6
218-
#: Property type represented with a QSpinBox widget in the properties bin.
219-
NODE_PROP_QSPINBOX = 7
220-
#: Property type represented with a ColorPicker widget in the properties bin.
221-
NODE_PROP_COLORPICKER = 8
222-
#: Property type represented with a Slider widget in the properties bin.
223-
NODE_PROP_SLIDER = 9
224-
#: Property type represented with a file selector widget in the properties bin.
225-
NODE_PROP_FILE = 10
226-
#: Property type represented with a file save widget in the properties bin.
227-
NODE_PROP_FILE_SAVE = 11
228-
#: Property type represented with a vector2 widget in the properties bin.
229-
NODE_PROP_VECTOR2 = 12
230-
#: Property type represented with vector3 widget in the properties bin.
231-
NODE_PROP_VECTOR3 = 13
232-
#: Property type represented with vector4 widget in the properties bin.
233-
NODE_PROP_VECTOR4 = 14
234-
#: Property type represented with float widget in the properties bin.
235-
NODE_PROP_FLOAT = 15
236-
#: Property type represented with int widget in the properties bin.
237-
NODE_PROP_INT = 16
238-
#: Property type represented with button widget in the properties bin.
239-
NODE_PROP_BUTTON = 17
206+
class NodePropWidgetEnum(Enum):
207+
"""
208+
Mapping used for the :class:`NodeGraphQt.PropertiesBinWidget` to display a
209+
node property in the specified widget type.
210+
211+
:py:mod:`NodeGraphQt.constants.NodePropWidgetEnum`
212+
"""
213+
#: Node property will be hidden in the ``PropertiesBinWidget`` (default).
214+
HIDDEN = 0
215+
#: Node property represented with a ``QLabel`` widget.
216+
QLABEL = 2
217+
#: Node property represented with a ``QLineEdit`` widget.
218+
QLINE_EDIT = 3
219+
#: Node property represented with a ``QTextEdit`` widget.
220+
QTEXT_EDIT = 4
221+
#: Node property represented with a ``QComboBox`` widget.
222+
QCOMBO_BOX = 5
223+
#: Node property represented with a ``QCheckBox`` widget.
224+
QCHECK_BOX = 6
225+
#: Node property represented with a ``QSpinBox`` widget.
226+
QSPIN_BOX = 7
227+
#: Node property represented with a ``QDoubleSpinBox`` widget.
228+
QDOUBLESPIN_BOX = 8
229+
#: Node property represented with a ColorPicker widget.
230+
COLOR_PICKER = 9
231+
#: Node property represented with a Slider widget.
232+
SLIDER = 10
233+
#: Node property represented with a file selector widget.
234+
FILE_OPEN = 11
235+
#: Node property represented with a file save widget.
236+
FILE_SAVE = 12
237+
#: Node property represented with a vector2 widget.
238+
VECTOR2 = 13
239+
#: Node property represented with vector3 widget.
240+
VECTOR3 = 14
241+
#: Node property represented with vector4 widget.
242+
VECTOR4 = 15
243+
#: Node property represented with float line edit widget.
244+
FLOAT = 16
245+
#: Node property represented with int line edit widget.
246+
INT = 17
247+
#: Node property represented with button widget.
248+
BUTTON = 18

0 commit comments

Comments
 (0)