Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append existing menu in unreal #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions dev/unimenu_samples/menu_config_unreal_append_existing_menu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
parent_path: ContentBrowser.FolderContextMenu


label: ContentBrowser.FolderContextMenu
items:
- label: Example
separator: True

- label: SyncToAssetByPath
command: print("SyncToAssetByPath")
kwargs:
section_name: Example_section

- label: CheckAssets
command: print("CheckAssets")
kwargs:
section_name: Example_section
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 12 additions & 3 deletions unimenu/apps/_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,13 @@ def setup(self, parent_app_node=None, backlink=True):
self.app_node = self._setup_menu_item(parent_app_node=parent_app_node)

elif self.items: # submenu
self.app_node = self._setup_sub_menu(parent_app_node=parent_app_node)
for item in self.items:
item.setup(parent_app_node=self.app_node)
if self.label == self._get_parent_app_node_name(parent_app_node=parent_app_node):
for item in self.items:
item.setup(parent_app_node=parent_app_node)
else:
self.app_node = self._setup_sub_menu(parent_app_node=parent_app_node)
for item in self.items:
item.setup(parent_app_node=self.app_node)
else:
logging.warning("Can not create a MenuNode that has no command or children: " + self.label)

Expand All @@ -250,6 +254,11 @@ def setup(self, parent_app_node=None, backlink=True):
def _default_root_parent(self):
"""get the default parent for the root node, optional method"""
return None

@abstractmethod
def _get_parent_app_node_name(self, parent_app_node=None):
"""get the default parent name for the root node, optional method"""
pass

@abstractmethod
def _setup_sub_menu(self, parent_app_node=None):
Expand Down
5 changes: 4 additions & 1 deletion unimenu/apps/unreal.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def setup(self, parent_app_node: unreal.ToolMenu = None, backlink=True) -> unrea
unreal_menus.refresh_all_widgets()

return app_node

def _get_parent_app_node_name(self, parent_app_node: unreal.ToolMenu = None) -> str:
return unreal.StringLibrary.conv_name_to_string(parent_app_node.menu_name) if parent_app_node else ""

def _setup_sub_menu(self, parent_app_node: unreal.ToolMenu = None) -> unreal.ToolMenu:
"""
Expand Down Expand Up @@ -91,7 +94,7 @@ def _setup_separator(self, parent_app_node: unreal.ToolMenu = None) -> None:

# see https://docs.unrealengine.com/4.27/en-US/PythonAPI/class/ToolMenu.html
# todo what is diff with dynamic section?
return parent_app_node.add_section(section_name=self.label + "_section", label=self.label + "_label", **self.kwargs)
return parent_app_node.add_section(section_name=self.label + "_section", label=self.label, **self.kwargs)

def teardown(self):
"""remove from menu"""
Expand Down