[Bf-blender-cvs] [9bcf1bb] master: Fix for nodeitems module using the NODE_MT_add menu types from bl_ui.

Lukas Tönne noreply at git.blender.org
Fri Jul 17 12:00:02 CEST 2015


Commit: 9bcf1bb266e09f92a50033d1c9c4c42bd69290e3
Author: Lukas Tönne
Date:   Fri Jul 17 11:45:02 2015 +0200
Branches: master
https://developer.blender.org/rB9bcf1bb266e09f92a50033d1c9c4c42bd69290e3

Fix for nodeitems module using the NODE_MT_add menu types from bl_ui.

This is basically a bad-level call: ui scripts are registered *after*
the modules. It only works for addons because those are loaded even
later.

Now the nodeitems_utils module just defines a function which is then
called by the UI script, rather than the other way around.

===================================================================

M	release/scripts/modules/nodeitems_utils.py
M	release/scripts/startup/bl_ui/space_node.py

===================================================================

diff --git a/release/scripts/modules/nodeitems_utils.py b/release/scripts/modules/nodeitems_utils.py
index 2f69ea8..1cc9afc 100644
--- a/release/scripts/modules/nodeitems_utils.py
+++ b/release/scripts/modules/nodeitems_utils.py
@@ -85,7 +85,6 @@ class NodeItemCustom:
 
 _node_categories = {}
 
-
 def register_node_categories(identifier, cat_list):
     if identifier in _node_categories:
         raise KeyError("Node categories list '%s' already registered" % identifier)
@@ -131,8 +130,6 @@ def register_node_categories(identifier, cat_list):
             if cat.poll(context):
                 layout.menu("NODE_MT_category_%s" % cat.identifier)
 
-    bpy.types.NODE_MT_add.append(draw_add_menu)
-
     # stores: (categories list, menu draw function, submenu types, panel types)
     _node_categories[identifier] = (cat_list, draw_add_menu, menu_types, panel_types)
 
@@ -151,7 +148,6 @@ def node_items_iter(context):
 
 
 def unregister_node_cat_types(cats):
-    bpy.types.NODE_MT_add.remove(cats[1])
     for mt in cats[2]:
         bpy.utils.unregister_class(mt)
     for pt in cats[3]:
@@ -170,3 +166,7 @@ def unregister_node_categories(identifier=None):
         for cat_types in _node_categories.values():
             unregister_node_cat_types(cat_types)
         _node_categories.clear()
+
+def draw_node_categories_menu(self, context):
+    for cats in _node_categories.values():
+        cats[1](self, context)
diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py
index d0d1376..4fc93fa 100644
--- a/release/scripts/startup/bl_ui/space_node.py
+++ b/release/scripts/startup/bl_ui/space_node.py
@@ -18,6 +18,7 @@
 
 # <pep8 compliant>
 import bpy
+import nodeitems_utils
 from bpy.types import Header, Menu, Panel
 from bpy.app.translations import pgettext_iface as iface_
 from bl_ui.properties_grease_pencil_common import (
@@ -154,7 +155,8 @@ class NODE_MT_add(bpy.types.Menu):
         props = layout.operator("node.add_search", text="Search ...")
         props.use_transform = True
 
-        # actual node submenus are added by draw functions from node categories
+        # actual node submenus are defined by draw functions from node categories
+        nodeitems_utils.draw_node_categories_menu(self, context)
 
 
 class NODE_MT_view(Menu):




More information about the Bf-blender-cvs mailing list