Merge pull request #261 from BigRoy/enhancement/maya_prompt_save_task_change

Maya: Prompt reset scene context on saving to another task
This commit is contained in:
Toke Jepsen 2024-03-29 08:26:15 +00:00 committed by GitHub
commit ecc9ad4b41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 109 additions and 11 deletions

View file

@ -2651,31 +2651,114 @@ def reset_scene_resolution():
set_scene_resolution(width, height, pixelAspect)
def set_context_settings():
def set_context_settings(
fps=True,
resolution=True,
frame_range=True,
colorspace=True
):
"""Apply the project settings from the project definition
Settings can be overwritten by an folder if the folder.attrib contains
Settings can be overwritten by an asset if the asset.data contains
any information regarding those settings.
Examples of settings:
fps
resolution
renderer
Args:
fps (bool): Whether to set the scene FPS.
resolution (bool): Whether to set the render resolution.
frame_range (bool): Whether to reset the time slide frame ranges.
colorspace (bool): Whether to reset the colorspace.
Returns:
None
"""
# Set project fps
set_scene_fps(get_fps_for_current_context())
if fps:
# Set project fps
set_scene_fps(get_fps_for_current_context())
reset_scene_resolution()
if resolution:
reset_scene_resolution()
# Set frame range.
reset_frame_range()
if frame_range:
reset_frame_range(fps=False)
# Set colorspace
set_colorspace()
if colorspace:
set_colorspace()
def prompt_reset_context():
"""Prompt the user what context settings to reset.
This prompt is used on saving to a different task to allow the scene to
get matched to the new context.
"""
# TODO: Cleanup this prototyped mess of imports and odd dialog
from ayon_core.tools.attribute_defs.dialog import (
AttributeDefinitionsDialog
)
from ayon_core.style import load_stylesheet
from ayon_core.lib import BoolDef, UILabelDef
definitions = [
UILabelDef(
label=(
"You are saving your workfile into a different folder or task."
"\n\n"
"Would you like to update some settings to the new context?\n"
)
),
BoolDef(
"fps",
label="FPS",
tooltip="Reset workfile FPS",
default=True
),
BoolDef(
"frame_range",
label="Frame Range",
tooltip="Reset workfile start and end frame ranges",
default=True
),
BoolDef(
"resolution",
label="Resolution",
tooltip="Reset workfile resolution",
default=True
),
BoolDef(
"colorspace",
label="Colorspace",
tooltip="Reset workfile resolution",
default=True
),
BoolDef(
"instances",
label="Publish instances",
tooltip="Update all publish instance's folder and task to match "
"the new folder and task",
default=True
),
]
dialog = AttributeDefinitionsDialog(definitions)
dialog.setWindowTitle("Saving to different context.")
dialog.setStyleSheet(load_stylesheet())
if not dialog.exec_():
return None
options = dialog.get_values()
with suspended_refresh():
set_context_settings(
fps=options["fps"],
resolution=options["resolution"],
frame_range=options["frame_range"],
colorspace=options["colorspace"]
)
if options["instances"]:
update_content_on_context_change()
dialog.deleteLater()
# Valid FPS

View file

@ -67,6 +67,9 @@ INVENTORY_PATH = os.path.join(PLUGINS_DIR, "inventory")
AVALON_CONTAINERS = ":AVALON_CONTAINERS"
# Track whether the workfile tool is about to save
ABOUT_TO_SAVE = False
class MayaHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost):
name = "maya"
@ -581,6 +584,10 @@ def on_save():
for node, new_id in lib.generate_ids(nodes):
lib.set_id(node, new_id, overwrite=False)
# We are now starting the actual save directly
global ABOUT_TO_SAVE
ABOUT_TO_SAVE = False
def on_open():
"""On scene open let's assume the containers have changed."""
@ -650,6 +657,11 @@ def on_task_changed():
lib.set_context_settings()
lib.update_content_on_context_change()
global ABOUT_TO_SAVE
if not lib.IS_HEADLESS and ABOUT_TO_SAVE:
# Let's prompt the user to update the context settings or not
lib.prompt_reset_context()
def before_workfile_open():
if handle_workfile_locks():
@ -664,6 +676,9 @@ def before_workfile_save(event):
if workdir_path:
create_workspace_mel(workdir_path, project_name)
global ABOUT_TO_SAVE
ABOUT_TO_SAVE = True
def workfile_save_before_xgen(event):
"""Manage Xgen external files when switching context.