Skip to content

Commit

Permalink
Merge pull request #14 from ynput/enhancement/shortcut_to_open_template
Browse files Browse the repository at this point in the history
Add shortcut to open template for current context
  • Loading branch information
iLLiCiTiT authored Feb 13, 2024
2 parents f43922b + 1b3ac1f commit 21a10c5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 12 deletions.
34 changes: 24 additions & 10 deletions client/ayon_core/hosts/maya/api/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from ayon_core.pipeline import (
get_current_asset_name,
get_current_task_name
get_current_task_name,
registered_host
)
from ayon_core.pipeline.workfile import BuildWorkfile
from ayon_core.tools.utils import host_tools
Expand All @@ -21,8 +22,10 @@
create_placeholder,
update_placeholder,
build_workfile_template,
update_workfile_template,
update_workfile_template
)
from ayon_core.tools.workfile_template_build import open_template_ui
from .workfile_template_builder import MayaTemplateBuilder

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -168,24 +171,35 @@ def add_menu():
parent=MENU_NAME
)
cmds.menuItem(
"Create Placeholder",
"Build Workfile from template",
parent=builder_menu,
command=create_placeholder
command=build_workfile_template
)
cmds.menuItem(
"Update Placeholder",
"Update Workfile from template",
parent=builder_menu,
command=update_placeholder
command=update_workfile_template
)
cmds.menuItem(
"Build Workfile from template",
divider=True,
parent=builder_menu
)
cmds.menuItem(
"Open Template",
parent=builder_menu,
command=build_workfile_template
command=lambda *args: open_template_ui(
MayaTemplateBuilder(registered_host()), get_main_window()
),
)
cmds.menuItem(
"Update Workfile from template",
"Create Placeholder",
parent=builder_menu,
command=update_workfile_template
command=create_placeholder
)
cmds.menuItem(
"Update Placeholder",
parent=builder_menu,
command=update_placeholder
)

cmds.setParent(MENU_NAME, menu=True)
Expand Down
11 changes: 10 additions & 1 deletion client/ayon_core/hosts/nuke/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
AVALON_CONTAINER_ID,
get_current_asset_name,
get_current_task_name,
registered_host,
)
from ayon_core.pipeline.workfile import BuildWorkfile
from ayon_core.tools.utils import host_tools
from ayon_core.hosts.nuke import NUKE_ROOT_DIR
from ayon_core.tools.workfile_template_build import open_template_ui

from .command import viewer_update_and_undo_stop
from .lib import (
Expand Down Expand Up @@ -55,6 +57,7 @@
build_workfile_template,
create_placeholder,
update_placeholder,
NukeTemplateBuilder,
)
from .workio import (
open_file,
Expand Down Expand Up @@ -313,14 +316,20 @@ def _install_menu():
lambda: BuildWorkfile().process()
)

menu_template = menu.addMenu("Template Builder") # creating template menu
menu_template = menu.addMenu("Template Builder")
menu_template.addCommand(
"Build Workfile from template",
lambda: build_workfile_template()
)

if not ASSIST:
menu_template.addSeparator()
menu_template.addCommand(
"Open template",
lambda: open_template_ui(
NukeTemplateBuilder(registered_host()), get_main_window()
)
)
menu_template.addCommand(
"Create Place Holder",
lambda: create_placeholder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
LoadPlaceholderItem,
CreatePlaceholderItem,
PlaceholderLoadMixin,
PlaceholderCreateMixin
PlaceholderCreateMixin,
)
from ayon_core.tools.workfile_template_build import (
WorkfileBuildPlaceholderDialog,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,12 @@ def rebuild_template(self):

self.clear_shared_populate_data()

def open_template(self):
"""Open template file with registered host."""
template_preset = self.get_template_preset()
template_path = template_preset["path"]
self.host.open_file(template_path)

@abstractmethod
def import_template(self, template_path):
"""
Expand Down
3 changes: 3 additions & 0 deletions client/ayon_core/tools/workfile_template_build/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from .window import WorkfileBuildPlaceholderDialog
from .lib import open_template_ui

__all__ = (
"WorkfileBuildPlaceholderDialog",

"open_template_ui"
)
28 changes: 28 additions & 0 deletions client/ayon_core/tools/workfile_template_build/lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import traceback

from qtpy import QtWidgets

from ayon_core.tools.utils.dialogs import show_message_dialog


def open_template_ui(builder, main_window):
"""Open template from `builder`
Asks user about overwriting current scene and feedsback exceptions.
"""
result = QtWidgets.QMessageBox.question(
main_window,
"Opening template",
"Caution! You will loose unsaved changes.\nDo you want to continue?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No
)
if result == QtWidgets.QMessageBox.Yes:
try:
builder.open_template()
except Exception:
show_message_dialog(
title="Template Load Failed",
message="".join(traceback.format_exc()),
parent=main_window,
level="critical"
)

0 comments on commit 21a10c5

Please sign in to comment.