mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Validate scene settings.
This commit is contained in:
parent
9fee13a58a
commit
2c398c07ba
2 changed files with 109 additions and 41 deletions
|
|
@ -7,46 +7,7 @@ import pyblish.api
|
|||
from pype import lib
|
||||
|
||||
|
||||
def ensure_scene_settings():
|
||||
asset_data = lib.get_asset()["data"]
|
||||
fps = asset_data.get("fps")
|
||||
frame_start = asset_data.get("frameStart")
|
||||
frame_end = asset_data.get("frameEnd")
|
||||
resolution_width = asset_data.get("resolutionWidth")
|
||||
resolution_height = asset_data.get("resolutionHeight")
|
||||
|
||||
settings = {
|
||||
"fps": fps,
|
||||
"frameStart": frame_start,
|
||||
"frameEnd": frame_end,
|
||||
"resolutionWidth": resolution_width,
|
||||
"resolutionHeight": resolution_height
|
||||
}
|
||||
|
||||
invalid_settings = []
|
||||
valid_settings = {}
|
||||
for key, value in settings.items():
|
||||
if value is None:
|
||||
invalid_settings.append(key)
|
||||
else:
|
||||
valid_settings[key] = value
|
||||
|
||||
# Warn about missing attributes.
|
||||
print("Starting new QApplication..")
|
||||
app = Qt.QtWidgets.QApplication(sys.argv)
|
||||
|
||||
message_box = Qt.QtWidgets.QMessageBox()
|
||||
message_box.setIcon(Qt.QtWidgets.QMessageBox.Warning)
|
||||
msg = "Missing attributes:"
|
||||
if invalid_settings:
|
||||
for item in invalid_settings:
|
||||
msg += f"\n{item}"
|
||||
message_box.setText(msg)
|
||||
message_box.exec_()
|
||||
|
||||
# Garbage collect QApplication.
|
||||
del app
|
||||
|
||||
def set_scene_settings(settings):
|
||||
func = """function func(args)
|
||||
{
|
||||
if (args[0]["fps"])
|
||||
|
|
@ -81,7 +42,54 @@ def ensure_scene_settings():
|
|||
}
|
||||
func
|
||||
"""
|
||||
harmony.send({"function": func, "args": [valid_settings]})
|
||||
harmony.send({"function": func, "args": [settings]})
|
||||
|
||||
|
||||
def get_asset_settings():
|
||||
asset_data = lib.get_asset()["data"]
|
||||
fps = asset_data.get("fps")
|
||||
frame_start = asset_data.get("frameStart")
|
||||
frame_end = asset_data.get("frameEnd")
|
||||
resolution_width = asset_data.get("resolutionWidth")
|
||||
resolution_height = asset_data.get("resolutionHeight")
|
||||
|
||||
return {
|
||||
"fps": fps,
|
||||
"frameStart": frame_start,
|
||||
"frameEnd": frame_end,
|
||||
"resolutionWidth": resolution_width,
|
||||
"resolutionHeight": resolution_height
|
||||
}
|
||||
|
||||
|
||||
def ensure_scene_settings():
|
||||
settings = get_asset_settings()
|
||||
|
||||
invalid_settings = []
|
||||
valid_settings = {}
|
||||
for key, value in settings.items():
|
||||
if value is None:
|
||||
invalid_settings.append(key)
|
||||
else:
|
||||
valid_settings[key] = value
|
||||
|
||||
# Warn about missing attributes.
|
||||
print("Starting new QApplication..")
|
||||
app = Qt.QtWidgets.QApplication(sys.argv)
|
||||
|
||||
message_box = Qt.QtWidgets.QMessageBox()
|
||||
message_box.setIcon(Qt.QtWidgets.QMessageBox.Warning)
|
||||
msg = "Missing attributes:"
|
||||
if invalid_settings:
|
||||
for item in invalid_settings:
|
||||
msg += f"\n{item}"
|
||||
message_box.setText(msg)
|
||||
message_box.exec_()
|
||||
|
||||
# Garbage collect QApplication.
|
||||
del app
|
||||
|
||||
set_scene_settings(valid_settings)
|
||||
|
||||
|
||||
def install():
|
||||
|
|
|
|||
60
pype/plugins/harmony/publish/validate_scene_settings.py
Normal file
60
pype/plugins/harmony/publish/validate_scene_settings.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import json
|
||||
|
||||
import pyblish.api
|
||||
|
||||
import avalon.harmony
|
||||
import pype.hosts.harmony
|
||||
|
||||
|
||||
class ValidateSceneSettingsRepair(pyblish.api.Action):
|
||||
"""Repair the instance."""
|
||||
|
||||
label = "Repair"
|
||||
icon = "wrench"
|
||||
on = "failed"
|
||||
|
||||
def process(self, context, plugin):
|
||||
pype.hosts.harmony.set_scene_settings(
|
||||
pype.hosts.harmony.get_asset_settings()
|
||||
)
|
||||
|
||||
|
||||
class ValidateSceneSettings(pyblish.api.InstancePlugin):
|
||||
"""Ensure the scene settings are in sync with database."""
|
||||
|
||||
order = pyblish.api.ValidatorOrder
|
||||
label = "Validate Scene Settings"
|
||||
families = ["workfile"]
|
||||
hosts = ["harmony"]
|
||||
actions = [ValidateSceneSettingsRepair]
|
||||
|
||||
def process(self, instance):
|
||||
expected_settings = pype.hosts.harmony.get_asset_settings()
|
||||
|
||||
func = """function func()
|
||||
{
|
||||
return {
|
||||
"fps": scene.getFrameRate(),
|
||||
"frameStart": scene.getStartFrame(),
|
||||
"frameEnd": scene.getStopFrame(),
|
||||
"resolutionWidth": scene.defaultResolutionX(),
|
||||
"resolutionHeight": scene.defaultResolutionY()
|
||||
};
|
||||
}
|
||||
func
|
||||
"""
|
||||
current_settings = avalon.harmony.send({"function": func})["result"]
|
||||
|
||||
invalid_settings = []
|
||||
for key, value in expected_settings.items():
|
||||
if value != current_settings[key]:
|
||||
invalid_settings.append({
|
||||
"name": key,
|
||||
"expected": value,
|
||||
"current": current_settings[key]
|
||||
})
|
||||
|
||||
msg = "Found invalid settings:\n{}".format(
|
||||
json.dumps(invalid_settings, sort_keys=True, indent=4)
|
||||
)
|
||||
assert not invalid_settings, msg
|
||||
Loading…
Add table
Add a link
Reference in a new issue