Working version

This commit is contained in:
Toke Stuart Jepsen 2024-04-10 10:13:59 +01:00
parent b3d7a233e4
commit ddf90da4fd
9 changed files with 158 additions and 67 deletions

View file

@ -8,6 +8,7 @@ from .lib import (
sync_avalon_data_to_workfile,
launch_workfiles_app,
before_project_save,
apply_colorspace_project
)
from .tags import add_tags_to_workfile
from .menu import update_menu_task_label
@ -44,6 +45,8 @@ def afterNewProjectCreated(event):
# reset workfiles startup not to open any more in session
os.environ["WORKFILES_STARTUP"] = "0"
apply_colorspace_project()
def beforeProjectLoad(event):
log.info("before project load event...")
@ -122,6 +125,7 @@ def register_hiero_events():
except RuntimeError:
pass
def register_events():
"""
Adding all callbacks.

View file

@ -11,7 +11,6 @@ import warnings
import json
import ast
import secrets
import shutil
import hiero
from qtpy import QtWidgets, QtCore
@ -36,9 +35,6 @@ from .constants import (
DEFAULT_SEQUENCE_NAME,
DEFAULT_BIN_NAME
)
from ayon_core.pipeline.colorspace import (
get_imageio_config
)
class _CTX:
@ -105,9 +101,9 @@ def flatten(list_):
def get_current_project(remove_untitled=False):
projects = flatten(hiero.core.projects())
projects = hiero.core.projects()
if not remove_untitled:
return next(iter(projects))
return projects[0]
# if remove_untitled
for proj in projects:
@ -1050,18 +1046,68 @@ def _set_hrox_project_knobs(doc, **knobs):
def apply_colorspace_project():
project_name = get_current_project_name()
# get path the the active projects
project = get_current_project(remove_untitled=True)
current_file = project.path()
# close the active project
project.close()
"""Apply colorspaces from settings.
Due to not being able to set the project settings through the Python API,
we need to do use some dubious code to find the widgets and set them. It is
possible to set the project settings without traversing through the widgets
but it involves reading the hrox files from disk with XML, so no in-memory
support. See https://community.foundry.com/discuss/topic/137771/change-a-project-s-default-color-transform-with-python # noqa
for more details.
"""
# get presets for hiero
project_name = get_current_project_name()
imageio = get_project_settings(project_name)["hiero"]["imageio"]
presets = imageio.get("workfile")
# Open Project Settings UI.
for act in hiero.ui.registeredActions():
if act.objectName() == "foundry.project.settings":
act.trigger()
# Find widgets from their sibling label.
labels = {
"Working Space:": "workingSpace",
"Viewer:": "viewerLut",
"Thumbnails:": "thumbnailLut",
"Monitor Out:": "monitorOutLut",
"8 Bit Files:": "eightBitLut",
"16 Bit Files:": "sixteenBitLut",
"Log Files:": "logLut",
"Floating Point Files:": "floatLut"
}
widgets = {x: None for x in labels.values()}
def _recursive_children(widget, labels, widgets):
children = widget.children()
for count, child in enumerate(children):
if isinstance(child, QtWidgets.QLabel):
if child.text() in labels.keys():
widgets[labels[child.text()]] = children[count + 1]
_recursive_children(child, labels, widgets)
app = QtWidgets.QApplication.instance()
title = "Project Settings"
for widget in app.topLevelWidgets():
if isinstance(widget, QtWidgets.QMainWindow):
if widget.windowTitle() != title:
continue
_recursive_children(widget, labels, widgets)
widget.close()
msg = "Setting value \"{}\" is not a valid option for \"{}\""
for key, widget in widgets.items():
options = [widget.itemText(i) for i in range(widget.count())]
setting_value = presets[key]
assert setting_value in options, msg.format(setting_value, key)
widget.setCurrentText(presets[key])
# This code block is for setting up project colorspaces for files on disk.
# Due to not having Python API access to set the project settings, the
# Foundry recommended way is to modify the hrox files on disk with XML. See
# this forum thread for more details;
# https://community.foundry.com/discuss/topic/137771/change-a-project-s-default-color-transform-with-python # noqa
'''
# backward compatibility layer
# TODO: remove this after some time
config_data = get_imageio_config(
@ -1074,6 +1120,13 @@ def apply_colorspace_project():
"ocioConfigName": "custom"
})
# get path the the active projects
project = get_current_project()
current_file = project.path()
msg = "The project needs to be saved to disk to apply colorspace settings."
assert current_file, msg
# save the workfile as subversion "comment:_colorspaceChange"
split_current_file = os.path.splitext(current_file)
copy_current_file = current_file
@ -1116,6 +1169,7 @@ def apply_colorspace_project():
# open the file as current project
hiero.core.openProject(copy_current_file)
'''
def apply_colorspace_clips():
@ -1125,10 +1179,8 @@ def apply_colorspace_clips():
# get presets for hiero
imageio = get_project_settings(project_name)["hiero"]["imageio"]
from pprint import pprint
presets = imageio.get("regexInputs", {}).get("inputs", {})
pprint(presets)
for clip in clips:
clip_media_source_path = clip.mediaSource().firstpath()
clip_name = clip.name()

View file

@ -144,7 +144,7 @@ def add_tags_to_workfile():
# Get project task types.
project_name = get_current_project_name()
project_entity = ayon_api.get_project(project_name)
task_types = project_entity["taskType"]
task_types = project_entity["taskTypes"]
nks_pres_tags["[Tasks]"] = {}
log.debug("__ tasks: {}".format(task_types))
for task_type in task_types:

View file

@ -1495,18 +1495,28 @@ class WorkfileSettings(object):
filter_knobs = [
"viewerProcess",
"wipe_position"
"wipe_position",
"monitorOutOutputTransform"
]
display, viewer = get_viewer_config_from_string(
viewer_dict["viewerProcess"]
)
viewer_process = create_viewer_profile_string(
viewer, display, path_like=False
)
display, viewer = get_viewer_config_from_string(
viewer_dict["output_transform"]
)
output_transform = create_viewer_profile_string(
viewer, display, path_like=False
)
erased_viewers = []
for v in nuke.allNodes(filter="Viewer"):
# set viewProcess to preset from settings
v["viewerProcess"].setValue(
str(viewer_dict["viewerProcess"])
)
v["viewerProcess"].setValue(viewer_process)
if str(viewer_dict["viewerProcess"]) \
not in v["viewerProcess"].value():
if viewer_process not in v["viewerProcess"].value():
copy_inputs = v.dependencies()
copy_knobs = {k: v[k].value() for k in v.knobs()
if k not in filter_knobs}
@ -1524,11 +1534,11 @@ class WorkfileSettings(object):
# set copied knobs
for k, v in copy_knobs.items():
print(k, v)
nv[k].setValue(v)
# set viewerProcess
nv["viewerProcess"].setValue(str(viewer_dict["viewerProcess"]))
nv["viewerProcess"].setValue(viewer_process)
nv["monitorOutOutputTransform"].setValue(output_transform)
if erased_viewers:
log.warning(
@ -1547,7 +1557,6 @@ class WorkfileSettings(object):
host_name="nuke"
)
viewer_process_settings = imageio_host["viewer"]["viewerProcess"]
workfile_settings = imageio_host["workfile"]
color_management = workfile_settings["color_management"]
native_ocio_config = workfile_settings["native_ocio_config"]
@ -1574,29 +1583,6 @@ class WorkfileSettings(object):
residual_path
))
# get monitor lut from settings respecting Nuke version differences
monitor_lut = workfile_settings["thumbnail_space"]
monitor_lut_data = self._get_monitor_settings(
viewer_process_settings, monitor_lut
)
monitor_lut_data["workingSpaceLUT"] = (
workfile_settings["working_space"]
)
# then set the rest
for knob, value_ in monitor_lut_data.items():
# skip unfilled ocio config path
# it will be dict in value
if isinstance(value_, dict):
continue
# skip empty values
if not value_:
continue
if self._root_node[knob].value() not in value_:
self._root_node[knob].setValue(str(value_))
log.debug("nuke.root()['{}'] changed to: {}".format(
knob, value_))
# set ocio config path
if config_data:
config_path = config_data["path"].replace("\\", "/")
@ -1611,6 +1597,31 @@ class WorkfileSettings(object):
if correct_settings:
self._set_ocio_config_path_to_workfile(config_data)
# get monitor lut from settings respecting Nuke version differences
monitor_lut_data = self._get_monitor_settings(
workfile_settings["monitor_out_lut"],
workfile_settings["monitor_lut"]
)
monitor_lut_data.update({
"workingSpaceLUT": workfile_settings["working_space"],
"int8Lut": workfile_settings["int_8_lut"],
"int16Lut": workfile_settings["int_16_lut"],
"logLut": workfile_settings["log_lut"],
"floatLut": workfile_settings["float_lut"]
})
# then set the rest
for knob, value_ in monitor_lut_data.items():
# skip unfilled ocio config path
# it will be dict in value
if isinstance(value_, dict):
continue
# skip empty values
if not value_:
continue
self._root_node[knob].setValue(str(value_))
log.debug("nuke.root()['{}'] changed to: {}".format(knob, value_))
def _get_monitor_settings(self, viewer_lut, monitor_lut):
""" Get monitor settings from viewer and monitor lut

