Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Hiero: Add custom scripts menu #3425

Merged
merged 18 commits into from
Jul 8, 2022
85 changes: 85 additions & 0 deletions openpype/hosts/hiero/api/launchforhiero.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import logging

from scriptsmenu import scriptsmenu
from Qt import QtWidgets


log = logging.getLogger(__name__)


def _hiero_main_window():
"""Return Hiero's main window"""
for obj in QtWidgets.QApplication.topLevelWidgets():
if (obj.inherits('QMainWindow') and
obj.metaObject().className() == 'Foundry::UI::DockMainWindow'):
return obj
raise RuntimeError('Could not find HieroWindow instance')


def _hiero_main_menubar():
"""Retrieve the main menubar of the Hiero window"""
hiero_window = _hiero_main_window()
menubar = [i for i in hiero_window.children() if isinstance(
i,
QtWidgets.QMenuBar
)]

assert len(menubar) == 1, "Error, could not find menu bar!"
return menubar[0]


def find_scripts_menu(title, parent):
"""
Check if the menu exists with the given title in the parent

Args:
title (str): the title name of the scripts menu

parent (QtWidgets.QMenuBar): the menubar to check

Returns:
QtWidgets.QMenu or None

"""

menu = None
search = [i for i in parent.children() if
isinstance(i, scriptsmenu.ScriptsMenu)
and i.title() == title]
if search:
assert len(search) < 2, ("Multiple instances of menu '{}' "
"in menu bar".format(title))
menu = search[0]

return menu


def main(title="Scripts", parent=None, objectName=None):
"""Build the main scripts menu in Hiero

Args:
title (str): name of the menu in the application

parent (QtWidgets.QtMenuBar): the parent object for the menu

objectName (str): custom objectName for scripts menu

Returns:
scriptsmenu.ScriptsMenu instance

"""
hieromainbar = parent or _hiero_main_menubar()
try:
# check menu already exists
menu = find_scripts_menu(title, hieromainbar)
if not menu:
log.info("Attempting to build menu ...")
object_name = objectName or title.lower()
menu = scriptsmenu.ScriptsMenu(title=title,
parent=hieromainbar,
objectName=object_name)
except Exception as e:
log.error(e)
return

return menu
29 changes: 29 additions & 0 deletions openpype/hosts/hiero/api/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from openpype.tools.utils import host_tools

from . import tags
from openpype.settings import get_project_settings

log = Logger.get_logger(__name__)

Expand Down Expand Up @@ -41,6 +42,7 @@ def menu_install():
Installing menu into Hiero

"""

from Qt import QtGui
from . import (
publish, launch_workfiles_app, reload_config,
Expand Down Expand Up @@ -138,3 +140,30 @@ def menu_install():
exeprimental_action.triggered.connect(
lambda: host_tools.show_experimental_tools_dialog(parent=main_window)
)


def add_scripts_menu():
try:
from . import launchforhiero
except ImportError:

log.warning(
"Skipping studio.menu install, because "
"'scriptsmenu' module seems unavailable."
)
return

# load configuration of custom menu
project_settings = get_project_settings(os.getenv("AVALON_PROJECT"))
config = project_settings["hiero"]["scriptsmenu"]["definition"]
_menu = project_settings["hiero"]["scriptsmenu"]["name"]

if not config:
log.warning("Skipping studio menu, no definition found.")
return

# run the launcher for Hiero menu
studio_menu = launchforhiero.main(title=_menu.title())

# apply configuration
studio_menu.build_from_configuration(studio_menu, config)
1 change: 1 addition & 0 deletions openpype/hosts/hiero/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def install():

# install menu
menu.menu_install()
menu.add_scripts_menu()

# register hiero events
events.register_hiero_events()
Expand Down
14 changes: 13 additions & 1 deletion openpype/settings/defaults/project_settings/hiero.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,17 @@
]
}
},
"filters": {}
"filters": {},
"scriptsmenu": {
"name": "OpenPype Tools",
"definition": [
{
"type": "action",
"sourcetype": "python",
"title": "OpenPype Docs",
"command": "import webbrowser;webbrowser.open(url='https://openpype.io/docs/artist_hosts_hiero')",
"tooltip": "Open the OpenPype Hiero user doc page"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@
{
"type": "schema",
"name": "schema_publish_gui_filter"
},
{
"type": "schema",
"name": "schema_scriptsmenu"
}
]
}
9 changes: 9 additions & 0 deletions website/docs/admin_hosts_hiero.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
id: admin_hosts_hiero
title: Hiero
sidebar_label: Hiero
---

## Custom Menu
You can add your custom tools menu into Hiero by extending definitions in **Hiero -> Scripts Menu Definition**.
![Custom menu definition](assets/hiero-admin_scriptsmenu.png)
Binary file added website/docs/assets/hiero-admin_scriptsmenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module.exports = {
label: "Integrations",
items: [
"admin_hosts_blender",
"admin_hosts_hiero",
"admin_hosts_maya",
"admin_hosts_nuke",
"admin_hosts_resolve",
Expand Down