From b77cb4ba1a367e5974342e670241d19137fb2a3e Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Mon, 6 Jun 2022 19:17:34 +0200 Subject: [PATCH] Add global menu from settings --- openpype/hosts/nuke/api/gizmo_menu.py | 52 +++---- openpype/hosts/nuke/api/lib.py | 1 - .../defaults/project_settings/nuke.json | 13 +- .../schemas/schema_nuke_scriptsgizmo.json | 133 +++++++++--------- 4 files changed, 106 insertions(+), 93 deletions(-) diff --git a/openpype/hosts/nuke/api/gizmo_menu.py b/openpype/hosts/nuke/api/gizmo_menu.py index 7f8121372c..42b5812360 100644 --- a/openpype/hosts/nuke/api/gizmo_menu.py +++ b/openpype/hosts/nuke/api/gizmo_menu.py @@ -38,38 +38,42 @@ class GizmoMenu(): return parent def build_from_configuration(self, configuration): - for item in configuration: - assert isinstance(item, dict), "Configuration is wrong!" - + for menu in configuration: # Construct parent path else parent is toolbar parent = self.toolbar - gizmo_toolbar_path = item.get("gizmo_toolbar_path") + gizmo_toolbar_path = menu.get("gizmo_toolbar_path") if gizmo_toolbar_path: parent = self._make_menu_path(gizmo_toolbar_path) - item_type = item.get("sourcetype") + for item in menu["sub_gizmo_list"]: + assert isinstance(item, dict), "Configuration is wrong!" - if item_type == ("python" or "file"): - parent.addCommand( - item['title'], - command=str(item["command"]), - icon=item.get("icon"), - shortcut=item.get('hotkey') - ) + if not item.get("title"): + continue - # add separator - # Special behavior for separators - elif item_type == "separator": - parent.addSeparator() + item_type = item.get("sourcetype") - # add submenu - # items should hold a collection of submenu items (dict) - elif item_type == "menu": - # assert "items" in item, "Menu is missing 'items' key" - parent.addMenu( - item['title'], - icon=item.get('icon') - ) + if item_type == ("python" or "file"): + parent.addCommand( + item["title"], + command=str(item["command"]), + icon=item.get("icon"), + shortcut=item.get("hotkey") + ) + + # add separator + # Special behavior for separators + elif item_type == "separator": + parent.addSeparator() + + # add submenu + # items should hold a collection of submenu items (dict) + elif item_type == "menu": + # assert "items" in item, "Menu is missing 'items' key" + parent.addMenu( + item['title'], + icon=item.get('icon') + ) def add_gizmo_path(self, gizmo_paths): for gizmo_path in gizmo_paths: diff --git a/openpype/hosts/nuke/api/lib.py b/openpype/hosts/nuke/api/lib.py index 335e7190a0..0d766c8459 100644 --- a/openpype/hosts/nuke/api/lib.py +++ b/openpype/hosts/nuke/api/lib.py @@ -2516,7 +2516,6 @@ def add_scripts_gizmo(): for gizmo_settings in project_settings["nuke"]["gizmo"]: gizmo_list_definition = gizmo_settings["gizmo_definition"] - print(1, gizmo_list_definition) toolbar_name = gizmo_settings["toolbar_menu_name"] # gizmo_toolbar_path = gizmo_settings["gizmo_toolbar_path"] gizmo_source_dir = gizmo_settings.get( diff --git a/openpype/settings/defaults/project_settings/nuke.json b/openpype/settings/defaults/project_settings/nuke.json index 63978ad1be..c609a0927a 100644 --- a/openpype/settings/defaults/project_settings/nuke.json +++ b/openpype/settings/defaults/project_settings/nuke.json @@ -301,10 +301,15 @@ "toolbar_icon_path": {}, "gizmo_definition": [ { - "type": "action", - "sourcetype": "python", - "title": "Gizmo Note", - "command": "nuke.nodes.StickyNote(label='You can create your own toolbar menu in the Nuke GizmoMenu of OpenPype')" + "gizmo_toolbar_path": "/path/to/menu", + "sub_gizmo_list": [ + { + "sourcetype": "python", + "title": "Gizmo Note", + "command": "nuke.nodes.StickyNote(label='You can create your own toolbar menu in the Nuke GizmoMenu of OpenPype')", + "shortcut": "" + } + ] } ] } diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_nuke_scriptsgizmo.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_nuke_scriptsgizmo.json index 80fda56175..abe14970c5 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_nuke_scriptsgizmo.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_nuke_scriptsgizmo.json @@ -41,73 +41,78 @@ "label": "Gizmo definitions", "use_label_wrap": true, "object_type": { - "type": "dict-conditional", - "enum_key": "sourcetype", - "enum_label": "Type of usage", - "enum_children": [ + "type": "dict", + "children": [ { - "key": "python", - "label": "Python", - "children": [ - { - "type": "text", - "key": "title", - "label": "Title" - }, - { - "type": "text", - "key": "gizmo_toolbar_path", - "label": "Toolbar path" - }, - { - "type": "text", - "key": "command", - "label": "Python command" - }, - { - "type": "text", - "key": "shortcut", - "label": "Hotkey" - } - ] + "type": "text", + "key": "gizmo_toolbar_path", + "label": "Gizmo Menu Path" }, { - "key": "file", - "label": "File", - "children": [ - { - "type": "text", - "key": "title", - "label": "Title" - }, - { - "type": "text", - "key": "gizmo_toolbar_path", - "label": "Toolbar path" - }, - { - "type": "text", - "key": "file_name", - "label": "Gizmo file name" - }, - { - "type": "text", - "key": "shortcut", - "label": "Hotkey" - } - - ] - }, - { - "key": "separator", - "label": "Separator", - "children": [ - { - "type": "text", - "key": "gizmo_toolbar_path", - "label": "Toolbar path" - } - ] + "type": "list", + "key": "sub_gizmo_list", + "label": "Sub Gizmo List", + "use_label_wrap": true, + "object_type": { + "type": "dict-conditional", + "enum_key": "sourcetype", + "enum_label": "Type of usage", + "enum_children": [ + { + "key": "python", + "label": "Python", + "children": [ + { + "type": "text", + "key": "title", + "label": "Title" + }, + { + "type": "text", + "key": "command", + "label": "Python command" + }, + { + "type": "text", + "key": "shortcut", + "label": "Hotkey" + } + ] + }, + { + "key": "file", + "label": "File", + "children": [ + { + "type": "text", + "key": "title", + "label": "Title" + }, + { + "type": "text", + "key": "file_name", + "label": "Gizmo file name" + }, + { + "type": "text", + "key": "shortcut", + "label": "Hotkey" + } + ] + }, + { + "key": "separator", + "label": "Separator", + "children": [ + { + "type": "text", + "key": "gizmo_toolbar_path", + "label": "Toolbar path" + } + ] + } + ] + } } ] }