Skip to content

Commit

Permalink
Add menu fix (#3959)
Browse files Browse the repository at this point in the history
* add menu fix

* Almost perfect

* seems done

* Deleting Monkey Patch

* remove unnecesary import

* cleaning

* cleaning 2
  • Loading branch information
vicdoval authored Mar 7, 2021
1 parent 8a08f15 commit 49bf489
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 82 deletions.
4 changes: 2 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
from sverchok.core import reload_event, handle_reload_event
from sverchok.utils import utils_modules
from sverchok.ui import ui_modules
from sverchok.ui.nodeview_add_menu import perform_menu_monkey_patch

from sverchok.utils.profile import profiling_startup

imported_modules = init_architecture(__name__, utils_modules, ui_modules)
Expand All @@ -92,7 +92,7 @@ def register():
if reload_event:
data_structure.RELOAD_EVENT = True
menu.reload_menu()
# perform_menu_monkey_patch() <-- this hijacks other custom node trees


def unregister():
sverchok.utils.clear_node_classes()
Expand Down
15 changes: 5 additions & 10 deletions menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def make_categories():
items=node_items))
node_count += len(nodes)
node_categories.append(SverchNodeCategory("SVERCHOK_MONAD", "Monad", items=sv_group_items))

SverchNodeItem.new('SvMonadInfoNode')
return node_categories, node_count, original_categories

def register_node_panels(identifier, std_menu):
Expand Down Expand Up @@ -593,11 +593,10 @@ def unregister_node_panels():

def reload_menu():
menu, node_count, original_categories = make_categories()
if 'SVERCHOK' in nodeitems_utils._node_categories:
if hasattr(bpy.types, "SV_PT_NodesTPanel"):
unregister_node_panels()
nodeitems_utils.unregister_node_categories("SVERCHOK")
unregister_node_add_operators()
nodeitems_utils.register_node_categories("SVERCHOK", menu)

register_node_panels("SVERCHOK", menu)
register_node_add_operators()

Expand Down Expand Up @@ -632,10 +631,8 @@ def register():
global logger
logger = getLogger("menu")
menu, node_count, original_categories = make_categories()
if 'SVERCHOK' in nodeitems_utils._node_categories:
if hasattr(bpy.types, "SV_PT_NodesTPanel"):
unregister_node_panels()
nodeitems_utils.unregister_node_categories("SVERCHOK")
nodeitems_utils.register_node_categories("SVERCHOK", menu)

