-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathNumberlistNode.py
129 lines (106 loc) · 3.26 KB
/
NumberlistNode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import bpy
from bpy.types import Node
from . MindmapNodeBase import MindmapTreeNode
# Numberlist Node
class NumberlistNode(Node, MindmapTreeNode):
'''A Numberlist node'''
# Optional. If not explicitly defined, the python class name is used.
bl_idname = 'NumberlistNodeType'
# Label for nice name display
bl_label = "Numberlist"
# Icon identifier
bl_icon = 'LINENUMBERS_ON'
# === Custom Properties ===
numberlist_length: bpy.props.IntProperty(
name='Items', # noqa: F821
default=1,
min=1,
max=10
)
string_0: bpy.props.StringProperty(
name='1',
default=''
)
string_1: bpy.props.StringProperty(
name='2',
default=''
)
string_2: bpy.props.StringProperty(
name='3',
default=''
)
string_3: bpy.props.StringProperty(
name='4',
default=''
)
string_4: bpy.props.StringProperty(
name='5',
default=''
)
string_5: bpy.props.StringProperty(
name='6',
default=''
)
string_6: bpy.props.StringProperty(
name='7',
default=''
)
string_7: bpy.props.StringProperty(
name='8',
default=''
)
string_8: bpy.props.StringProperty(
name='9',
default=''
)
string_9: bpy.props.StringProperty(
name='10',
default=''
)
string_10: bpy.props.StringProperty(
name='11',
default=''
)
my_title_prop: bpy.props.StringProperty(
name='',
default='Numberlist' # noqa: F821
)
my_node_color: bpy.props.FloatVectorProperty(
name='',
default=(0, 0.3, 0),
subtype='COLOR', # noqa: F821
)
# === Optional Functions ===
# Initialization function, called when a new node is created.
def init(self, context):
self.use_custom_color = True
self.color = self.my_node_color
self.width = 250
# Copy function to initialize a copied node from an existing one.
def copy(self, node):
print("Copying from node ", node)
# Free function to clean up on removal.
def free(self):
print("Removing node ", self, ", Goodbye!")
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
column = layout.column(align=True)
column.alignment = 'CENTER'
for i in range(self.numberlist_length):
text = f"string_{i}"
column.prop(self, text)
row = layout.row(align=True)
row.prop(self, 'numberlist_length', icon='PRESET')
row.prop(self, 'color', text='', icon='MATERIAL')
# Detail buttons in the sidebar.
# If function is not defined, the draw_buttons function is used instead
def draw_buttons_ext(self, context, layout):
column = layout.column()
row = column.row()
row.prop(self, "my_title_prop", icon='GREASEPENCIL')
# Optional: custom label
# Explicit user label overrides, but here we can define a label dynamically
def draw_label(self):
return self.my_title_prop
def update(self):
self.my_title_prop = self.my_title_prop