Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Tools: Fix style and modality of errors in loader and creator #2489

Merged
23 changes: 21 additions & 2 deletions openpype/style/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import json
import collections
from openpype import resources
import six

from openpype import resources

from .color_defs import parse_color


Expand All @@ -12,6 +14,18 @@
current_dir = os.path.dirname(os.path.abspath(__file__))


def get_style_image_path(image_name):
# All filenames are lowered
image_name = image_name.lower()
# Male sure filename has png extension
if not image_name.endswith(".png"):
image_name += ".png"
filepath = os.path.join(current_dir, "images", image_name)
if os.path.exists(filepath):
return filepath
return None


def _get_colors_raw_data():
"""Read data file with stylesheet fill values.

Expand Down Expand Up @@ -160,6 +174,11 @@ def load_stylesheet():
return _STYLESHEET_CACHE


def app_icon_path():
def get_app_icon_path():
"""Path to OpenPype icon."""
return resources.get_openpype_icon_filepath()


def app_icon_path():
# Backwards compatibility
return get_app_icon_path()
101 changes: 48 additions & 53 deletions openpype/tools/creator/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,49 @@

from openpype import style
from openpype.pipeline.create import SUBSET_NAME_ALLOWED_SYMBOLS
from openpype.tools.utils import ErrorMessageBox


class CreateErrorMessageBox(QtWidgets.QDialog):
class CreateErrorMessageBox(ErrorMessageBox):
def __init__(
self,
family,
subset_name,
asset_name,
exc_msg,
formatted_traceback,
parent=None
parent
):
super(CreateErrorMessageBox, self).__init__(parent)
self.setWindowTitle("Creation failed")
self.setFocusPolicy(QtCore.Qt.StrongFocus)
self.setWindowFlags(
self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint
)

body_layout = QtWidgets.QVBoxLayout(self)

main_label = (
self._family = family
self._subset_name = subset_name
self._asset_name = asset_name
self._exc_msg = exc_msg
self._formatted_traceback = formatted_traceback
super(CreateErrorMessageBox, self).__init__("Creation failed", parent)

def _create_top_widget(self, parent_widget):
label_widget = QtWidgets.QLabel(parent_widget)
label_widget.setText(
"<span style='font-size:18pt;'>Failed to create</span>"
)
main_label_widget = QtWidgets.QLabel(main_label, self)
body_layout.addWidget(main_label_widget)
return label_widget

def _get_report_data(self):
report_message = (
"Failed to create Subset: \"{subset}\" Family: \"{family}\""
" in Asset: \"{asset}\""
"\n\nError: {message}"
).format(
subset=self._subset_name,
family=self._family,
asset=self._asset_name,
message=self._exc_msg
)
if self._formatted_traceback:
report_message += "\n\n{}".format(self._formatted_traceback)
return [report_message]

def _create_content(self, content_layout):
item_name_template = (
"<span style='font-weight:bold;'>Family:</span> {}<br>"
"<span style='font-weight:bold;'>Subset:</span> {}<br>"
Expand All @@ -42,50 +58,29 @@ def __init__(
exc_msg_template = "<span style='font-weight:bold'>{}</span>"

line = self._create_line()
body_layout.addWidget(line)
content_layout.addWidget(line)

item_name = item_name_template.format(family, subset_name, asset_name)
item_name_widget = QtWidgets.QLabel(
item_name.replace("\n", "<br>"), self
item_name_widget = QtWidgets.QLabel(self)
item_name_widget.setText(
item_name_template.format(
self._family, self._subset_name, self._asset_name
)
)
body_layout.addWidget(item_name_widget)
content_layout.addWidget(item_name_widget)

exc_msg = exc_msg_template.format(exc_msg.replace("\n", "<br>"))
message_label_widget = QtWidgets.QLabel(exc_msg, self)
body_layout.addWidget(message_label_widget)
message_label_widget = QtWidgets.QLabel(self)
message_label_widget.setText(
exc_msg_template.format(self.convert_text_for_html(self._exc_msg))
)
content_layout.addWidget(message_label_widget)

if formatted_traceback:
tb_widget = QtWidgets.QLabel(
formatted_traceback.replace("\n", "<br>"), self
)
tb_widget.setTextInteractionFlags(
QtCore.Qt.TextBrowserInteraction
if self._formatted_traceback:
line_widget = self._create_line()
tb_widget = self._create_traceback_widget(
self._formatted_traceback
)
body_layout.addWidget(tb_widget)

footer_widget = QtWidgets.QWidget(self)
footer_layout = QtWidgets.QHBoxLayout(footer_widget)
button_box = QtWidgets.QDialogButtonBox(QtCore.Qt.Vertical)
button_box.setStandardButtons(
QtWidgets.QDialogButtonBox.StandardButton.Ok
)
button_box.accepted.connect(self._on_accept)
footer_layout.addWidget(button_box, alignment=QtCore.Qt.AlignRight)
body_layout.addWidget(footer_widget)

def showEvent(self, event):
self.setStyleSheet(style.load_stylesheet())
super(CreateErrorMessageBox, self).showEvent(event)

def _on_accept(self):
self.close()

def _create_line(self):
line = QtWidgets.QFrame(self)
line.setFixedHeight(2)
line.setFrameShape(QtWidgets.QFrame.HLine)
line.setFrameShadow(QtWidgets.QFrame.Sunken)
return line
content_layout.addWidget(line_widget)
content_layout.addWidget(tb_widget)


class SubsetNameValidator(QtGui.QRegExpValidator):
Expand Down
6 changes: 5 additions & 1 deletion openpype/tools/creator/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,11 @@ def _on_create(self):

if error_info:
box = CreateErrorMessageBox(
creator_plugin.family, subset_name, asset_name, *error_info
creator_plugin.family,
subset_name,
asset_name,
*error_info,
parent=self
)
box.show()
# Store dialog so is not garbage collected before is shown
Expand Down
85 changes: 43 additions & 42 deletions openpype/tools/loader/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
from avalon import api, pipeline
from avalon.lib import HeroVersionType

from openpype.tools.utils import lib as tools_lib
from openpype.tools.utils import (
ErrorMessageBox,
lib as tools_lib
)
from openpype.tools.utils.delegates import (
VersionDelegate,
PrettyTimeDelegate
Expand Down Expand Up @@ -64,67 +67,65 @@ def set_label(self, label):
self.label_widget.setText(label)


class LoadErrorMessageBox(QtWidgets.QDialog):
class LoadErrorMessageBox(ErrorMessageBox):
def __init__(self, messages, parent=None):
super(LoadErrorMessageBox, self).__init__(parent)
self.setWindowTitle("Loading failed")
self.setFocusPolicy(QtCore.Qt.StrongFocus)

body_layout = QtWidgets.QVBoxLayout(self)
self._messages = messages
super(LoadErrorMessageBox, self).__init__("Loading failed", parent)

main_label = (
def _create_top_widget(self, parent_widget):
label_widget = QtWidgets.QLabel(parent_widget)
label_widget.setText(
"<span style='font-size:18pt;'>Failed to load items</span>"
)
main_label_widget = QtWidgets.QLabel(main_label, self)
body_layout.addWidget(main_label_widget)
return label_widget

def _get_report_data(self):
report_data = []
for exc_msg, tb_text, repre, subset, version in self._messages:
report_message = (
"During load error happened on Subset: \"{subset}\""
" Representation: \"{repre}\" Version: {version}"
"\n\nError message: {message}"
).format(
subset=subset,
repre=repre,
version=version,
message=exc_msg
)
if tb_text:
report_message += "\n\n{}".format(tb_text)
report_data.append(report_message)
return report_data

def _create_content(self, content_layout):
item_name_template = (
"<span style='font-weight:bold;'>Subset:</span> {}<br>"
"<span style='font-weight:bold;'>Version:</span> {}<br>"
"<span style='font-weight:bold;'>Representation:</span> {}<br>"
)
exc_msg_template = "<span style='font-weight:bold'>{}</span>"

for exc_msg, tb, repre, subset, version in messages:
for exc_msg, tb_text, repre, subset, version in self._messages:
line = self._create_line()
body_layout.addWidget(line)
content_layout.addWidget(line)

item_name = item_name_template.format(subset, version, repre)
item_name_widget = QtWidgets.QLabel(
item_name.replace("\n", "<br>"), self
)
body_layout.addWidget(item_name_widget)
item_name_widget.setWordWrap(True)
content_layout.addWidget(item_name_widget)

exc_msg = exc_msg_template.format(exc_msg.replace("\n", "<br>"))
message_label_widget = QtWidgets.QLabel(exc_msg, self)
body_layout.addWidget(message_label_widget)

if tb:
tb_widget = QtWidgets.QLabel(tb.replace("\n", "<br>"), self)
tb_widget.setTextInteractionFlags(
QtCore.Qt.TextBrowserInteraction
)
body_layout.addWidget(tb_widget)

footer_widget = QtWidgets.QWidget(self)
footer_layout = QtWidgets.QHBoxLayout(footer_widget)
buttonBox = QtWidgets.QDialogButtonBox(QtCore.Qt.Vertical)
buttonBox.setStandardButtons(
QtWidgets.QDialogButtonBox.StandardButton.Ok
)
buttonBox.accepted.connect(self._on_accept)
footer_layout.addWidget(buttonBox, alignment=QtCore.Qt.AlignRight)
body_layout.addWidget(footer_widget)

def _on_accept(self):
self.close()
message_label_widget.setWordWrap(True)
content_layout.addWidget(message_label_widget)

def _create_line(self):
line = QtWidgets.QFrame(self)
line.setFixedHeight(2)
line.setFrameShape(QtWidgets.QFrame.HLine)
line.setFrameShadow(QtWidgets.QFrame.Sunken)
return line
if tb_text:
line = self._create_line()
tb_widget = self._create_traceback_widget(tb_text, self)
content_layout.addWidget(line)
content_layout.addWidget(tb_widget)


class SubsetWidget(QtWidgets.QWidget):
Expand Down Expand Up @@ -535,7 +536,7 @@ def on_context_menu(self, point):
self.load_ended.emit()

if error_info:
box = LoadErrorMessageBox(error_info)
box = LoadErrorMessageBox(error_info, self)
box.show()

def selected_subsets(self, _groups=False, _merged=False, _other=True):
Expand Down Expand Up @@ -1431,7 +1432,7 @@ def _process_action(self, items, menu, point):
self.load_ended.emit()

if errors:
box = LoadErrorMessageBox(errors)
box = LoadErrorMessageBox(errors, self)
box.show()

def _get_optional_labels(self, loaders, selected_side):
Expand Down
10 changes: 10 additions & 0 deletions openpype/tools/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
from .widgets import (
PlaceholderLineEdit,
BaseClickableFrame,
ClickableFrame,
ExpandBtn,
)

from .error_dialog import ErrorMessageBox


__all__ = (
"PlaceholderLineEdit",
"BaseClickableFrame",
"ClickableFrame",
"ExpandBtn",

"ErrorMessageBox"
)
Loading