Skip to content

Commit

Permalink
add panel fixes #4703 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
Durman committed Oct 24, 2022
1 parent 8ed55ee commit a74063a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 25 deletions.
41 changes: 20 additions & 21 deletions ui/add_nodes_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def select_category_update(self, context):
cat_name = context.scene.sv_add_node_panel_settings.selected_category
for cat in sm.add_node_menu.walk_categories():
if cat.menu_cls.__name__ == cat_name:
items = [n for n in cat if isinstance(n, sm.AddNode)]
items = [n for n in cat if isinstance(n, (sm.AddNode, sm.Separator))]
AddNodeToolPanel._items = items
return

Expand Down Expand Up @@ -87,28 +87,10 @@ def draw(self, context):
for cat, add_nodes in self.categories.items():
icon_prop = sm.icon(cat.icon) if cat.icon else {}
layout.label(text=cat.name, **icon_prop)
if context.scene.sv_add_node_panel_settings.icons_only:
num = context.scene.sv_add_node_panel_settings.columns_number
grid = layout.grid_flow(row_major=True, align=True, columns=num)
grid.scale_x = 1.5
for add_node in add_nodes:
add_node.draw(grid, only_icon=True)
else:
col = layout.column(align=True)
for add_node in add_nodes:
add_node.draw(col)
self.draw_add_node(context, add_nodes)
else:
layout.prop(context.scene.sv_add_node_panel_settings, "selected_category", text="")
if context.scene.sv_add_node_panel_settings.icons_only:
num = context.scene.sv_add_node_panel_settings.columns_number
grid = layout.grid_flow(row_major=True, align=True, columns=num)
grid.scale_x = 1.5
for add_node in self.items:
add_node.draw(grid, only_icon=True)
else:
col = layout.column(align=True)
for add_node in self.items:
add_node.draw(col)
self.draw_add_node(context, self.items)

col = layout.column()
col.use_property_split = True
Expand All @@ -117,6 +99,23 @@ def draw(self, context):
if context.scene.sv_add_node_panel_settings.icons_only:
col.prop(context.scene.sv_add_node_panel_settings, 'columns_number')

def draw_add_node(self, context, items):
layout = self.layout
if context.scene.sv_add_node_panel_settings.icons_only:
num = context.scene.sv_add_node_panel_settings.columns_number
grid = layout.grid_flow(row_major=True, align=True, columns=num)
grid.scale_x = 1.5
for add_node in items:
if hasattr(add_node, 'draw_icon'):
add_node.draw_icon(grid)
else: # <- separator
grid = layout.grid_flow(row_major=True, align=True, columns=num)
grid.scale_x = 1.5
else:
col = layout.column(align=True)
for add_node in items:
add_node.draw(col)


class AddNodePanelSettings(bpy.types.PropertyGroup):
def search_tooltip(self, context, edit_text):
Expand Down
29 changes: 25 additions & 4 deletions ui/nodeview_space_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,25 @@ def draw(self, layout, only_icon=False):
add.use_transform = True
add.dependency = self.dependency

def draw_icon(self, layout):
node_cls = bpy.types.Node.bl_rna_get_subclass_py(self.bl_idname)
icon_prop = self.icon_prop or {'icon': 'OUTLINER_OB_EMPTY'}

if not self.dependency and node_cls is None:
layout.label(text=self.label, **icon_prop)
return

op = ShowMissingDependsOperator if self.dependency else SvNodeAddOperator
default_context = bpy.app.translations.contexts.default
add = layout.operator(op.bl_idname,
text='',
text_ctxt=default_context,
**icon_prop)
add.type = self.bl_idname
add.use_transform = True
add.dependency = self.dependency
add.extra_description = f'Add {self.label} node'

def search_match(self, request: str) -> bool:
"""Return True if the request satisfies to node search tags"""
request = request.upper()
Expand Down Expand Up @@ -447,6 +466,7 @@ class AddNodeOp(bl_operators.node.NodeAddOperator):
dependency: StringProperty()

_node_classes = dict()
extra_description: StringProperty()

@classmethod
def node_classes(cls) -> dict[str, type]:
Expand All @@ -459,22 +479,23 @@ def node_classes(cls) -> dict[str, type]:
@classmethod
def description(cls, _context, properties):
node_type = properties["type"]
tooltip = ''
extra = properties.get("extra_description", "")
tooltip = extra + ("\n" if extra else "")
if node_type in dummy_nodes_dict:
if node_cls := cls.node_classes().get(node_type):
tooltip = node_cls.docstring.get_tooltip()
gap = "\n\n" if tooltip else ''
tooltip = tooltip + f"{gap}Dependency: {properties.dependency}"
else:
if node_cls := bpy.types.Node.bl_rna_get_subclass_py(node_type):
tooltip = node_cls.docstring.get_tooltip()
tooltip += node_cls.docstring.get_tooltip()
return tooltip


class SvNodeAddOperator(AddNodeOp, bpy.types.Operator):
"""Operator to show as menu item to add available node"""
bl_idname = "node.sv_add_node"
bl_label = "Add SV node"
bl_label = ""
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}

def execute(self, context):
Expand All @@ -488,7 +509,7 @@ def execute(self, context):
class ShowMissingDependsOperator(AddNodeOp, bpy.types.Operator):
"""Operator as menu item to show that a node is not available"""
bl_idname = 'node.show_missing_dependencies'
bl_label = 'Show missing dependencies'
bl_label = 'Missing dependencies'
bl_options = {'REGISTER', 'UNDO'}

@classmethod
Expand Down

0 comments on commit a74063a

Please sign in to comment.