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

Add shortcut to open template for current context #6181

Closed
wants to merge 18 commits into from
Closed
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
34 changes: 24 additions & 10 deletions openpype/hosts/maya/api/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from openpype.pipeline import (
get_current_asset_name,
get_current_task_name
get_current_task_name,
registered_host
)
from openpype.pipeline.workfile import BuildWorkfile
from openpype.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 openpype.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
2 changes: 1 addition & 1 deletion openpype/hosts/maya/api/workfile_template_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
PlaceholderLoadMixin,
)
from openpype.tools.workfile_template_build import (
WorkfileBuildPlaceholderDialog,
WorkfileBuildPlaceholderDialog
)

from .lib import read, imprint, get_reference_node, get_main_window
Expand Down
11 changes: 10 additions & 1 deletion openpype/hosts/nuke/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
AVALON_CONTAINER_ID,
get_current_asset_name,
get_current_task_name,
registered_host,
)
from openpype.pipeline.workfile import BuildWorkfile
from openpype.tools.utils import host_tools
from openpype.tools.workfile_template_build import open_template_ui

from .command import viewer_update_and_undo_stop
from .lib import (
Expand Down Expand Up @@ -54,6 +56,7 @@
build_workfile_template,
create_placeholder,
update_placeholder,
NukeTemplateBuilder,
)
from .workio import (
open_file,
Expand Down Expand Up @@ -315,14 +318,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
4 changes: 2 additions & 2 deletions openpype/hosts/nuke/api/workfile_template_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
LoadPlaceholderItem,
CreatePlaceholderItem,
PlaceholderLoadMixin,
PlaceholderCreateMixin
PlaceholderCreateMixin,
)
from openpype.tools.workfile_template_build import (
WorkfileBuildPlaceholderDialog,
WorkfileBuildPlaceholderDialog
)
from .lib import (
find_free_space_to_paste_nodes,
Expand Down
6 changes: 6 additions & 0 deletions openpype/pipeline/workfile/workfile_template_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,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 openpype/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"
)
29 changes: 29 additions & 0 deletions openpype/tools/workfile_template_build/lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import traceback

from openpype.widgets import message_window


def open_template_ui(builder, main_window):
"""Open template from `builder`

Asks user about overwriting current scene and feedsback exceptions.
"""

result = message_window.message(
title="Opening template",
message="Caution! You will loose unsaved changes.\n"
"Do you want to continue?",
parent=main_window,
level="question",
)

if result:
try:
builder.open_template()
except Exception:
message_window.message(
title="Template Load Failed",
message="".join(traceback.format_exc()),
parent=main_window,
level="critical"
)
25 changes: 20 additions & 5 deletions openpype/widgets/message_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ def __init__(self, parent, title, message, level):
self.message = message
self.level = level

self.setWindowTitle(self.title)

if self.level == "info":
self._info()
elif self.level == "warning":
self._warning()
elif self.level == "critical":
self._critical()
elif self.level == "question":
self._question()

def _info(self):
self.setWindowTitle(self.title)
Expand All @@ -28,23 +32,32 @@ def _info(self):
self.exit()

def _warning(self):
self.setWindowTitle(self.title)
rc = QtWidgets.QMessageBox.warning(
self, self.title, self.message)
if rc:
self.exit()

def _critical(self):
self.setWindowTitle(self.title)
rc = QtWidgets.QMessageBox.critical(
self, self.title, self.message)
if rc:
self.exit()

def _question(self):
self.answer = None
rc = QtWidgets.QMessageBox.question(
self,
self.title,
self.message,
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No
)
self.answer = False
if rc == QtWidgets.QMessageBox.Yes:
self.answer = True
self.exit()

def exit(self):
self.hide()
# self.parent.exec_()
# self.parent.hide()
return


Expand Down Expand Up @@ -78,7 +91,9 @@ def message(title=None, message=None, level="info", parent=None):
except Exception:
# skip all possible issues that may happen feature is not crutial
log.warning("Couldn't center message.", exc_info=True)
# sys.exit(app.exec_())

if level == "question":
return ex.answer


class ScrollMessageBox(QtWidgets.QDialog):
Expand Down
Loading