From 7c705eded6c715d478dfccbc796c107fdeb0fa9b Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Tue, 9 May 2023 15:53:38 +0200 Subject: [PATCH 01/19] add open template for maya --- openpype/hosts/maya/api/menu.py | 26 +++++++++----- .../maya/api/workfile_template_builder.py | 34 +++++++++++++++++++ 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/openpype/hosts/maya/api/menu.py b/openpype/hosts/maya/api/menu.py index 5284c0249d..91d5b06f80 100644 --- a/openpype/hosts/maya/api/menu.py +++ b/openpype/hosts/maya/api/menu.py @@ -19,6 +19,7 @@ update_placeholder, build_workfile_template, update_workfile_template, + open_template, ) log = logging.getLogger(__name__) @@ -159,24 +160,33 @@ def deferred(): 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=open_template, ) 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) diff --git a/openpype/hosts/maya/api/workfile_template_builder.py b/openpype/hosts/maya/api/workfile_template_builder.py index d65e4c74d2..3342a86b70 100644 --- a/openpype/hosts/maya/api/workfile_template_builder.py +++ b/openpype/hosts/maya/api/workfile_template_builder.py @@ -1,4 +1,5 @@ import json +import os from maya import cmds @@ -24,6 +25,36 @@ class MayaTemplateBuilder(AbstractTemplateBuilder): use_legacy_creators = True + def open_template(self): + """Open template in current scene. + """ + template_preset = self.get_template_preset() + template_path = template_preset["path"] + + if not os.path.exists(template_path): + cmds.confirmDialog( + title="Warning", + message="Template doesn't exist: {}".format(template_path), + button=["OK"], + defaultButton="OK", + ) + return + + result = cmds.confirmDialog( + title="Warning", + message="Opening a template will clear the current scene.", + button=["OK", "Cancel"], + defaultButton="OK", + cancelButton="Cancel", + dismissString="Cancel", + ) + + if result != "OK": + return + + print("opening template {}".format(template_path)) + cmds.file(template_path, open=True, force=True) + def import_template(self, path): """Import template into current scene. Block if a template is already loaded. @@ -298,6 +329,9 @@ def update_workfile_template(*args): builder = MayaTemplateBuilder(registered_host()) builder.rebuild_template() +def open_template(*args): + builder = MayaTemplateBuilder(registered_host()) + builder.open_template() def create_placeholder(*args): host = registered_host() From 24f6cfca306033041da8c8c1c9bb79c4922335d4 Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Tue, 9 May 2023 15:54:40 +0200 Subject: [PATCH 02/19] add abstracmethod --- .../pipeline/workfile/workfile_template_builder.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/openpype/pipeline/workfile/workfile_template_builder.py b/openpype/pipeline/workfile/workfile_template_builder.py index a3d7340367..d234866b00 100644 --- a/openpype/pipeline/workfile/workfile_template_builder.py +++ b/openpype/pipeline/workfile/workfile_template_builder.py @@ -533,6 +533,17 @@ def rebuild_template(self): self.clear_shared_populate_data() + @abstractmethod + def open_template(self, template_path): + """Open template file in default application. + + Args: + template_path (str): Fullpath for current task and + host's template file. + """ + + pass + @abstractmethod def import_template(self, template_path): """ From 36fd0f9b9c709127d6a52964185068529ed31b64 Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Tue, 9 May 2023 15:59:11 +0200 Subject: [PATCH 03/19] add open template for nuke --- openpype/hosts/nuke/api/pipeline.py | 7 ++++- .../nuke/api/workfile_template_builder.py | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/nuke/api/pipeline.py b/openpype/hosts/nuke/api/pipeline.py index d649ffae7f..b45a9dfe7c 100644 --- a/openpype/hosts/nuke/api/pipeline.py +++ b/openpype/hosts/nuke/api/pipeline.py @@ -49,6 +49,7 @@ NukePlaceholderLoadPlugin, NukePlaceholderCreatePlugin, build_workfile_template, + open_template, create_placeholder, update_placeholder, ) @@ -288,7 +289,7 @@ 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() @@ -296,6 +297,10 @@ def _install_menu(): if not ASSIST: menu_template.addSeparator() + menu_template.addCommand( + "Open template", + lambda: open_template() + ) menu_template.addCommand( "Create Place Holder", lambda: create_placeholder() diff --git a/openpype/hosts/nuke/api/workfile_template_builder.py b/openpype/hosts/nuke/api/workfile_template_builder.py index 72d4ffb476..2303ab7fbb 100644 --- a/openpype/hosts/nuke/api/workfile_template_builder.py +++ b/openpype/hosts/nuke/api/workfile_template_builder.py @@ -1,4 +1,5 @@ import collections +import os import nuke from openpype.pipeline import registered_host from openpype.pipeline.workfile.workfile_template_builder import ( @@ -33,6 +34,30 @@ class NukeTemplateBuilder(AbstractTemplateBuilder): """Concrete implementation of AbstractTemplateBuilder for nuke""" + def open_template(self): + """Open template in current scene. + + Args: + path (str): A path to current template (usually given by + get_template_preset implementation) + """ + + template_preset = self.get_template_preset() + template_path = template_preset["path"] + + if not os.path.exists(template_path): + nuke.message("Template doesn't exist: {}".format(template_path)) + return + + result = nuke.ask( + "This will replace current scene with template. Continue?" + ) + if not result: + return + + print("opening template {}".format(template_path)) + nuke.scriptOpen(template_path) + def import_template(self, path): """Import template into current scene. Block if a template is already loaded. @@ -960,6 +985,11 @@ def update_workfile_template(*args): builder.rebuild_template() +def open_template(*args): + builder = NukeTemplateBuilder(registered_host()) + builder.open_template() + + def create_placeholder(*args): host = registered_host() builder = NukeTemplateBuilder(host) From bebaeee66a626196f4cb99df4728a7fa3f5b8010 Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Tue, 9 May 2023 16:21:14 +0200 Subject: [PATCH 04/19] fix linter --- openpype/hosts/maya/api/workfile_template_builder.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openpype/hosts/maya/api/workfile_template_builder.py b/openpype/hosts/maya/api/workfile_template_builder.py index 3342a86b70..7b7c6a1fe4 100644 --- a/openpype/hosts/maya/api/workfile_template_builder.py +++ b/openpype/hosts/maya/api/workfile_template_builder.py @@ -329,10 +329,12 @@ def update_workfile_template(*args): builder = MayaTemplateBuilder(registered_host()) builder.rebuild_template() + def open_template(*args): builder = MayaTemplateBuilder(registered_host()) builder.open_template() + def create_placeholder(*args): host = registered_host() builder = MayaTemplateBuilder(host) From 9c4f1f6035139b7c6bf6873de21bb599c3025a80 Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Thu, 11 May 2023 14:08:16 +0200 Subject: [PATCH 05/19] catch exception to display the message for users --- .../maya/api/workfile_template_builder.py | 20 ++++++++++----- .../nuke/api/workfile_template_builder.py | 25 +++++++++++++------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/openpype/hosts/maya/api/workfile_template_builder.py b/openpype/hosts/maya/api/workfile_template_builder.py index 7b7c6a1fe4..4393ac4cf3 100644 --- a/openpype/hosts/maya/api/workfile_template_builder.py +++ b/openpype/hosts/maya/api/workfile_template_builder.py @@ -1,5 +1,4 @@ import json -import os from maya import cmds @@ -10,6 +9,9 @@ PlaceholderPlugin, LoadPlaceholderItem, PlaceholderLoadMixin, + TemplateLoadFailed, + TemplateNotFound, + TemplateProfileNotFound, ) from openpype.tools.workfile_template_build import ( WorkfileBuildPlaceholderDialog, @@ -28,13 +30,19 @@ class MayaTemplateBuilder(AbstractTemplateBuilder): def open_template(self): """Open template in current scene. """ - template_preset = self.get_template_preset() - template_path = template_preset["path"] - if not os.path.exists(template_path): + try: + template_preset = self.get_template_preset() + template_path = template_preset["path"] + + except ( + TemplateNotFound, + TemplateProfileNotFound, + TemplateLoadFailed + ) as e: cmds.confirmDialog( - title="Warning", - message="Template doesn't exist: {}".format(template_path), + title="Error", + message="An error has occurred:\n{}".format(e), button=["OK"], defaultButton="OK", ) diff --git a/openpype/hosts/nuke/api/workfile_template_builder.py b/openpype/hosts/nuke/api/workfile_template_builder.py index 2303ab7fbb..82502f3eba 100644 --- a/openpype/hosts/nuke/api/workfile_template_builder.py +++ b/openpype/hosts/nuke/api/workfile_template_builder.py @@ -1,5 +1,4 @@ import collections -import os import nuke from openpype.pipeline import registered_host from openpype.pipeline.workfile.workfile_template_builder import ( @@ -8,7 +7,10 @@ LoadPlaceholderItem, CreatePlaceholderItem, PlaceholderLoadMixin, - PlaceholderCreateMixin + PlaceholderCreateMixin, + TemplateNotFound, + TemplateLoadFailed, + TemplateProfileNotFound, ) from openpype.tools.workfile_template_build import ( WorkfileBuildPlaceholderDialog, @@ -27,7 +29,9 @@ duplicate_node, node_tempfile, ) - +from .workio import ( + open_file, +) PLACEHOLDER_SET = "PLACEHOLDERS_SET" @@ -42,11 +46,16 @@ def open_template(self): get_template_preset implementation) """ - template_preset = self.get_template_preset() - template_path = template_preset["path"] + try: + template_preset = self.get_template_preset() + template_path = template_preset["path"] - if not os.path.exists(template_path): - nuke.message("Template doesn't exist: {}".format(template_path)) + except ( + TemplateNotFound, + TemplateProfileNotFound, + TemplateLoadFailed + ) as e: + nuke.critical("An error has occurred:\n{}".format(e)) return result = nuke.ask( @@ -56,7 +65,7 @@ def open_template(self): return print("opening template {}".format(template_path)) - nuke.scriptOpen(template_path) + open_file(template_path) def import_template(self, path): """Import template into current scene. From 961d7abf235ce628fcb33b74a4190b4409904940 Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Thu, 11 May 2023 14:13:37 +0200 Subject: [PATCH 06/19] fix indent --- openpype/hosts/maya/api/workfile_template_builder.py | 8 ++++---- openpype/hosts/nuke/api/workfile_template_builder.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/openpype/hosts/maya/api/workfile_template_builder.py b/openpype/hosts/maya/api/workfile_template_builder.py index 4393ac4cf3..b93132164a 100644 --- a/openpype/hosts/maya/api/workfile_template_builder.py +++ b/openpype/hosts/maya/api/workfile_template_builder.py @@ -36,10 +36,10 @@ def open_template(self): template_path = template_preset["path"] except ( - TemplateNotFound, - TemplateProfileNotFound, - TemplateLoadFailed - ) as e: + TemplateNotFound, + TemplateProfileNotFound, + TemplateLoadFailed + ) as e: cmds.confirmDialog( title="Error", message="An error has occurred:\n{}".format(e), diff --git a/openpype/hosts/nuke/api/workfile_template_builder.py b/openpype/hosts/nuke/api/workfile_template_builder.py index 82502f3eba..d0d34e36f3 100644 --- a/openpype/hosts/nuke/api/workfile_template_builder.py +++ b/openpype/hosts/nuke/api/workfile_template_builder.py @@ -51,10 +51,10 @@ def open_template(self): template_path = template_preset["path"] except ( - TemplateNotFound, - TemplateProfileNotFound, - TemplateLoadFailed - ) as e: + TemplateNotFound, + TemplateProfileNotFound, + TemplateLoadFailed + ) as e: nuke.critical("An error has occurred:\n{}".format(e)) return From 3e2c82d42f19cfd15cdb5acc7da00f23bb657ac9 Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Tue, 16 May 2023 17:58:19 +0200 Subject: [PATCH 07/19] Use Qt for popup message --- .../nuke/api/workfile_template_builder.py | 36 +-------------- .../workfile/workfile_template_builder.py | 44 +++++++++++++++++-- openpype/widgets/message_window.py | 25 ++++++++--- 3 files changed, 61 insertions(+), 44 deletions(-) diff --git a/openpype/hosts/nuke/api/workfile_template_builder.py b/openpype/hosts/nuke/api/workfile_template_builder.py index d0d34e36f3..038270ea69 100644 --- a/openpype/hosts/nuke/api/workfile_template_builder.py +++ b/openpype/hosts/nuke/api/workfile_template_builder.py @@ -8,9 +8,6 @@ CreatePlaceholderItem, PlaceholderLoadMixin, PlaceholderCreateMixin, - TemplateNotFound, - TemplateLoadFailed, - TemplateProfileNotFound, ) from openpype.tools.workfile_template_build import ( WorkfileBuildPlaceholderDialog, @@ -29,44 +26,13 @@ duplicate_node, node_tempfile, ) -from .workio import ( - open_file, -) + PLACEHOLDER_SET = "PLACEHOLDERS_SET" class NukeTemplateBuilder(AbstractTemplateBuilder): """Concrete implementation of AbstractTemplateBuilder for nuke""" - def open_template(self): - """Open template in current scene. - - Args: - path (str): A path to current template (usually given by - get_template_preset implementation) - """ - - try: - template_preset = self.get_template_preset() - template_path = template_preset["path"] - - except ( - TemplateNotFound, - TemplateProfileNotFound, - TemplateLoadFailed - ) as e: - nuke.critical("An error has occurred:\n{}".format(e)) - return - - result = nuke.ask( - "This will replace current scene with template. Continue?" - ) - if not result: - return - - print("opening template {}".format(template_path)) - open_file(template_path) - def import_template(self, path): """Import template into current scene. Block if a template is already loaded. diff --git a/openpype/pipeline/workfile/workfile_template_builder.py b/openpype/pipeline/workfile/workfile_template_builder.py index d234866b00..9cab9af9b7 100644 --- a/openpype/pipeline/workfile/workfile_template_builder.py +++ b/openpype/pipeline/workfile/workfile_template_builder.py @@ -37,7 +37,12 @@ attribute_definitions, ) from openpype.lib.attribute_definitions import get_attributes_keys -from openpype.pipeline import legacy_io, Anatomy +from openpype.pipeline import ( + legacy_io, + Anatomy, + registered_host, + get_current_host_name, +) from openpype.pipeline.load import ( get_loaders_by_name, get_contexts_for_repre_docs, @@ -533,16 +538,47 @@ def rebuild_template(self): self.clear_shared_populate_data() - @abstractmethod - def open_template(self, template_path): + def open_template(self): """Open template file in default application. Args: template_path (str): Fullpath for current task and host's template file. """ + from openpype.widgets import message_window - pass + module_name = 'openpype.hosts.{}.api.lib'.format(get_current_host_name()) + api_lib = __import__(module_name, fromlist=['get_main_window']) + main_window = api_lib.get_main_window() + + try: + template_preset = self.get_template_preset() + template_path = template_preset["path"] + + except ( + TemplateNotFound, + TemplateProfileNotFound, + TemplateLoadFailed + ) as e: + message_window.message( + title="Template Load Failed", + message=str(e), + parent= main_window, + level="critical" + ) + return + + result = message_window.message( + title="Opening template", + message="Caution! This will overwrite your current scene.\n"\ + "Do you want to continue?", + parent= main_window, + level="ask", + ) + + if result: + host = registered_host() + host.open_file(template_path) @abstractmethod def import_template(self, template_path): diff --git a/openpype/widgets/message_window.py b/openpype/widgets/message_window.py index c207702f74..59bbd5bf52 100644 --- a/openpype/widgets/message_window.py +++ b/openpype/widgets/message_window.py @@ -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 == "ask": + self._ask() def _info(self): self.setWindowTitle(self.title) @@ -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 _ask(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 @@ -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 == "ask": + return ex.answer class ScrollMessageBox(QtWidgets.QDialog): From 083dc5db830b5b958857655ac3976b2ba58e2a37 Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Tue, 16 May 2023 18:00:13 +0200 Subject: [PATCH 08/19] Remove code from maya lib --- .../maya/api/workfile_template_builder.py | 39 ------------------- 1 file changed, 39 deletions(-) diff --git a/openpype/hosts/maya/api/workfile_template_builder.py b/openpype/hosts/maya/api/workfile_template_builder.py index b93132164a..561d085b08 100644 --- a/openpype/hosts/maya/api/workfile_template_builder.py +++ b/openpype/hosts/maya/api/workfile_template_builder.py @@ -9,9 +9,6 @@ PlaceholderPlugin, LoadPlaceholderItem, PlaceholderLoadMixin, - TemplateLoadFailed, - TemplateNotFound, - TemplateProfileNotFound, ) from openpype.tools.workfile_template_build import ( WorkfileBuildPlaceholderDialog, @@ -27,42 +24,6 @@ class MayaTemplateBuilder(AbstractTemplateBuilder): use_legacy_creators = True - def open_template(self): - """Open template in current scene. - """ - - try: - template_preset = self.get_template_preset() - template_path = template_preset["path"] - - except ( - TemplateNotFound, - TemplateProfileNotFound, - TemplateLoadFailed - ) as e: - cmds.confirmDialog( - title="Error", - message="An error has occurred:\n{}".format(e), - button=["OK"], - defaultButton="OK", - ) - return - - result = cmds.confirmDialog( - title="Warning", - message="Opening a template will clear the current scene.", - button=["OK", "Cancel"], - defaultButton="OK", - cancelButton="Cancel", - dismissString="Cancel", - ) - - if result != "OK": - return - - print("opening template {}".format(template_path)) - cmds.file(template_path, open=True, force=True) - def import_template(self, path): """Import template into current scene. Block if a template is already loaded. From 873c9d9a03c519143acf1fc80b649f5e79237481 Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Tue, 16 May 2023 18:11:06 +0200 Subject: [PATCH 09/19] Fix linter --- .../workfile/workfile_template_builder.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/openpype/pipeline/workfile/workfile_template_builder.py b/openpype/pipeline/workfile/workfile_template_builder.py index 9cab9af9b7..1f56962eee 100644 --- a/openpype/pipeline/workfile/workfile_template_builder.py +++ b/openpype/pipeline/workfile/workfile_template_builder.py @@ -547,7 +547,9 @@ def open_template(self): """ from openpype.widgets import message_window - module_name = 'openpype.hosts.{}.api.lib'.format(get_current_host_name()) + module_name = 'openpype.hosts.{}.api.lib'.format( + get_current_host_name() + ) api_lib = __import__(module_name, fromlist=['get_main_window']) main_window = api_lib.get_main_window() @@ -561,19 +563,19 @@ def open_template(self): TemplateLoadFailed ) as e: message_window.message( - title="Template Load Failed", - message=str(e), - parent= main_window, - level="critical" + title = "Template Load Failed", + message = str(e), + parent = main_window, + level = "critical" ) return result = message_window.message( - title="Opening template", - message="Caution! This will overwrite your current scene.\n"\ + title = "Opening template", + message = "Caution! This will overwrite your current scene.\n"\ "Do you want to continue?", - parent= main_window, - level="ask", + parent = main_window, + level = "ask", ) if result: From 9676dec82da733a204ecb926ba05b7ae3b7a16d4 Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Wed, 17 May 2023 11:22:05 +0200 Subject: [PATCH 10/19] Fix linter --- .../workfile/workfile_template_builder.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/openpype/pipeline/workfile/workfile_template_builder.py b/openpype/pipeline/workfile/workfile_template_builder.py index 1f56962eee..54018b71b6 100644 --- a/openpype/pipeline/workfile/workfile_template_builder.py +++ b/openpype/pipeline/workfile/workfile_template_builder.py @@ -563,19 +563,19 @@ def open_template(self): TemplateLoadFailed ) as e: message_window.message( - title = "Template Load Failed", - message = str(e), - parent = main_window, - level = "critical" + title="Template Load Failed", + message=str(e), + parent=main_window, + level="critical" ) return result = message_window.message( - title = "Opening template", - message = "Caution! This will overwrite your current scene.\n"\ - "Do you want to continue?", - parent = main_window, - level = "ask", + title="Opening template", + message="Caution! This will overwrite your current scene.\n" + "Do you want to continue?", + parent=main_window, + level="ask", ) if result: From 5acb386ea594ba1a6296b47241e0154dbed6ea07 Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Tue, 23 May 2023 15:58:01 +0200 Subject: [PATCH 11/19] use self.host --- openpype/pipeline/workfile/workfile_template_builder.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openpype/pipeline/workfile/workfile_template_builder.py b/openpype/pipeline/workfile/workfile_template_builder.py index 54018b71b6..d56bf84757 100644 --- a/openpype/pipeline/workfile/workfile_template_builder.py +++ b/openpype/pipeline/workfile/workfile_template_builder.py @@ -40,7 +40,6 @@ from openpype.pipeline import ( legacy_io, Anatomy, - registered_host, get_current_host_name, ) from openpype.pipeline.load import ( @@ -579,8 +578,7 @@ def open_template(self): ) if result: - host = registered_host() - host.open_file(template_path) + self.host.open_file(template_path) @abstractmethod def import_template(self, template_path): From ebfc0a339a553186b3624a337ee388c374367bba Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Wed, 24 May 2023 10:16:20 +0200 Subject: [PATCH 12/19] remove get_current_host_name method --- .../pipeline/workfile/workfile_template_builder.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/openpype/pipeline/workfile/workfile_template_builder.py b/openpype/pipeline/workfile/workfile_template_builder.py index d56bf84757..fabf3652f9 100644 --- a/openpype/pipeline/workfile/workfile_template_builder.py +++ b/openpype/pipeline/workfile/workfile_template_builder.py @@ -37,11 +37,7 @@ attribute_definitions, ) from openpype.lib.attribute_definitions import get_attributes_keys -from openpype.pipeline import ( - legacy_io, - Anatomy, - get_current_host_name, -) +from openpype.pipeline import legacy_io, Anatomy from openpype.pipeline.load import ( get_loaders_by_name, get_contexts_for_repre_docs, @@ -546,9 +542,7 @@ def open_template(self): """ from openpype.widgets import message_window - module_name = 'openpype.hosts.{}.api.lib'.format( - get_current_host_name() - ) + module_name = 'openpype.hosts.{}.api.lib'.format(self.host_name) api_lib = __import__(module_name, fromlist=['get_main_window']) main_window = api_lib.get_main_window() From 3d22cce9792dbdef1da19da75ff80b852e93472b Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Tue, 30 Jan 2024 10:08:03 +0000 Subject: [PATCH 13/19] Refactor Refactored UI code out of pipeline. --- .../maya/api/workfile_template_builder.py | 4 +- .../nuke/api/workfile_template_builder.py | 4 +- .../workfile/workfile_template_builder.py | 43 ++----------------- .../tools/workfile_template_build/__init__.py | 3 ++ openpype/tools/workfile_template_build/lib.py | 29 +++++++++++++ openpype/widgets/message_window.py | 8 ++-- 6 files changed, 44 insertions(+), 47 deletions(-) create mode 100644 openpype/tools/workfile_template_build/lib.py diff --git a/openpype/hosts/maya/api/workfile_template_builder.py b/openpype/hosts/maya/api/workfile_template_builder.py index e91fa839a3..0261d87b36 100644 --- a/openpype/hosts/maya/api/workfile_template_builder.py +++ b/openpype/hosts/maya/api/workfile_template_builder.py @@ -12,6 +12,7 @@ ) from openpype.tools.workfile_template_build import ( WorkfileBuildPlaceholderDialog, + open_template_ui ) from .lib import read, imprint, get_reference_node, get_main_window @@ -342,8 +343,7 @@ def update_workfile_template(*args): def open_template(*args): - builder = MayaTemplateBuilder(registered_host()) - builder.open_template() + open_template_ui(MayaTemplateBuilder(registered_host()), get_main_window()) def create_placeholder(*args): diff --git a/openpype/hosts/nuke/api/workfile_template_builder.py b/openpype/hosts/nuke/api/workfile_template_builder.py index b07330e5b2..b4c780ec07 100644 --- a/openpype/hosts/nuke/api/workfile_template_builder.py +++ b/openpype/hosts/nuke/api/workfile_template_builder.py @@ -11,6 +11,7 @@ ) from openpype.tools.workfile_template_build import ( WorkfileBuildPlaceholderDialog, + open_template_ui ) from .lib import ( find_free_space_to_paste_nodes, @@ -971,8 +972,7 @@ def update_workfile_template(*args): def open_template(*args): - builder = NukeTemplateBuilder(registered_host()) - builder.open_template() + open_template_ui(NukeTemplateBuilder(registered_host()), get_main_window()) def create_placeholder(*args): diff --git a/openpype/pipeline/workfile/workfile_template_builder.py b/openpype/pipeline/workfile/workfile_template_builder.py index c6a9a608f3..fffd761d38 100644 --- a/openpype/pipeline/workfile/workfile_template_builder.py +++ b/openpype/pipeline/workfile/workfile_template_builder.py @@ -552,45 +552,10 @@ def rebuild_template(self): self.clear_shared_populate_data() def open_template(self): - """Open template file in default application. - - Args: - template_path (str): Fullpath for current task and - host's template file. - """ - from openpype.widgets import message_window - - module_name = 'openpype.hosts.{}.api.lib'.format(self.host_name) - api_lib = __import__(module_name, fromlist=['get_main_window']) - main_window = api_lib.get_main_window() - - try: - template_preset = self.get_template_preset() - template_path = template_preset["path"] - - except ( - TemplateNotFound, - TemplateProfileNotFound, - TemplateLoadFailed - ) as e: - message_window.message( - title="Template Load Failed", - message=str(e), - parent=main_window, - level="critical" - ) - return - - result = message_window.message( - title="Opening template", - message="Caution! This will overwrite your current scene.\n" - "Do you want to continue?", - parent=main_window, - level="ask", - ) - - if result: - self.host.open_file(template_path) + """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): diff --git a/openpype/tools/workfile_template_build/__init__.py b/openpype/tools/workfile_template_build/__init__.py index 82a22aea50..ad94ebcf79 100644 --- a/openpype/tools/workfile_template_build/__init__.py +++ b/openpype/tools/workfile_template_build/__init__.py @@ -1,5 +1,8 @@ from .window import WorkfileBuildPlaceholderDialog +from .lib import open_template_ui __all__ = ( "WorkfileBuildPlaceholderDialog", + + "open_template_ui" ) diff --git a/openpype/tools/workfile_template_build/lib.py b/openpype/tools/workfile_template_build/lib.py new file mode 100644 index 0000000000..13c6fd9a2d --- /dev/null +++ b/openpype/tools/workfile_template_build/lib.py @@ -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! This will overwrite your current scene.\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" + ) diff --git a/openpype/widgets/message_window.py b/openpype/widgets/message_window.py index 59bbd5bf52..940d530565 100644 --- a/openpype/widgets/message_window.py +++ b/openpype/widgets/message_window.py @@ -21,8 +21,8 @@ def __init__(self, parent, title, message, level): self._warning() elif self.level == "critical": self._critical() - elif self.level == "ask": - self._ask() + elif self.level == "question": + self._question() def _info(self): self.setWindowTitle(self.title) @@ -43,7 +43,7 @@ def _critical(self): if rc: self.exit() - def _ask(self): + def _question(self): self.answer = None rc = QtWidgets.QMessageBox.question( self, @@ -92,7 +92,7 @@ def message(title=None, message=None, level="info", parent=None): # skip all possible issues that may happen feature is not crutial log.warning("Couldn't center message.", exc_info=True) - if level == "ask": + if level == "question": return ex.answer From c3e81c131f65e8e464852db21991aad89dff22b3 Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Fri, 2 Feb 2024 08:38:49 +0000 Subject: [PATCH 14/19] Move open template to Maya menu.py --- openpype/hosts/maya/api/menu.py | 12 ++++++++---- openpype/hosts/maya/api/workfile_template_builder.py | 7 +------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/openpype/hosts/maya/api/menu.py b/openpype/hosts/maya/api/menu.py index f71c30ce15..18cac34a4a 100644 --- a/openpype/hosts/maya/api/menu.py +++ b/openpype/hosts/maya/api/menu.py @@ -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 @@ -21,9 +22,10 @@ create_placeholder, update_placeholder, build_workfile_template, - update_workfile_template, - open_template, + update_workfile_template ) +from openpype.tools.workfile_template_build import open_template_ui +from .workfile_template_builder import MayaTemplateBuilder log = logging.getLogger(__name__) @@ -185,7 +187,9 @@ def add_menu(): cmds.menuItem( "Open Template", parent=builder_menu, - command=open_template, + command=lambda *args: open_template_ui( + MayaTemplateBuilder(registered_host()), get_main_window() + ), ) cmds.menuItem( "Create Placeholder", diff --git a/openpype/hosts/maya/api/workfile_template_builder.py b/openpype/hosts/maya/api/workfile_template_builder.py index 0261d87b36..aadf1cc21e 100644 --- a/openpype/hosts/maya/api/workfile_template_builder.py +++ b/openpype/hosts/maya/api/workfile_template_builder.py @@ -11,8 +11,7 @@ PlaceholderLoadMixin, ) from openpype.tools.workfile_template_build import ( - WorkfileBuildPlaceholderDialog, - open_template_ui + WorkfileBuildPlaceholderDialog ) from .lib import read, imprint, get_reference_node, get_main_window @@ -342,10 +341,6 @@ def update_workfile_template(*args): builder.rebuild_template() -def open_template(*args): - open_template_ui(MayaTemplateBuilder(registered_host()), get_main_window()) - - def create_placeholder(*args): host = registered_host() builder = MayaTemplateBuilder(host) From 98f69448de6ddd1f74572774368423fc998aaf45 Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Fri, 2 Feb 2024 08:45:44 +0000 Subject: [PATCH 15/19] Remove open_template --- openpype/hosts/nuke/api/pipeline.py | 8 ++++++-- openpype/hosts/nuke/api/workfile_template_builder.py | 7 +------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/openpype/hosts/nuke/api/pipeline.py b/openpype/hosts/nuke/api/pipeline.py index 3d6f3b9423..6bd7e3fb96 100644 --- a/openpype/hosts/nuke/api/pipeline.py +++ b/openpype/hosts/nuke/api/pipeline.py @@ -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 ( @@ -52,9 +54,9 @@ NukePlaceholderLoadPlugin, NukePlaceholderCreatePlugin, build_workfile_template, - open_template, create_placeholder, update_placeholder, + NukeTemplateBuilder, ) from .workio import ( open_file, @@ -326,7 +328,9 @@ def _install_menu(): menu_template.addSeparator() menu_template.addCommand( "Open template", - lambda: open_template() + lambda: open_template_ui( + NukeTemplateBuilder(registered_host()), get_main_window() + ) ) menu_template.addCommand( "Create Place Holder", diff --git a/openpype/hosts/nuke/api/workfile_template_builder.py b/openpype/hosts/nuke/api/workfile_template_builder.py index b4c780ec07..8159840f32 100644 --- a/openpype/hosts/nuke/api/workfile_template_builder.py +++ b/openpype/hosts/nuke/api/workfile_template_builder.py @@ -10,8 +10,7 @@ PlaceholderCreateMixin, ) from openpype.tools.workfile_template_build import ( - WorkfileBuildPlaceholderDialog, - open_template_ui + WorkfileBuildPlaceholderDialog ) from .lib import ( find_free_space_to_paste_nodes, @@ -971,10 +970,6 @@ def update_workfile_template(*args): builder.rebuild_template() -def open_template(*args): - open_template_ui(NukeTemplateBuilder(registered_host()), get_main_window()) - - def create_placeholder(*args): host = registered_host() builder = NukeTemplateBuilder(host) From b58917fefa0940ce3500446d2b25d84c85433bd8 Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Mon, 5 Feb 2024 08:17:25 +0000 Subject: [PATCH 16/19] Update openpype/tools/workfile_template_build/lib.py --- openpype/tools/workfile_template_build/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/tools/workfile_template_build/lib.py b/openpype/tools/workfile_template_build/lib.py index 13c6fd9a2d..2f6dfb414f 100644 --- a/openpype/tools/workfile_template_build/lib.py +++ b/openpype/tools/workfile_template_build/lib.py @@ -11,7 +11,7 @@ def open_template_ui(builder, main_window): result = message_window.message( title="Opening template", - message="Caution! This will overwrite your current scene.\n" + message="Caution! You will loose unsaved changes.\n" "Do you want to continue?", parent=main_window, level="question", From 4e76c9f5dc9282fa65c97faeaf3598f5b9f5e07b Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Fri, 9 Feb 2024 08:16:23 +0000 Subject: [PATCH 17/19] Add submodule --- client/ayon_core/hosts/unreal/integration | 1 + 1 file changed, 1 insertion(+) create mode 160000 client/ayon_core/hosts/unreal/integration diff --git a/client/ayon_core/hosts/unreal/integration b/client/ayon_core/hosts/unreal/integration new file mode 160000 index 0000000000..6d2793170e --- /dev/null +++ b/client/ayon_core/hosts/unreal/integration @@ -0,0 +1 @@ +Subproject commit 6d2793170ed57187842f683a943593973abcc337 From 6538f5b75d96545d0e0089663f2a6c7454b9e2b1 Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Fri, 9 Feb 2024 09:05:31 +0000 Subject: [PATCH 18/19] Update client/ayon_core/hosts/maya/api/menu.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/hosts/maya/api/menu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/hosts/maya/api/menu.py b/client/ayon_core/hosts/maya/api/menu.py index e92878e3e5..70347e91b6 100644 --- a/client/ayon_core/hosts/maya/api/menu.py +++ b/client/ayon_core/hosts/maya/api/menu.py @@ -24,7 +24,7 @@ build_workfile_template, update_workfile_template ) -from openpype.tools.workfile_template_build import open_template_ui +from ayon_core.tools.workfile_template_build import open_template_ui from .workfile_template_builder import MayaTemplateBuilder log = logging.getLogger(__name__) From 1b3ac1f5eba703726f244eeb2ac7e41bde85766a Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Fri, 9 Feb 2024 11:37:15 +0000 Subject: [PATCH 19/19] Move question code to open_template_ui --- .../tools/workfile_template_build/lib.py | 21 ++- openpype/widgets/message_window.py | 156 ------------------ 2 files changed, 10 insertions(+), 167 deletions(-) delete mode 100644 openpype/widgets/message_window.py diff --git a/client/ayon_core/tools/workfile_template_build/lib.py b/client/ayon_core/tools/workfile_template_build/lib.py index 2f6dfb414f..de3a0d0084 100644 --- a/client/ayon_core/tools/workfile_template_build/lib.py +++ b/client/ayon_core/tools/workfile_template_build/lib.py @@ -1,6 +1,8 @@ import traceback -from openpype.widgets import message_window +from qtpy import QtWidgets + +from ayon_core.tools.utils.dialogs import show_message_dialog def open_template_ui(builder, main_window): @@ -8,20 +10,17 @@ def open_template_ui(builder, main_window): 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", + result = QtWidgets.QMessageBox.question( + main_window, + "Opening template", + "Caution! You will loose unsaved changes.\nDo you want to continue?", + QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No ) - - if result: + if result == QtWidgets.QMessageBox.Yes: try: builder.open_template() except Exception: - message_window.message( + show_message_dialog( title="Template Load Failed", message="".join(traceback.format_exc()), parent=main_window, diff --git a/openpype/widgets/message_window.py b/openpype/widgets/message_window.py deleted file mode 100644 index 940d530565..0000000000 --- a/openpype/widgets/message_window.py +++ /dev/null @@ -1,156 +0,0 @@ -import sys -import logging -from qtpy import QtWidgets, QtCore - -log = logging.getLogger(__name__) - - -class Window(QtWidgets.QWidget): - def __init__(self, parent, title, message, level): - super(Window, self).__init__() - self.parent = parent - self.title = title - 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) - rc = QtWidgets.QMessageBox.information( - self, self.title, self.message) - if rc: - self.exit() - - def _warning(self): - rc = QtWidgets.QMessageBox.warning( - self, self.title, self.message) - if rc: - self.exit() - - def _critical(self): - 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() - return - - -def message(title=None, message=None, level="info", parent=None): - """ - Produces centered dialog with specific level denoting severity - Args: - title: (string) dialog title - message: (string) message - level: (string) info|warning|critical - parent: (QtWidgets.QApplication) - - Returns: - None - """ - app = parent - if not app: - app = QtWidgets.QApplication(sys.argv) - - ex = Window(app, title, message, level) - ex.show() - - # Move widget to center of screen - try: - desktop_rect = QtWidgets.QApplication.desktop().availableGeometry(ex) - center = desktop_rect.center() - ex.move( - center.x() - (ex.width() * 0.5), - center.y() - (ex.height() * 0.5) - ) - except Exception: - # skip all possible issues that may happen feature is not crutial - log.warning("Couldn't center message.", exc_info=True) - - if level == "question": - return ex.answer - - -class ScrollMessageBox(QtWidgets.QDialog): - """ - Basic version of scrollable QMessageBox. No other existing dialog - implementation is scrollable. - Args: - icon: - title: - messages: of messages - cancelable: - True if Cancel button should be added - """ - def __init__(self, icon, title, messages, cancelable=False): - super(ScrollMessageBox, self).__init__() - self.setWindowTitle(title) - self.icon = icon - - self.setWindowFlags(QtCore.Qt.WindowTitleHint) - - layout = QtWidgets.QVBoxLayout(self) - - scroll_widget = QtWidgets.QScrollArea(self) - scroll_widget.setWidgetResizable(True) - content_widget = QtWidgets.QWidget(self) - scroll_widget.setWidget(content_widget) - - message_len = 0 - content_layout = QtWidgets.QVBoxLayout(content_widget) - for message in messages: - label_widget = QtWidgets.QLabel(message, content_widget) - content_layout.addWidget(label_widget) - message_len = max(message_len, len(message)) - - # guess size of scrollable area - desktop = QtWidgets.QApplication.desktop() - max_width = desktop.availableGeometry().width() - scroll_widget.setMinimumWidth( - min(max_width, message_len * 6) - ) - layout.addWidget(scroll_widget) - - if not cancelable: # if no specific buttons OK only - buttons = QtWidgets.QDialogButtonBox.Ok - else: - buttons = QtWidgets.QDialogButtonBox.Ok | \ - QtWidgets.QDialogButtonBox.Cancel - - btn_box = QtWidgets.QDialogButtonBox(buttons) - btn_box.accepted.connect(self.accept) - - if cancelable: - btn_box.reject.connect(self.reject) - - btn = QtWidgets.QPushButton('Copy to clipboard') - btn.clicked.connect(lambda: QtWidgets.QApplication. - clipboard().setText("\n".join(messages))) - btn_box.addButton(btn, QtWidgets.QDialogButtonBox.NoRole) - - layout.addWidget(btn_box) - self.show()