View file

@ -1151,7 +1151,6 @@ def _remove_old_knobs(node):
"OpenpypeDataGroup", "OpenpypeDataGroup_End", "deadlinePriority",
"deadlineChunkSize", "deadlineConcurrentTasks", "Deadline"
]
print(node.name())
# remove all old knobs
for knob in node.allKnobs():

View file

@ -149,15 +149,15 @@ class ImageIOSettings(BaseSettingsModel):
DEFAULT_IMAGEIO_SETTINGS = {
"workfile": {
"ocioConfigName": "nuke-default",
"workingSpace": "linear",
"viewerLut": "sRGB",
"eightBitLut": "sRGB",
"sixteenBitLut": "sRGB",
"logLut": "Cineon",
"floatLut": "linear",
"thumbnailLut": "sRGB",
"monitorOutLut": "sRGB"
"ocioConfigName": "aces_1.2",
"workingSpace": "role_scene_linear",
"viewerLut": "ACES/sRGB",
"eightBitLut": "role_matte_paint",
"sixteenBitLut": "role_texture_paint",
"logLut": "role_compositing_log",
"floatLut": "role_scene_linear",
"thumbnailLut": "ACES/sRGB",
"monitorOutLut": "ACES/sRGB"
},
"regexInputs": {
"inputs": [

View file

@ -1 +1 @@
__version__ = "0.1.2"
__version__ = "0.1.3"

View file

@ -97,8 +97,23 @@ class WorkfileColorspaceSettings(BaseSettingsModel):
working_space: str = SettingsField(
title="Working Space"
)
thumbnail_space: str = SettingsField(
title="Thumbnail Space"
monitor_lut: str = SettingsField(
title="Thumbnails"
)
monitor_out_lut: str = SettingsField(
title="Monitor Out"
)
int_8_lut: str = SettingsField(
title="8-bit Files"
)
int_16_lut: str = SettingsField(
title="16-bit Files"
)
log_lut: str = SettingsField(
title="Log Files"
)
float_lut: str = SettingsField(
title="Float Files"
)
@ -120,6 +135,9 @@ class ViewProcessModel(BaseSettingsModel):
viewerProcess: str = SettingsField(
title="Viewer Process Name"
)
output_transform: str = SettingsField(
title="Output Transform"
)
class ImageIOConfigModel(BaseSettingsModel):
@ -214,16 +232,23 @@ class ImageIOSettings(BaseSettingsModel):
DEFAULT_IMAGEIO_SETTINGS = {
"viewer": {
"viewerProcess": "sRGB (default)"
"viewerProcess": "ACES/sRGB",
"output_transform": "ACES/sRGB"
},
"baking": {
"viewerProcess": "rec709 (default)"
"viewerProcess": "ACES/Rec.709",
"output_transform": "ACES/Rec.709"
},
"workfile": {
"color_management": "OCIO",
"native_ocio_config": "nuke-default",
"working_space": "scene_linear",
"thumbnail_space": "sRGB (default)",
"native_ocio_config": "aces_1.2",
"working_space": "role_scene_linear",
"monitor_lut": "ACES/sRGB",
"monitor_out_lut": "ACES/sRGB",
"int_8_lut": "role_matte_paint",
"int_16_lut": "role_texture_paint",
"log_lut": "role_compositing_log",
"float_lut": "role_scene_linear"
},
"nodes": {
"required_nodes": [

View file

@ -1 +1 @@
__version__ = "0.1.10"
__version__ = "0.1.11"