From 496a29ba992cd2071612b649e1b4204e14e3503f Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Mon, 5 Oct 2020 13:58:57 +0200 Subject: [PATCH 1/3] fixing harmony js function signatures --- pype/hosts/harmony/__init__.py | 32 ++++++++++++------- pype/plugins/harmony/create/create_render.py | 7 ++-- pype/plugins/harmony/load/load_audio.py | 8 ++--- pype/plugins/harmony/load/load_background.py | 8 ++--- .../harmony/load/load_imagesequence.py | 7 ++-- .../harmony/load/load_template_workfile.py | 7 ++-- .../harmony/publish/collect_current_file.py | 7 ++-- .../harmony/publish/collect_palettes.py | 7 ++-- .../harmony/publish/extract_palette.py | 7 ++-- .../plugins/harmony/publish/extract_render.py | 14 ++++---- .../harmony/publish/extract_template.py | 22 +++++++------ .../harmony/publish/extract_workfile.py | 6 ++-- .../plugins/harmony/publish/validate_audio.py | 13 +++++--- .../publish/validate_scene_settings.py | 11 ++++--- 14 files changed, 89 insertions(+), 67 deletions(-) diff --git a/pype/hosts/harmony/__init__.py b/pype/hosts/harmony/__init__.py index a6a3310374..6721939c7e 100644 --- a/pype/hosts/harmony/__init__.py +++ b/pype/hosts/harmony/__init__.py @@ -14,7 +14,9 @@ signature = str(uuid4()) def set_scene_settings(settings): - func = """function %s_func(args) + + signature = harmony.signature("set_scene_settings") + func = """function %s(args) { if (args[0]["fps"]) { @@ -41,7 +43,7 @@ def set_scene_settings(settings): ) } } - %s_func + %s """ % (signature, signature) harmony.send({"function": func, "args": [settings]}) @@ -62,7 +64,7 @@ def get_asset_settings(): "resolutionHeight": resolution_height } - harmony_config = config.get_presets().["harmony"]["general"] + harmony_config = config.get_presets()["harmony"]["general"] skip_resolution_check = harmony_config.get(["skip_resolution_check"], []) if os.getenv('AVALON_TASK') in skip_resolution_check: @@ -121,15 +123,17 @@ def check_inventory(): outdated_containers.append(container) # Colour nodes. - func = """function %s_func(args){ + sig = harmony.signature("set_color") + func = """function %s(args){ + for( var i =0; i <= args[0].length - 1; ++i) { var red_color = new ColorRGBA(255, 0, 0, 255); node.setColor(args[0][i], red_color); } } - %s_func - """ % (signature, signature) + %s + """ % (sig, sig) outdated_nodes = [] for container in outdated_containers: if container["loader"] == "ImageSequenceLoader": @@ -158,7 +162,9 @@ def application_launch(): def export_template(backdrops, nodes, filepath): - func = """function %s_func(args) + + sig = harmony.signature("set_color") + func = """function %s(args) { var temp_node = node.add("Top", "temp_note", "NOTE", 0, 0, 0); @@ -193,8 +199,8 @@ def export_template(backdrops, nodes, filepath): Action.perform("onActionUpToParent()", "Node View"); node.deleteNode(template_group, true, true); } - %s_func - """ % (signature, signature) + %s + """ % (sig, sig) harmony.send({ "function": func, "args": [ @@ -235,12 +241,14 @@ def install(): def on_pyblish_instance_toggled(instance, old_value, new_value): """Toggle node enabling on instance toggles.""" - func = """function %s_func(args) + + sig = harmony.signature("enable_node") + func = """function %s(args) { node.setEnable(args[0], args[1]) } - %s_func - """ % (signature, signature) + %s + """ % (sig, sig) try: harmony.send( {"function": func, "args": [instance[0], new_value]} diff --git a/pype/plugins/harmony/create/create_render.py b/pype/plugins/harmony/create/create_render.py index 493c585a09..a94e395241 100644 --- a/pype/plugins/harmony/create/create_render.py +++ b/pype/plugins/harmony/create/create_render.py @@ -13,13 +13,14 @@ class CreateRender(harmony.Creator): super(CreateRender, self).__init__(*args, **kwargs) def setup_node(self, node): - func = """function func(args) + sig = harmony.signature() + func = """function %s(args) { node.setTextAttr(args[0], "DRAWING_TYPE", 1, "PNG4"); node.setTextAttr(args[0], "DRAWING_NAME", 1, args[1]); node.setTextAttr(args[0], "MOVIE_PATH", 1, args[1]); } - func - """ + %s + """ % (sig, sig) path = "{0}/{0}".format(node.split("/")[-1]) harmony.send({"function": func, "args": [node, path]}) diff --git a/pype/plugins/harmony/load/load_audio.py b/pype/plugins/harmony/load/load_audio.py index 600791e61a..71ce5b30e0 100644 --- a/pype/plugins/harmony/load/load_audio.py +++ b/pype/plugins/harmony/load/load_audio.py @@ -1,6 +1,6 @@ from avalon import api, harmony - +sig = harmony.signature() func = """ function getUniqueColumnName( column_prefix ) { @@ -18,14 +18,14 @@ function getUniqueColumnName( column_prefix ) return column_name; } -function func(args) +function %s(args) { var uniqueColumnName = getUniqueColumnName(args[0]); column.add(uniqueColumnName , "SOUND"); column.importSound(uniqueColumnName, 1, args[1]); } -func -""" +%s +""" % (sig, sig) class ImportAudioLoader(api.Loader): diff --git a/pype/plugins/harmony/load/load_background.py b/pype/plugins/harmony/load/load_background.py index f96fc275be..b1be9389e3 100644 --- a/pype/plugins/harmony/load/load_background.py +++ b/pype/plugins/harmony/load/load_background.py @@ -324,9 +324,9 @@ class BackgroundLoader(api.Loader): )["result"] container['nodes'].append(read_node) - # Colour node. - func = """function func(args){ + sig = harmony.signature("set_color") + func = """function %s(args){ for( var i =0; i <= args[0].length - 1; ++i) { var red_color = new ColorRGBA(255, 0, 0, 255); @@ -339,8 +339,8 @@ class BackgroundLoader(api.Loader): } } } - func - """ + %s + """ % (sig, sig) if pype.lib.is_latest(representation): harmony.send({"function": func, "args": [node, "green"]}) else: diff --git a/pype/plugins/harmony/load/load_imagesequence.py b/pype/plugins/harmony/load/load_imagesequence.py index c5f50a7d23..056d5554ad 100644 --- a/pype/plugins/harmony/load/load_imagesequence.py +++ b/pype/plugins/harmony/load/load_imagesequence.py @@ -301,7 +301,8 @@ class ImageSequenceLoader(api.Loader): ) # Colour node. - func = """function func(args){ + sig = harmony.signature("copyFile") + func = """function %s(args){ for( var i =0; i <= args[0].length - 1; ++i) { var red_color = new ColorRGBA(255, 0, 0, 255); @@ -314,8 +315,8 @@ class ImageSequenceLoader(api.Loader): } } } - func - """ + %s + """ % (sig, sig) if pype.lib.is_latest(representation): harmony.send({"function": func, "args": [node, "green"]}) else: diff --git a/pype/plugins/harmony/load/load_template_workfile.py b/pype/plugins/harmony/load/load_template_workfile.py index 3e79cc1903..1d1fd7f7be 100644 --- a/pype/plugins/harmony/load/load_template_workfile.py +++ b/pype/plugins/harmony/load/load_template_workfile.py @@ -21,15 +21,16 @@ class ImportTemplateLoader(api.Loader): with zipfile.ZipFile(zip_file, "r") as zip_ref: zip_ref.extractall(template_path) - func = """function func(args) + sig = harmony.signature("paste") + func = """function %s(args) { var template_path = args[0]; var drag_object = copyPaste.pasteTemplateIntoGroup( template_path, "Top", 1 ); } - func - """ + %s + """ % (sig, sig) harmony.send({"function": func, "args": [template_path]}) diff --git a/pype/plugins/harmony/publish/collect_current_file.py b/pype/plugins/harmony/publish/collect_current_file.py index aab66c2b62..40c154e847 100644 --- a/pype/plugins/harmony/publish/collect_current_file.py +++ b/pype/plugins/harmony/publish/collect_current_file.py @@ -13,15 +13,16 @@ class CollectCurrentFile(pyblish.api.ContextPlugin): def process(self, context): """Inject the current working file""" - func = """function func() + sig = harmony.signature() + func = """function %s() { return ( scene.currentProjectPath() + "/" + scene.currentVersionName() + ".xstage" ); } - func - """ + %s + """ % (sig, sig) current_file = harmony.send({"function": func})["result"] context.data["currentFile"] = os.path.normpath(current_file) diff --git a/pype/plugins/harmony/publish/collect_palettes.py b/pype/plugins/harmony/publish/collect_palettes.py index 2a2c1066c0..dc573c381f 100644 --- a/pype/plugins/harmony/publish/collect_palettes.py +++ b/pype/plugins/harmony/publish/collect_palettes.py @@ -13,7 +13,8 @@ class CollectPalettes(pyblish.api.ContextPlugin): hosts = ["harmony"] def process(self, context): - func = """function func() + sig = harmony.signature() + func = """function %s() { var palette_list = PaletteObjectManager.getScenePaletteList(); @@ -26,8 +27,8 @@ class CollectPalettes(pyblish.api.ContextPlugin): return palettes; } - func - """ + %s + """ % (sig, sig) palettes = harmony.send({"function": func})["result"] for name, id in palettes.items(): diff --git a/pype/plugins/harmony/publish/extract_palette.py b/pype/plugins/harmony/publish/extract_palette.py index 9bca005278..9b5f1f5dc9 100644 --- a/pype/plugins/harmony/publish/extract_palette.py +++ b/pype/plugins/harmony/publish/extract_palette.py @@ -13,14 +13,15 @@ class ExtractPalette(pype.api.Extractor): families = ["harmony.palette"] def process(self, instance): - func = """function func(args) + sig = harmony.signature() + func = """function %s(args) { var palette_list = PaletteObjectManager.getScenePaletteList(); var palette = palette_list.getPaletteById(args[0]); return (palette.getPath() + "/" + palette.getName() + ".plt"); } - func - """ + %s + """ % (sig, sig) palette_file = harmony.send( {"function": func, "args": [instance.data["id"]]} )["result"] diff --git a/pype/plugins/harmony/publish/extract_render.py b/pype/plugins/harmony/publish/extract_render.py index 70dceb9ca2..10e6b05bea 100644 --- a/pype/plugins/harmony/publish/extract_render.py +++ b/pype/plugins/harmony/publish/extract_render.py @@ -21,7 +21,8 @@ class ExtractRender(pyblish.api.InstancePlugin): def process(self, instance): # Collect scene data. - func = """function func(write_node) + sig = harmony.signature() + func = """function %s(write_node) { return [ about.getApplicationPath(), @@ -33,8 +34,8 @@ class ExtractRender(pyblish.api.InstancePlugin): sound.getSoundtrackAll().path() ] } - func - """ + %s + """ % (sig, sig) result = harmony.send( {"function": func, "args": [instance[0]]} )["result"] @@ -50,12 +51,13 @@ class ExtractRender(pyblish.api.InstancePlugin): # Set output path to temp folder. path = tempfile.mkdtemp() - func = """function func(args) + sig = harmony.signature() + func = """function %s(args) { node.setTextAttr(args[0], "DRAWING_NAME", 1, args[1]); } - func - """ + %s + """ % (sig, sig) result = harmony.send( { "function": func, diff --git a/pype/plugins/harmony/publish/extract_template.py b/pype/plugins/harmony/publish/extract_template.py index 1ba0befc54..d6851e4027 100644 --- a/pype/plugins/harmony/publish/extract_template.py +++ b/pype/plugins/harmony/publish/extract_template.py @@ -2,7 +2,7 @@ import os import shutil import pype.api -import avalon.harmony +from avalon import harmony import pype.hosts.harmony @@ -30,7 +30,7 @@ class ExtractTemplate(pype.api.Extractor): unique_backdrops = [backdrops[x] for x in set(backdrops.keys())] # Get non-connected nodes within backdrops. - all_nodes = avalon.harmony.send( + all_nodes = harmony.send( {"function": "node.subNodes", "args": ["Top"]} )["result"] for node in [x for x in all_nodes if x not in dependencies]: @@ -66,7 +66,8 @@ class ExtractTemplate(pype.api.Extractor): instance.data["representations"] = [representation] def get_backdrops(self, node): - func = """function func(probe_node) + sig = harmony.signature() + func = """function %s(probe_node) { var backdrops = Backdrop.backdrops("Top"); var valid_backdrops = []; @@ -92,14 +93,15 @@ class ExtractTemplate(pype.api.Extractor): } return valid_backdrops; } - func - """ - return avalon.harmony.send( + %s + """ % (sig, sig) + return harmony.send( {"function": func, "args": [node]} )["result"] def get_dependencies(self, node, dependencies): - func = """function func(args) + sig = harmony.signature() + func = """function %s(args) { var target_node = args[0]; var numInput = node.numberOfInputPorts(target_node); @@ -110,10 +112,10 @@ class ExtractTemplate(pype.api.Extractor): } return dependencies; } - func - """ + %s + """ % (sig, sig) - current_dependencies = avalon.harmony.send( + current_dependencies = harmony.send( {"function": func, "args": [node]} )["result"] diff --git a/pype/plugins/harmony/publish/extract_workfile.py b/pype/plugins/harmony/publish/extract_workfile.py index 304b70e293..3c5af11021 100644 --- a/pype/plugins/harmony/publish/extract_workfile.py +++ b/pype/plugins/harmony/publish/extract_workfile.py @@ -2,7 +2,7 @@ import os import shutil import pype.api -import avalon.harmony +from avalon import harmony import pype.hosts.harmony @@ -15,10 +15,10 @@ class ExtractWorkfile(pype.api.Extractor): def process(self, instance): # Export template. - backdrops = avalon.harmony.send( + backdrops = harmony.send( {"function": "Backdrop.backdrops", "args": ["Top"]} )["result"] - nodes = avalon.harmony.send( + nodes = harmony.send( {"function": "node.subNodes", "args": ["Top"]} )["result"] staging_dir = self.staging_dir(instance) diff --git a/pype/plugins/harmony/publish/validate_audio.py b/pype/plugins/harmony/publish/validate_audio.py index ba113e7610..cc8d2cdc35 100644 --- a/pype/plugins/harmony/publish/validate_audio.py +++ b/pype/plugins/harmony/publish/validate_audio.py @@ -1,14 +1,17 @@ -import json import os import pyblish.api -import avalon.harmony -import pype.hosts.harmony +from avalon import harmony class ValidateAudio(pyblish.api.InstancePlugin): - """Ensures that there is an audio file in the scene. If you are sure that you want to send render without audio, you can disable this validator before clicking on "publish" """ + """Ensures that there is an audio file in the scene. + + If you are sure that you want to send render without audio, you can + disable this validator before clicking on "publish" + + """ order = pyblish.api.ValidatorOrder label = "Validate Audio" @@ -26,7 +29,7 @@ class ValidateAudio(pyblish.api.InstancePlugin): } func """ - result = avalon.harmony.send( + result = harmony.send( {"function": func, "args": [instance[0]]} )["result"] diff --git a/pype/plugins/harmony/publish/validate_scene_settings.py b/pype/plugins/harmony/publish/validate_scene_settings.py index d7895804bd..fbeedeab77 100644 --- a/pype/plugins/harmony/publish/validate_scene_settings.py +++ b/pype/plugins/harmony/publish/validate_scene_settings.py @@ -2,7 +2,7 @@ import json import pyblish.api -import avalon.harmony +from avalon import harmony import pype.hosts.harmony @@ -46,7 +46,8 @@ class ValidateSceneSettings(pyblish.api.InstancePlugin): for string in self.frame_check_filter): expected_settings.pop("frameEnd") - func = """function func() + sig = harmony.signature() + func = """function %s() { return { "fps": scene.getFrameRate(), @@ -56,9 +57,9 @@ class ValidateSceneSettings(pyblish.api.InstancePlugin): "resolutionHeight": scene.defaultResolutionY() }; } - func - """ - current_settings = avalon.harmony.send({"function": func})["result"] + %s + """ % (sig, sig) + current_settings = harmony.send({"function": func})["result"] invalid_settings = [] for key, value in expected_settings.items(): From e0ff9cc04f47a46899f4d03381db80f8dbc5f567 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Mon, 5 Oct 2020 23:15:31 +0200 Subject: [PATCH 2/3] fix QApp utilization and minor style changes --- pype/hosts/harmony/__init__.py | 28 +++++++++---------- pype/plugins/harmony/load/load_background.py | 16 ++++++----- .../plugins/harmony/publish/extract_render.py | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pype/hosts/harmony/__init__.py b/pype/hosts/harmony/__init__.py index 6721939c7e..fbf5ca6f12 100644 --- a/pype/hosts/harmony/__init__.py +++ b/pype/hosts/harmony/__init__.py @@ -1,6 +1,5 @@ import os import sys -from uuid import uuid4 from avalon import api, io, harmony from avalon.vendor import Qt @@ -10,9 +9,6 @@ from pype import lib from pype.api import config -signature = str(uuid4()) - - def set_scene_settings(settings): signature = harmony.signature("set_scene_settings") @@ -64,9 +60,12 @@ def get_asset_settings(): "resolutionHeight": resolution_height } - harmony_config = config.get_presets()["harmony"]["general"] + try: + skip_resolution_check = \ + config.get_presets()["harmony"]["general"]["skip_resolution_check"] + except KeyError: + skip_resolution_check = [] - skip_resolution_check = harmony_config.get(["skip_resolution_check"], []) if os.getenv('AVALON_TASK') in skip_resolution_check: scene_data.pop("resolutionWidth") scene_data.pop("resolutionHeight") @@ -86,21 +85,20 @@ def ensure_scene_settings(): 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: + print("Starting new QApplication..") + app = Qt.QtWidgets.QApplication.instance() + if not app: + app = Qt.QtWidgets.QApplication(sys.argv) + + message_box = Qt.QtWidgets.QMessageBox() + message_box.setIcon(Qt.QtWidgets.QMessageBox.Warning) + msg = "Missing attributes:" 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) diff --git a/pype/plugins/harmony/load/load_background.py b/pype/plugins/harmony/load/load_background.py index b1be9389e3..5ef4535576 100644 --- a/pype/plugins/harmony/load/load_background.py +++ b/pype/plugins/harmony/load/load_background.py @@ -1,11 +1,9 @@ import os -import uuid - -import clique +import json from avalon import api, harmony import pype.lib -import json + copy_files = """function copyFile(srcFilename, dstFilename) { @@ -256,7 +254,9 @@ class BackgroundLoader(api.Loader): container_nodes = [] for layer in sorted(layers): - file_to_import = [os.path.join(bg_folder, layer).replace("\\", "/")] + file_to_import = [ + os.path.join(bg_folder, layer).replace("\\", "/") + ] read_node = harmony.send( { @@ -301,8 +301,10 @@ class BackgroundLoader(api.Loader): print(container) for layer in sorted(layers): - file_to_import = [os.path.join(bg_folder, layer).replace("\\", "/")] - print(20*"#") + file_to_import = [ + os.path.join(bg_folder, layer).replace("\\", "/") + ] + print(20 * "#") print(f"FILE TO REPLACE: {file_to_import}") print(f"LAYER: {layer}") node = harmony.find_node_by_name(layer, "READ") diff --git a/pype/plugins/harmony/publish/extract_render.py b/pype/plugins/harmony/publish/extract_render.py index 10e6b05bea..4fd61efbbf 100644 --- a/pype/plugins/harmony/publish/extract_render.py +++ b/pype/plugins/harmony/publish/extract_render.py @@ -91,7 +91,7 @@ class ExtractRender(pyblish.api.InstancePlugin): if len(collections) > 1: for col in collections: if len(list(col)) > 1: - collection = col + collection = col else: collection = collections[0] From 9772bf76607106b3f8a563aa0cf1966595993007 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 6 Oct 2020 14:07:52 +0200 Subject: [PATCH 3/3] add audio to instance.data only if audio file exists --- pype/plugins/harmony/publish/extract_render.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pype/plugins/harmony/publish/extract_render.py b/pype/plugins/harmony/publish/extract_render.py index 4fd61efbbf..9d3ae33e23 100644 --- a/pype/plugins/harmony/publish/extract_render.py +++ b/pype/plugins/harmony/publish/extract_render.py @@ -45,8 +45,7 @@ class ExtractRender(pyblish.api.InstancePlugin): frame_start = result[4] frame_end = result[5] audio_path = result[6] - if audio_path: - instance.data["audio"] = [{"filename": audio_path}] + instance.data["fps"] = frame_rate # Set output path to temp folder. @@ -139,6 +138,9 @@ class ExtractRender(pyblish.api.InstancePlugin): } instance.data["representations"] = [representation, thumbnail] + if audio_path and os.path.exists(audio_path): + instance.data["audio"] = [{"filename": audio_path}] + # Required for extract_review plugin (L222 onwards). instance.data["frameStart"] = frame_start instance.data["frameEnd"] = frame_end