categories = [(category.identifier, category.name, category.name, i) for i, category in enumerate(menu)]
bpy.types.Scene.sv_selected_category = bpy.props.EnumProperty(
Expand All @@ -656,9 +653,7 @@ def register():
print(f"sv: {node_count} nodes.")

def unregister():
if 'SVERCHOK' in nodeitems_utils._node_categories:
unregister_node_panels()
nodeitems_utils.unregister_node_categories("SVERCHOK")
unregister_node_panels()
unregister_node_add_operators()
bpy.utils.unregister_class(SvResetNodeSearchOperator)
del bpy.types.Scene.sv_selected_category
Expand Down
63 changes: 0 additions & 63 deletions ui/nodeview_add_menu.py

This file was deleted.

79 changes: 72 additions & 7 deletions ui/nodeview_space_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@

import bpy

from sverchok.menu import make_node_cats, draw_add_node_operator, is_submenu_call, get_submenu_call_name, compose_submenu_name
from sverchok.menu import (
make_node_cats,
draw_add_node_operator,
is_submenu_call,
get_submenu_call_name,
compose_submenu_name,
draw_node_ops as monad_node_ops)

from sverchok.utils import get_node_class_reference
from sverchok.utils.extra_categories import get_extra_categories
from sverchok.ui.sv_icons import node_icon, icon, get_icon_switch, custom_icon
from sverchok.ui import presets
import nodeitems_utils
# from nodeitems_utils import _node_categories

sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'}
Expand Down Expand Up @@ -75,7 +83,7 @@ def category_has_nodes(cat_name):
["NODEVIEW_MT_AddScene", 'SCENE_DATA'],
["NODEVIEW_MT_AddExchange", 'SCENE_DATA'],
["NODEVIEW_MT_AddLayout", 'NODETREE'],
["NODE_MT_category_SVERCHOK_BPY_Data", "BLENDER"],
["NODEVIEW_MT_AddBPYData", "BLENDER"],
["separator"],
["NODEVIEW_MT_AddScript", "WORDWRAP_ON"],
["NODEVIEW_MT_AddNetwork", "SYSTEM"],
Expand Down Expand Up @@ -163,8 +171,8 @@ def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'

if self.bl_idname == 'NODEVIEW_MT_Dynamic_Menu':
layout.operator("node.sv_extra_search", text="Search", icon='OUTLINER_DATA_FONT')
# if self.bl_idname == 'NODEVIEW_MT_Dynamic_Menu':
layout.operator("node.sv_extra_search", text="Search", icon='OUTLINER_DATA_FONT')

for item in menu_structure:
if item[0] == 'separator':
Expand Down Expand Up @@ -211,6 +219,14 @@ def draw(self, context):
layout_draw_categories(self.layout, self.bl_label, node_cats[self.bl_label])
layout.menu("NODEVIEW_MT_AddGeneratorsExt", **icon('PLUGIN'))

class NODEVIEW_MT_AddBPYData(bpy.types.Menu):
bl_label = "BPY Data"

def draw(self, context):
layout = self.layout
layout_draw_categories(self.layout, self.bl_label, node_cats['BPY Data'])
layout_draw_categories(self.layout, self.bl_label, node_cats['Objects'])

class NODEVIEW_MT_AddModifiers(bpy.types.Menu):
bl_label = "Modifiers"

Expand Down Expand Up @@ -276,6 +292,41 @@ def draw(self, context):
layout.operator('node.add_node_output_input', text="Group output").node_type = 'output'
layout.operator('node.add_group_tree_from_selected')

class NODE_MT_category_SVERCHOK_MONAD(bpy.types.Menu):
bl_label = "Monad"
label = 'Monad'

def draw(self, context):

if context is None:
return
space = context.space_data
if not space:
return
ntree = space.edit_tree
if not ntree:
return
layout = self.layout

monad_node_ops(self, layout, context)

if ntree.bl_idname == "SverchGroupTreeType":
draw_add_node_operator(layout, "SvMonadInfoNode")
layout.separator()

for monad in context.blend_data.node_groups:
if monad.bl_idname != "SverchGroupTreeType":
continue
if monad.name == ntree.name:
continue
# make sure class exists
cls_ref = get_node_class_reference(monad.cls_bl_idname)

if cls_ref and monad.cls_bl_idname and monad.cls_bl_idname:
op = layout.operator('node.add_node', text=monad.name)
op.type = monad.cls_bl_idname
op.use_transform = True


extra_category_menu_classes = dict()

Expand Down Expand Up @@ -308,8 +359,10 @@ def draw(self, context):
NODEVIEW_MT_AddListOps,
NODEVIEW_MT_AddModifiers,
NODEVIEW_MT_AddGenerators,
NODEVIEW_MT_AddBPYData,
NODEVIEW_MT_AddPresetOps,
NODE_MT_category_SVERCHOK_GROUP,
NODE_MT_category_SVERCHOK_MONAD,
# like magic.
# make | NODEVIEW_MT_Add + class name , menu name
make_class('GeneratorsExt', "Generators Extended"),
Expand Down Expand Up @@ -351,15 +404,27 @@ def draw(self, context):
make_class('Alphas', "Alpha Nodes"),
# NODEVIEW_MT_Solids_Special_Menu
]
def sv_draw_menu(self, context):

tree_type = context.space_data.tree_type
if not tree_type in sv_tree_types:
return
layout = self.layout
layout.operator_context = "INVOKE_DEFAULT"

if not any([(g.bl_idname in sv_tree_types) for g in bpy.data.node_groups]):
layout.operator("node.new_node_tree", text="New Sverchok Node Tree", icon="RNA_ADD")
return

NODEVIEW_MT_Dynamic_Menu.draw(self, context)

def register():
#global menu_class_by_title
#menu_class_by_title = dict()

for category in presets.get_category_names():
make_preset_category_menu(category)
for class_name in classes:
bpy.utils.register_class(class_name)
bpy.types.NODE_MT_add.append(sv_draw_menu)

def unregister():
global menu_class_by_title
Expand All @@ -369,5 +434,5 @@ def unregister():
for category in presets.get_category_names():
if category in preset_category_menus:
bpy.utils.unregister_class(preset_category_menus[category])

bpy.types.NODE_MT_add.remove(sv_draw_menu)
menu_class_by_title = dict()

1 comment on commit 49bf489

@zeffii
Copy link
Collaborator

@zeffii zeffii commented on 49bf489 Mar 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice : )

Please sign in to comment.