Use Qt for popup message

This commit is contained in:
clement.hector 2023-05-16 17:58:19 +02:00
parent 961d7abf23
commit 3e2c82d42f
3 changed files with 61 additions and 44 deletions

View file

@ -8,9 +8,6 @@ from openpype.pipeline.workfile.workfile_template_builder import (
CreatePlaceholderItem,
PlaceholderLoadMixin,
PlaceholderCreateMixin,
TemplateNotFound,
TemplateLoadFailed,
TemplateProfileNotFound,
)
from openpype.tools.workfile_template_build import (
WorkfileBuildPlaceholderDialog,
@ -29,44 +26,13 @@ from .lib import (
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.

View file

@ -37,7 +37,12 @@ from openpype.lib import (
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 @@ class AbstractTemplateBuilder(object):
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):

View file

@ -13,12 +13,16 @@ class Window(QtWidgets.QWidget):
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 @@ class Window(QtWidgets.QWidget):
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):