Refactored UI code out of pipeline.
This commit is contained in:
Toke Stuart Jepsen 2024-01-30 10:08:03 +00:00
parent a0aeb0bc35
commit 3d22cce979
6 changed files with 44 additions and 47 deletions

View file

@ -12,6 +12,7 @@ from openpype.pipeline.workfile.workfile_template_builder import (
)
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):

View file

@ -11,6 +11,7 @@ from openpype.pipeline.workfile.workfile_template_builder import (
)
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):

View file

@ -552,45 +552,10 @@ class AbstractTemplateBuilder(object):
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):

View file

@ -1,5 +1,8 @@
from .window import WorkfileBuildPlaceholderDialog
from .lib import open_template_ui
__all__ = (
"WorkfileBuildPlaceholderDialog",
"open_template_ui"
)

View file

@ -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"
)

View file

@ -21,8 +21,8 @@ class Window(QtWidgets.QWidget):
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 @@ class Window(QtWidgets.QWidget):
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