From 8d69c751d8a41497859131d080ed40bc02d0de93 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 18 Aug 2021 13:40:46 +0200 Subject: [PATCH 1/7] use project settings only if menu is not passed --- openpype/hosts/maya/api/menu.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/openpype/hosts/maya/api/menu.py b/openpype/hosts/maya/api/menu.py index 0dced48868..888cd78be1 100644 --- a/openpype/hosts/maya/api/menu.py +++ b/openpype/hosts/maya/api/menu.py @@ -16,12 +16,10 @@ log = logging.getLogger(__name__) def _get_menu(menu_name=None): """Return the menu instance if it currently exists in Maya""" - - project_settings = get_project_settings(os.getenv("AVALON_PROJECT")) - _menu = project_settings["maya"]["scriptsmenu"]["name"] - if menu_name is None: - menu_name = _menu + project_settings = get_project_settings(os.getenv("AVALON_PROJECT")) + menu_name = project_settings["maya"]["scriptsmenu"]["name"] + widgets = dict(( w.objectName(), w) for w in QtWidgets.QApplication.allWidgets()) menu = widgets.get(menu_name) From c34f96b9b4ed5268b31b1d283c99c8981598dcd8 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 18 Aug 2021 13:41:05 +0200 Subject: [PATCH 2/7] added back workfiles tool replacement --- openpype/hosts/maya/api/menu.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/openpype/hosts/maya/api/menu.py b/openpype/hosts/maya/api/menu.py index 888cd78be1..f95918e070 100644 --- a/openpype/hosts/maya/api/menu.py +++ b/openpype/hosts/maya/api/menu.py @@ -56,6 +56,34 @@ def deferred(): parent=pipeline._parent ) + # Find the pipeline menu + top_menu = _get_menu(pipeline._menu) + + # Try to find workfile tool action in the menu + workfile_action = None + for action in top_menu.actions(): + if action.text() == "Work Files": + workfile_action = action + break + + # Add at the top of menu if "Work Files" action was not found + after_action = "" + if workfile_action: + # Use action's object name for `insertAfter` argument + after_action = workfile_action.objectName() + + # Insert action to menu + cmds.menuItem( + "Work Files", + parent=pipeline._menu, + command=launch_workfiles_app, + insertAfter=after_action + ) + + # Remove replaced action + if workfile_action: + top_menu.removeAction(workfile_action) + log.info("Attempting to install scripts menu ...") add_build_workfiles_item() From df21d988895212ef0bc058c2db7ed2a3a08ec716 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 18 Aug 2021 13:41:18 +0200 Subject: [PATCH 3/7] remove project manager action --- openpype/hosts/maya/api/menu.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/openpype/hosts/maya/api/menu.py b/openpype/hosts/maya/api/menu.py index f95918e070..b1f6adbd5e 100644 --- a/openpype/hosts/maya/api/menu.py +++ b/openpype/hosts/maya/api/menu.py @@ -84,11 +84,36 @@ def deferred(): if workfile_action: top_menu.removeAction(workfile_action) + def remove_project_manager(): + top_menu = _get_menu(pipeline._menu) + + # Try to find workfile tool action in the menu + system_menu = None + for action in top_menu.actions(): + if action.text() == "System": + system_menu = action + break + + if system_menu is None: + return + + project_manager_action = None + for action in system_menu.menu().children(): + if hasattr(action, "text"): + print(action.text()) + if action.text() == "Project Manager": + project_manager_action = action + break + + if project_manager_action is not None: + system_menu.menu().removeAction(project_manager_action) + log.info("Attempting to install scripts menu ...") add_build_workfiles_item() add_look_assigner_item() modify_workfiles() + remove_project_manager() try: import scriptsmenu.launchformaya as launchformaya From df836474ff6f6bd3ef25cced8e4a5e7dc74ae469 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 18 Aug 2021 13:58:30 +0200 Subject: [PATCH 4/7] do not uninstall on install --- openpype/hosts/maya/api/menu.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openpype/hosts/maya/api/menu.py b/openpype/hosts/maya/api/menu.py index b1f6adbd5e..58a9c54923 100644 --- a/openpype/hosts/maya/api/menu.py +++ b/openpype/hosts/maya/api/menu.py @@ -161,7 +161,6 @@ def install(): log.info("Skipping openpype.menu initialization in batch mode..") return - uninstall() # Allow time for uninstallation to finish. cmds.evalDeferred(deferred) From 14e40a2bca80904e6d12e5d35a723a66041da973 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 18 Aug 2021 14:00:52 +0200 Subject: [PATCH 5/7] don't use settings in `_get_menu` --- openpype/hosts/maya/api/menu.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/openpype/hosts/maya/api/menu.py b/openpype/hosts/maya/api/menu.py index 58a9c54923..939c6f9c82 100644 --- a/openpype/hosts/maya/api/menu.py +++ b/openpype/hosts/maya/api/menu.py @@ -17,8 +17,7 @@ log = logging.getLogger(__name__) def _get_menu(menu_name=None): """Return the menu instance if it currently exists in Maya""" if menu_name is None: - project_settings = get_project_settings(os.getenv("AVALON_PROJECT")) - menu_name = project_settings["maya"]["scriptsmenu"]["name"] + menu_name = pipeline._menu widgets = dict(( w.objectName(), w) for w in QtWidgets.QApplication.allWidgets()) @@ -57,7 +56,7 @@ def deferred(): ) # Find the pipeline menu - top_menu = _get_menu(pipeline._menu) + top_menu = _get_menu() # Try to find workfile tool action in the menu workfile_action = None @@ -85,7 +84,7 @@ def deferred(): top_menu.removeAction(workfile_action) def remove_project_manager(): - top_menu = _get_menu(pipeline._menu) + top_menu = _get_menu() # Try to find workfile tool action in the menu system_menu = None From 0e0d06b2684c7ef9bf5d75a7cadf0eb5610ec4d0 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 18 Aug 2021 14:01:01 +0200 Subject: [PATCH 6/7] simplified conditions --- openpype/hosts/maya/api/menu.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/openpype/hosts/maya/api/menu.py b/openpype/hosts/maya/api/menu.py index 939c6f9c82..6811887e87 100644 --- a/openpype/hosts/maya/api/menu.py +++ b/openpype/hosts/maya/api/menu.py @@ -98,11 +98,9 @@ def deferred(): project_manager_action = None for action in system_menu.menu().children(): - if hasattr(action, "text"): - print(action.text()) - if action.text() == "Project Manager": - project_manager_action = action - break + if hasattr(action, "text") and action.text() == "Project Manager": + project_manager_action = action + break if project_manager_action is not None: system_menu.menu().removeAction(project_manager_action) From 126a874420959f9d1fd8787ae2756892f8b56239 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 19 Aug 2021 11:01:49 +0200 Subject: [PATCH 7/7] fixed comments in remove project action --- openpype/hosts/maya/api/menu.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/maya/api/menu.py b/openpype/hosts/maya/api/menu.py index 6811887e87..ad225dcd28 100644 --- a/openpype/hosts/maya/api/menu.py +++ b/openpype/hosts/maya/api/menu.py @@ -86,7 +86,7 @@ def deferred(): def remove_project_manager(): top_menu = _get_menu() - # Try to find workfile tool action in the menu + # Try to find "System" menu action in the menu system_menu = None for action in top_menu.actions(): if action.text() == "System": @@ -96,12 +96,14 @@ def deferred(): if system_menu is None: return + # Try to find "Project manager" action in "System" menu project_manager_action = None for action in system_menu.menu().children(): if hasattr(action, "text") and action.text() == "Project Manager": project_manager_action = action break + # Remove "Project manager" action if was found if project_manager_action is not None: system_menu.menu().removeAction(project_manager_action)