io_mesh_uv_layout: speed up png export with OIIO (x7)
[blender-addons.git] / node_wrangler / preferences.py
blob970f6a0fc3c25fc2d1e52872701dbb29cd232c89
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import bpy
4 from bpy.props import EnumProperty, BoolProperty, StringProperty
5 from nodeitems_utils import node_categories_iter
7 from . import operators
8 from . import interface
10 from .utils.constants import nice_hotkey_name
13 # Principled prefs
14 class NWPrincipledPreferences(bpy.types.PropertyGroup):
15 base_color: StringProperty(
16 name='Base Color',
17 default='diffuse diff albedo base col color basecolor',
18 description='Naming Components for Base Color maps')
19 sss_color: StringProperty(
20 name='Subsurface Color',
21 default='sss subsurface',
22 description='Naming Components for Subsurface Color maps')
23 metallic: StringProperty(
24 name='Metallic',
25 default='metallic metalness metal mtl',
26 description='Naming Components for metallness maps')
27 specular: StringProperty(
28 name='Specular',
29 default='specularity specular spec spc',
30 description='Naming Components for Specular maps')
31 normal: StringProperty(
32 name='Normal',
33 default='normal nor nrm nrml norm',
34 description='Naming Components for Normal maps')
35 bump: StringProperty(
36 name='Bump',
37 default='bump bmp',
38 description='Naming Components for bump maps')
39 rough: StringProperty(
40 name='Roughness',
41 default='roughness rough rgh',
42 description='Naming Components for roughness maps')
43 gloss: StringProperty(
44 name='Gloss',
45 default='gloss glossy glossiness',
46 description='Naming Components for glossy maps')
47 displacement: StringProperty(
48 name='Displacement',
49 default='displacement displace disp dsp height heightmap',
50 description='Naming Components for displacement maps')
51 transmission: StringProperty(
52 name='Transmission',
53 default='transmission transparency',
54 description='Naming Components for transmission maps')
55 emission: StringProperty(
56 name='Emission',
57 default='emission emissive emit',
58 description='Naming Components for emission maps')
59 alpha: StringProperty(
60 name='Alpha',
61 default='alpha opacity',
62 description='Naming Components for alpha maps')
63 ambient_occlusion: StringProperty(
64 name='Ambient Occlusion',
65 default='ao ambient occlusion',
66 description='Naming Components for AO maps')
69 # Addon prefs
70 class NWNodeWrangler(bpy.types.AddonPreferences):
71 bl_idname = __package__
73 merge_hide: EnumProperty(
74 name="Hide Mix nodes",
75 items=(
76 ("ALWAYS", "Always", "Always collapse the new merge nodes"),
77 ("NON_SHADER", "Non-Shader", "Collapse in all cases except for shaders"),
78 ("NEVER", "Never", "Never collapse the new merge nodes")
80 default='NON_SHADER',
81 description="When merging nodes with the Ctrl+Numpad0 hotkey (and similar) specify whether to collapse them or show the full node with options expanded")
82 merge_position: EnumProperty(
83 name="Mix Node Position",
84 items=(
85 ("CENTER", "Center", "Place the Mix node between the two nodes"),
86 ("BOTTOM", "Bottom", "Place the Mix node at the same height as the lowest node")
88 default='CENTER',
89 description="When merging nodes with the Ctrl+Numpad0 hotkey (and similar) specify the position of the new nodes")
91 show_hotkey_list: BoolProperty(
92 name="Show Hotkey List",
93 default=False,
94 description="Expand this box into a list of all the hotkeys for functions in this addon"
96 hotkey_list_filter: StringProperty(
97 name=" Filter by Name",
98 default="",
99 description="Show only hotkeys that have this text in their name",
100 options={'TEXTEDIT_UPDATE'}
102 show_principled_lists: BoolProperty(
103 name="Show Principled naming tags",
104 default=False,
105 description="Expand this box into a list of all naming tags for principled texture setup"
107 principled_tags: bpy.props.PointerProperty(type=NWPrincipledPreferences)
109 def draw(self, context):
110 layout = self.layout
111 col = layout.column()
112 col.prop(self, "merge_position")
113 col.prop(self, "merge_hide")
115 box = layout.box()
116 col = box.column(align=True)
117 col.prop(
118 self,
119 "show_principled_lists",
120 text='Edit tags for auto texture detection in Principled BSDF setup',
121 toggle=True)
122 if self.show_principled_lists:
123 tags = self.principled_tags
125 col.prop(tags, "base_color")
126 col.prop(tags, "sss_color")
127 col.prop(tags, "metallic")
128 col.prop(tags, "specular")
129 col.prop(tags, "rough")
130 col.prop(tags, "gloss")
131 col.prop(tags, "normal")
132 col.prop(tags, "bump")
133 col.prop(tags, "displacement")
134 col.prop(tags, "transmission")
135 col.prop(tags, "emission")
136 col.prop(tags, "alpha")
137 col.prop(tags, "ambient_occlusion")
139 box = layout.box()
140 col = box.column(align=True)
141 hotkey_button_name = "Show Hotkey List"
142 if self.show_hotkey_list:
143 hotkey_button_name = "Hide Hotkey List"
144 col.prop(self, "show_hotkey_list", text=hotkey_button_name, toggle=True)
145 if self.show_hotkey_list:
146 col.prop(self, "hotkey_list_filter", icon="VIEWZOOM")
147 col.separator()
148 for hotkey in kmi_defs:
149 if hotkey[7]:
150 hotkey_name = hotkey[7]
152 if self.hotkey_list_filter.lower() in hotkey_name.lower():
153 row = col.row(align=True)
154 row.label(text=hotkey_name)
155 keystr = nice_hotkey_name(hotkey[1])
156 if hotkey[4]:
157 keystr = "Shift " + keystr
158 if hotkey[5]:
159 keystr = "Alt " + keystr
160 if hotkey[3]:
161 keystr = "Ctrl " + keystr
162 row.label(text=keystr)
166 # REGISTER/UNREGISTER CLASSES AND KEYMAP ITEMS
168 switch_category_menus = []
169 addon_keymaps = []
170 # kmi_defs entry: (identifier, key, action, CTRL, SHIFT, ALT, props, nice name)
171 # props entry: (property name, property value)
172 kmi_defs = (
173 # MERGE NODES
174 # NWMergeNodes with Ctrl (AUTO).
175 (operators.NWMergeNodes.bl_idname, 'NUMPAD_0', 'PRESS', True, False, False,
176 (('mode', 'MIX'), ('merge_type', 'AUTO'),), "Merge Nodes (Automatic)"),
177 (operators.NWMergeNodes.bl_idname, 'ZERO', 'PRESS', True, False, False,
178 (('mode', 'MIX'), ('merge_type', 'AUTO'),), "Merge Nodes (Automatic)"),
179 (operators.NWMergeNodes.bl_idname, 'NUMPAD_PLUS', 'PRESS', True, False, False,
180 (('mode', 'ADD'), ('merge_type', 'AUTO'),), "Merge Nodes (Add)"),
181 (operators.NWMergeNodes.bl_idname, 'EQUAL', 'PRESS', True, False, False,
182 (('mode', 'ADD'), ('merge_type', 'AUTO'),), "Merge Nodes (Add)"),
183 (operators.NWMergeNodes.bl_idname, 'NUMPAD_ASTERIX', 'PRESS', True, False, False,
184 (('mode', 'MULTIPLY'), ('merge_type', 'AUTO'),), "Merge Nodes (Multiply)"),
185 (operators.NWMergeNodes.bl_idname, 'EIGHT', 'PRESS', True, False, False,
186 (('mode', 'MULTIPLY'), ('merge_type', 'AUTO'),), "Merge Nodes (Multiply)"),
187 (operators.NWMergeNodes.bl_idname, 'NUMPAD_MINUS', 'PRESS', True, False, False,
188 (('mode', 'SUBTRACT'), ('merge_type', 'AUTO'),), "Merge Nodes (Subtract)"),
189 (operators.NWMergeNodes.bl_idname, 'MINUS', 'PRESS', True, False, False,
190 (('mode', 'SUBTRACT'), ('merge_type', 'AUTO'),), "Merge Nodes (Subtract)"),
191 (operators.NWMergeNodes.bl_idname, 'NUMPAD_SLASH', 'PRESS', True, False, False,
192 (('mode', 'DIVIDE'), ('merge_type', 'AUTO'),), "Merge Nodes (Divide)"),
193 (operators.NWMergeNodes.bl_idname, 'SLASH', 'PRESS', True, False, False,
194 (('mode', 'DIVIDE'), ('merge_type', 'AUTO'),), "Merge Nodes (Divide)"),
195 (operators.NWMergeNodes.bl_idname, 'COMMA', 'PRESS', True, False, False,
196 (('mode', 'LESS_THAN'), ('merge_type', 'MATH'),), "Merge Nodes (Less than)"),
197 (operators.NWMergeNodes.bl_idname, 'PERIOD', 'PRESS', True, False, False,
198 (('mode', 'GREATER_THAN'), ('merge_type', 'MATH'),), "Merge Nodes (Greater than)"),
199 (operators.NWMergeNodes.bl_idname, 'NUMPAD_PERIOD', 'PRESS', True, False, False,
200 (('mode', 'MIX'), ('merge_type', 'ZCOMBINE'),), "Merge Nodes (Z-Combine)"),
201 # NWMergeNodes with Ctrl Alt (MIX or ALPHAOVER)
202 (operators.NWMergeNodes.bl_idname, 'NUMPAD_0', 'PRESS', True, False, True,
203 (('mode', 'MIX'), ('merge_type', 'ALPHAOVER'),), "Merge Nodes (Alpha Over)"),
204 (operators.NWMergeNodes.bl_idname, 'ZERO', 'PRESS', True, False, True,
205 (('mode', 'MIX'), ('merge_type', 'ALPHAOVER'),), "Merge Nodes (Alpha Over)"),
206 (operators.NWMergeNodes.bl_idname, 'NUMPAD_PLUS', 'PRESS', True, False, True,
207 (('mode', 'ADD'), ('merge_type', 'MIX'),), "Merge Nodes (Color, Add)"),
208 (operators.NWMergeNodes.bl_idname, 'EQUAL', 'PRESS', True, False, True,
209 (('mode', 'ADD'), ('merge_type', 'MIX'),), "Merge Nodes (Color, Add)"),
210 (operators.NWMergeNodes.bl_idname, 'NUMPAD_ASTERIX', 'PRESS', True, False, True,
211 (('mode', 'MULTIPLY'), ('merge_type', 'MIX'),), "Merge Nodes (Color, Multiply)"),
212 (operators.NWMergeNodes.bl_idname, 'EIGHT', 'PRESS', True, False, True,
213 (('mode', 'MULTIPLY'), ('merge_type', 'MIX'),), "Merge Nodes (Color, Multiply)"),
214 (operators.NWMergeNodes.bl_idname, 'NUMPAD_MINUS', 'PRESS', True, False, True,
215 (('mode', 'SUBTRACT'), ('merge_type', 'MIX'),), "Merge Nodes (Color, Subtract)"),
216 (operators.NWMergeNodes.bl_idname, 'MINUS', 'PRESS', True, False, True,
217 (('mode', 'SUBTRACT'), ('merge_type', 'MIX'),), "Merge Nodes (Color, Subtract)"),
218 (operators.NWMergeNodes.bl_idname, 'NUMPAD_SLASH', 'PRESS', True, False, True,
219 (('mode', 'DIVIDE'), ('merge_type', 'MIX'),), "Merge Nodes (Color, Divide)"),
220 (operators.NWMergeNodes.bl_idname, 'SLASH', 'PRESS', True, False, True,
221 (('mode', 'DIVIDE'), ('merge_type', 'MIX'),), "Merge Nodes (Color, Divide)"),
222 # NWMergeNodes with Ctrl Shift (MATH)
223 (operators.NWMergeNodes.bl_idname, 'NUMPAD_PLUS', 'PRESS', True, True, False,
224 (('mode', 'ADD'), ('merge_type', 'MATH'),), "Merge Nodes (Math, Add)"),
225 (operators.NWMergeNodes.bl_idname, 'EQUAL', 'PRESS', True, True, False,
226 (('mode', 'ADD'), ('merge_type', 'MATH'),), "Merge Nodes (Math, Add)"),
227 (operators.NWMergeNodes.bl_idname, 'NUMPAD_ASTERIX', 'PRESS', True, True, False,
228 (('mode', 'MULTIPLY'), ('merge_type', 'MATH'),), "Merge Nodes (Math, Multiply)"),
229 (operators.NWMergeNodes.bl_idname, 'EIGHT', 'PRESS', True, True, False,
230 (('mode', 'MULTIPLY'), ('merge_type', 'MATH'),), "Merge Nodes (Math, Multiply)"),
231 (operators.NWMergeNodes.bl_idname, 'NUMPAD_MINUS', 'PRESS', True, True, False,
232 (('mode', 'SUBTRACT'), ('merge_type', 'MATH'),), "Merge Nodes (Math, Subtract)"),
233 (operators.NWMergeNodes.bl_idname, 'MINUS', 'PRESS', True, True, False,
234 (('mode', 'SUBTRACT'), ('merge_type', 'MATH'),), "Merge Nodes (Math, Subtract)"),
235 (operators.NWMergeNodes.bl_idname, 'NUMPAD_SLASH', 'PRESS', True, True, False,
236 (('mode', 'DIVIDE'), ('merge_type', 'MATH'),), "Merge Nodes (Math, Divide)"),
237 (operators.NWMergeNodes.bl_idname, 'SLASH', 'PRESS', True, True, False,
238 (('mode', 'DIVIDE'), ('merge_type', 'MATH'),), "Merge Nodes (Math, Divide)"),
239 (operators.NWMergeNodes.bl_idname, 'COMMA', 'PRESS', True, True, False,
240 (('mode', 'LESS_THAN'), ('merge_type', 'MATH'),), "Merge Nodes (Math, Less than)"),
241 (operators.NWMergeNodes.bl_idname, 'PERIOD', 'PRESS', True, True, False,
242 (('mode', 'GREATER_THAN'), ('merge_type', 'MATH'),), "Merge Nodes (Math, Greater than)"),
243 # BATCH CHANGE NODES
244 # NWBatchChangeNodes with Alt
245 (operators.NWBatchChangeNodes.bl_idname, 'NUMPAD_0', 'PRESS', False, False, True,
246 (('blend_type', 'MIX'), ('operation', 'CURRENT'),), "Batch change blend type (Mix)"),
247 (operators.NWBatchChangeNodes.bl_idname, 'ZERO', 'PRESS', False, False, True,
248 (('blend_type', 'MIX'), ('operation', 'CURRENT'),), "Batch change blend type (Mix)"),
249 (operators.NWBatchChangeNodes.bl_idname, 'NUMPAD_PLUS', 'PRESS', False, False, True,
250 (('blend_type', 'ADD'), ('operation', 'ADD'),), "Batch change blend type (Add)"),
251 (operators.NWBatchChangeNodes.bl_idname, 'EQUAL', 'PRESS', False, False, True,
252 (('blend_type', 'ADD'), ('operation', 'ADD'),), "Batch change blend type (Add)"),
253 (operators.NWBatchChangeNodes.bl_idname, 'NUMPAD_ASTERIX', 'PRESS', False, False, True,
254 (('blend_type', 'MULTIPLY'), ('operation', 'MULTIPLY'),), "Batch change blend type (Multiply)"),
255 (operators.NWBatchChangeNodes.bl_idname, 'EIGHT', 'PRESS', False, False, True,
256 (('blend_type', 'MULTIPLY'), ('operation', 'MULTIPLY'),), "Batch change blend type (Multiply)"),
257 (operators.NWBatchChangeNodes.bl_idname, 'NUMPAD_MINUS', 'PRESS', False, False, True,
258 (('blend_type', 'SUBTRACT'), ('operation', 'SUBTRACT'),), "Batch change blend type (Subtract)"),
259 (operators.NWBatchChangeNodes.bl_idname, 'MINUS', 'PRESS', False, False, True,
260 (('blend_type', 'SUBTRACT'), ('operation', 'SUBTRACT'),), "Batch change blend type (Subtract)"),
261 (operators.NWBatchChangeNodes.bl_idname, 'NUMPAD_SLASH', 'PRESS', False, False, True,
262 (('blend_type', 'DIVIDE'), ('operation', 'DIVIDE'),), "Batch change blend type (Divide)"),
263 (operators.NWBatchChangeNodes.bl_idname, 'SLASH', 'PRESS', False, False, True,
264 (('blend_type', 'DIVIDE'), ('operation', 'DIVIDE'),), "Batch change blend type (Divide)"),
265 (operators.NWBatchChangeNodes.bl_idname, 'COMMA', 'PRESS', False, False, True,
266 (('blend_type', 'CURRENT'), ('operation', 'LESS_THAN'),), "Batch change blend type (Current)"),
267 (operators.NWBatchChangeNodes.bl_idname, 'PERIOD', 'PRESS', False, False, True,
268 (('blend_type', 'CURRENT'), ('operation', 'GREATER_THAN'),), "Batch change blend type (Current)"),
269 (operators.NWBatchChangeNodes.bl_idname, 'DOWN_ARROW', 'PRESS', False, False, True,
270 (('blend_type', 'NEXT'), ('operation', 'NEXT'),), "Batch change blend type (Next)"),
271 (operators.NWBatchChangeNodes.bl_idname, 'UP_ARROW', 'PRESS', False, False, True,
272 (('blend_type', 'PREV'), ('operation', 'PREV'),), "Batch change blend type (Previous)"),
273 # LINK ACTIVE TO SELECTED
274 # Don't use names, don't replace links (K)
275 (operators.NWLinkActiveToSelected.bl_idname, 'K', 'PRESS', False, False, False,
276 (('replace', False), ('use_node_name', False), ('use_outputs_names', False),), "Link active to selected (Don't replace links)"),
277 # Don't use names, replace links (Shift K)
278 (operators.NWLinkActiveToSelected.bl_idname, 'K', 'PRESS', False, True, False,
279 (('replace', True), ('use_node_name', False), ('use_outputs_names', False),), "Link active to selected (Replace links)"),
280 # Use node name, don't replace links (')
281 (operators.NWLinkActiveToSelected.bl_idname, 'QUOTE', 'PRESS', False, False, False,
282 (('replace', False), ('use_node_name', True), ('use_outputs_names', False),), "Link active to selected (Don't replace links, node names)"),
283 # Use node name, replace links (Shift ')
284 (operators.NWLinkActiveToSelected.bl_idname, 'QUOTE', 'PRESS', False, True, False,
285 (('replace', True), ('use_node_name', True), ('use_outputs_names', False),), "Link active to selected (Replace links, node names)"),
286 # Don't use names, don't replace links (;)
287 (operators.NWLinkActiveToSelected.bl_idname, 'SEMI_COLON', 'PRESS', False, False, False,
288 (('replace', False), ('use_node_name', False), ('use_outputs_names', True),), "Link active to selected (Don't replace links, output names)"),
289 # Don't use names, replace links (')
290 (operators.NWLinkActiveToSelected.bl_idname, 'SEMI_COLON', 'PRESS', False, True, False,
291 (('replace', True), ('use_node_name', False), ('use_outputs_names', True),), "Link active to selected (Replace links, output names)"),
292 # CHANGE MIX FACTOR
293 (operators.NWChangeMixFactor.bl_idname, 'LEFT_ARROW', 'PRESS', False,
294 False, True, (('option', -0.1),), "Reduce Mix Factor by 0.1"),
295 (operators.NWChangeMixFactor.bl_idname, 'RIGHT_ARROW', 'PRESS', False,
296 False, True, (('option', 0.1),), "Increase Mix Factor by 0.1"),
297 (operators.NWChangeMixFactor.bl_idname, 'LEFT_ARROW', 'PRESS', False,
298 True, True, (('option', -0.01),), "Reduce Mix Factor by 0.01"),
299 (operators.NWChangeMixFactor.bl_idname, 'RIGHT_ARROW', 'PRESS', False,
300 True, True, (('option', 0.01),), "Increase Mix Factor by 0.01"),
301 (operators.NWChangeMixFactor.bl_idname, 'LEFT_ARROW', 'PRESS',
302 True, True, True, (('option', 0.0),), "Set Mix Factor to 0.0"),
303 (operators.NWChangeMixFactor.bl_idname, 'RIGHT_ARROW', 'PRESS',
304 True, True, True, (('option', 1.0),), "Set Mix Factor to 1.0"),
305 (operators.NWChangeMixFactor.bl_idname, 'NUMPAD_0', 'PRESS',
306 True, True, True, (('option', 0.0),), "Set Mix Factor to 0.0"),
307 (operators.NWChangeMixFactor.bl_idname, 'ZERO', 'PRESS', True, True, True, (('option', 0.0),), "Set Mix Factor to 0.0"),
308 (operators.NWChangeMixFactor.bl_idname, 'NUMPAD_1', 'PRESS', True, True, True, (('option', 1.0),), "Mix Factor to 1.0"),
309 (operators.NWChangeMixFactor.bl_idname, 'ONE', 'PRESS', True, True, True, (('option', 1.0),), "Set Mix Factor to 1.0"),
310 # CLEAR LABEL (Alt L)
311 (operators.NWClearLabel.bl_idname, 'L', 'PRESS', False, False, True, (('option', False),), "Clear node labels"),
312 # MODIFY LABEL (Alt Shift L)
313 (operators.NWModifyLabels.bl_idname, 'L', 'PRESS', False, True, True, None, "Modify node labels"),
314 # Copy Label from active to selected
315 (operators.NWCopyLabel.bl_idname, 'V', 'PRESS', False, True, False,
316 (('option', 'FROM_ACTIVE'),), "Copy label from active to selected"),
317 # DETACH OUTPUTS (Alt Shift D)
318 (operators.NWDetachOutputs.bl_idname, 'D', 'PRESS', False, True, True, None, "Detach outputs"),
319 # LINK TO OUTPUT NODE (O)
320 (operators.NWLinkToOutputNode.bl_idname, 'O', 'PRESS', False, False, False, None, "Link to output node"),
321 # SELECT PARENT/CHILDREN
322 # Select Children
323 (operators.NWSelectParentChildren.bl_idname, 'RIGHT_BRACKET', 'PRESS',
324 False, False, False, (('option', 'CHILD'),), "Select children"),
325 # Select Parent
326 (operators.NWSelectParentChildren.bl_idname, 'LEFT_BRACKET', 'PRESS',
327 False, False, False, (('option', 'PARENT'),), "Select Parent"),
328 # Add Texture Setup
329 (operators.NWAddTextureSetup.bl_idname, 'T', 'PRESS', True, False, False, None, "Add texture setup"),
330 # Add Principled BSDF Texture Setup
331 (operators.NWAddPrincipledSetup.bl_idname, 'T', 'PRESS', True, True, False, None, "Add Principled texture setup"),
332 # Reset backdrop
333 (operators.NWResetBG.bl_idname, 'Z', 'PRESS', False, False, False, None, "Reset backdrop image zoom"),
334 # Delete unused
335 (operators.NWDeleteUnused.bl_idname, 'X', 'PRESS', False, False, True, None, "Delete unused nodes"),
336 # Frame Selected
337 (operators.NWFrameSelected.bl_idname, 'P', 'PRESS', False, True, False, None, "Frame selected nodes"),
338 # Swap Links
339 (operators.NWSwapLinks.bl_idname, 'S', 'PRESS', False, False, True, None, "Swap Links"),
340 # Preview Node
341 (operators.NWPreviewNode.bl_idname, 'LEFTMOUSE', 'PRESS', True, True,
342 False, (('run_in_geometry_nodes', False),), "Preview node output"),
343 (operators.NWPreviewNode.bl_idname, 'LEFTMOUSE', 'PRESS', False, True,
344 True, (('run_in_geometry_nodes', True),), "Preview node output"),
345 # Reload Images
346 (operators.NWReloadImages.bl_idname, 'R', 'PRESS', False, False, True, None, "Reload images"),
347 # Lazy Mix
348 (operators.NWLazyMix.bl_idname, 'RIGHTMOUSE', 'PRESS', True, True, False, None, "Lazy Mix"),
349 # Lazy Connect
350 (operators.NWLazyConnect.bl_idname, 'RIGHTMOUSE', 'PRESS', False, False, True, (('with_menu', False),), "Lazy Connect"),
351 # Lazy Connect with Menu
352 (operators.NWLazyConnect.bl_idname, 'RIGHTMOUSE', 'PRESS', False,
353 True, True, (('with_menu', True),), "Lazy Connect with Socket Menu"),
354 # Viewer Tile Center
355 (operators.NWViewerFocus.bl_idname, 'LEFTMOUSE', 'DOUBLE_CLICK', False, False, False, None, "Set Viewers Tile Center"),
356 # Align Nodes
357 (operators.NWAlignNodes.bl_idname, 'EQUAL', 'PRESS', False, True,
358 False, None, "Align selected nodes neatly in a row/column"),
359 # Reset Nodes (Back Space)
360 (operators.NWResetNodes.bl_idname, 'BACK_SPACE', 'PRESS', False, False,
361 False, None, "Revert node back to default state, but keep connections"),
362 # MENUS
363 ('wm.call_menu', 'W', 'PRESS', False, True, False, (('name', interface.NodeWranglerMenu.bl_idname),), "Node Wrangler menu"),
364 ('wm.call_menu', 'SLASH', 'PRESS', False, False, False,
365 (('name', interface.NWAddReroutesMenu.bl_idname),), "Add Reroutes menu"),
366 ('wm.call_menu', 'NUMPAD_SLASH', 'PRESS', False, False, False,
367 (('name', interface.NWAddReroutesMenu.bl_idname),), "Add Reroutes menu"),
368 ('wm.call_menu', 'BACK_SLASH', 'PRESS', False, False, False,
369 (('name', interface.NWLinkActiveToSelectedMenu.bl_idname),), "Link active to selected (menu)"),
370 ('wm.call_menu', 'C', 'PRESS', False, True, False,
371 (('name', interface.NWCopyToSelectedMenu.bl_idname),), "Copy to selected (menu)"),
372 ('wm.call_menu', 'S', 'PRESS', False, True, False,
373 (('name', interface.NWSwitchNodeTypeMenu.bl_idname),), "Switch node type menu"),
376 classes = (
377 NWPrincipledPreferences, NWNodeWrangler
381 def register():
382 from bpy.utils import register_class
383 for cls in classes:
384 register_class(cls)
386 # keymaps
387 addon_keymaps.clear()
388 kc = bpy.context.window_manager.keyconfigs.addon
389 if kc:
390 km = kc.keymaps.new(name='Node Editor', space_type="NODE_EDITOR")
391 for (identifier, key, action, CTRL, SHIFT, ALT, props, nicename) in kmi_defs:
392 kmi = km.keymap_items.new(identifier, key, action, ctrl=CTRL, shift=SHIFT, alt=ALT)
393 if props:
394 for prop, value in props:
395 setattr(kmi.properties, prop, value)
396 addon_keymaps.append((km, kmi))
398 # switch submenus
399 switch_category_menus.clear()
400 for cat in node_categories_iter(None):
401 if cat.name not in ['Group', 'Script']:
402 idname = f"NODE_MT_nw_switch_{cat.identifier}_submenu"
403 switch_category_type = type(idname, (bpy.types.Menu,), {
404 "bl_space_type": 'NODE_EDITOR',
405 "bl_label": cat.name,
406 "category": cat,
407 "poll": cat.poll,
408 "draw": interface.draw_switch_category_submenu,
411 switch_category_menus.append(switch_category_type)
413 bpy.utils.register_class(switch_category_type)
416 def unregister():
417 for cat_types in switch_category_menus:
418 bpy.utils.unregister_class(cat_types)
419 switch_category_menus.clear()
421 # keymaps
422 for km, kmi in addon_keymaps:
423 km.keymap_items.remove(kmi)
424 addon_keymaps.clear()
426 from bpy.utils import unregister_class
427 for cls in classes:
428 unregister_class(cls)