diff --git a/openpype/resources/__init__.py b/openpype/resources/__init__.py index 34a833d080..49eee21002 100644 --- a/openpype/resources/__init__.py +++ b/openpype/resources/__init__.py @@ -14,6 +14,15 @@ def get_resource(*args): return os.path.normpath(os.path.join(RESOURCES_DIR, *args)) +def get_image_path(*args): + """Helper function to get images. + + Args: + *: Filepath part items. + """ + return get_resource("images", *args) + + def get_liberation_font_path(bold=False, italic=False): font_name = "LiberationSans" suffix = "" diff --git a/openpype/resources/images/warning.png b/openpype/resources/images/warning.png new file mode 100644 index 0000000000..3b4ae861f9 Binary files /dev/null and b/openpype/resources/images/warning.png differ diff --git a/openpype/tools/project_manager/project_manager/style.py b/openpype/tools/project_manager/project_manager/style.py index 9fa7a5520b..d24fc7102f 100644 --- a/openpype/tools/project_manager/project_manager/style.py +++ b/openpype/tools/project_manager/project_manager/style.py @@ -1,8 +1,8 @@ import os from Qt import QtCore, QtGui -from openpype.style import get_objected_colors from avalon.vendor import qtawesome +from openpype.tools.utils import paint_image_with_color class ResourceCache: @@ -91,17 +91,6 @@ class ResourceCache: icon.addPixmap(disabled_pix, QtGui.QIcon.Disabled, QtGui.QIcon.Off) return icon - @classmethod - def get_warning_pixmap(cls): - src_image = get_warning_image() - colors = get_objected_colors() - color_value = colors["delete-btn-bg"] - - return paint_image_with_color( - src_image, - color_value.get_qcolor() - ) - def get_remove_image(): image_path = os.path.join( @@ -110,36 +99,3 @@ def get_remove_image(): "bin.png" ) return QtGui.QImage(image_path) - - -def get_warning_image(): - image_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "images", - "warning.png" - ) - return QtGui.QImage(image_path) - - -def paint_image_with_color(image, color): - """TODO: This function should be imported from utils. - - At the moment of creation is not available yet. - """ - width = image.width() - height = image.height() - - alpha_mask = image.createAlphaMask() - alpha_region = QtGui.QRegion(QtGui.QBitmap.fromImage(alpha_mask)) - - pixmap = QtGui.QPixmap(width, height) - pixmap.fill(QtCore.Qt.transparent) - - painter = QtGui.QPainter(pixmap) - painter.setClipRegion(alpha_region) - painter.setPen(QtCore.Qt.NoPen) - painter.setBrush(color) - painter.drawRect(QtCore.QRect(0, 0, width, height)) - painter.end() - - return pixmap diff --git a/openpype/tools/project_manager/project_manager/widgets.py b/openpype/tools/project_manager/project_manager/widgets.py index 4b5aca35ef..ebf344b387 100644 --- a/openpype/tools/project_manager/project_manager/widgets.py +++ b/openpype/tools/project_manager/project_manager/widgets.py @@ -4,14 +4,16 @@ from .constants import ( NAME_ALLOWED_SYMBOLS, NAME_REGEX ) -from .style import ResourceCache from openpype.lib import ( create_project, PROJECT_NAME_ALLOWED_SYMBOLS, PROJECT_NAME_REGEX ) from openpype.style import load_stylesheet -from openpype.tools.utils import PlaceholderLineEdit +from openpype.tools.utils import ( + PlaceholderLineEdit, + get_warning_pixmap +) from avalon.api import AvalonMongoDB from Qt import QtWidgets, QtCore, QtGui @@ -338,7 +340,7 @@ class ConfirmProjectDeletion(QtWidgets.QDialog): top_widget = QtWidgets.QWidget(self) - warning_pixmap = ResourceCache.get_warning_pixmap() + warning_pixmap = get_warning_pixmap() warning_icon_label = PixmapLabel(warning_pixmap, top_widget) message_label = QtWidgets.QLabel(top_widget) diff --git a/openpype/tools/utils/__init__.py b/openpype/tools/utils/__init__.py index eb0cb1eef5..9363007532 100644 --- a/openpype/tools/utils/__init__.py +++ b/openpype/tools/utils/__init__.py @@ -8,7 +8,8 @@ from .widgets import ( from .error_dialog import ErrorMessageBox from .lib import ( WrappedCallbackItem, - paint_image_with_color + paint_image_with_color, + get_warning_pixmap ) @@ -22,4 +23,5 @@ __all__ = ( "WrappedCallbackItem", "paint_image_with_color", + "get_warning_pixmap", ) diff --git a/openpype/tools/utils/delegates.py b/openpype/tools/utils/delegates.py index 1caed732d8..4ec6079bb7 100644 --- a/openpype/tools/utils/delegates.py +++ b/openpype/tools/utils/delegates.py @@ -7,7 +7,6 @@ import Qt from Qt import QtWidgets, QtGui, QtCore from avalon.lib import HeroVersionType -from openpype.style import get_objected_colors from .models import TreeModel from . import lib diff --git a/openpype/tools/utils/lib.py b/openpype/tools/utils/lib.py index caaad522ad..76ad944ce5 100644 --- a/openpype/tools/utils/lib.py +++ b/openpype/tools/utils/lib.py @@ -14,6 +14,8 @@ from openpype.api import ( Logger ) from openpype.lib import filter_profiles +from openpype.style import get_objected_colors +from openpype.resources import get_image_path def center_window(window): @@ -670,3 +672,19 @@ class WrappedCallbackItem: finally: self._done = True + + +def get_warning_pixmap(color=None): + """Warning icon as QPixmap. + + Args: + color(QtGui.QColor): Color that will be used to paint warning icon. + """ + src_image_path = get_image_path("warning.png") + src_image = QtGui.QImage(src_image_path) + if color is None: + colors = get_objected_colors() + color_value = colors["delete-btn-bg"] + color = color_value.get_qcolor() + + return paint_image_with_color(src_image, color) diff --git a/openpype/tools/utils/models.py b/openpype/tools/utils/models.py index df3eee41a2..74d6c304c2 100644 --- a/openpype/tools/utils/models.py +++ b/openpype/tools/utils/models.py @@ -3,9 +3,6 @@ import logging import Qt from Qt import QtCore, QtGui -from avalon.vendor import qtawesome -from avalon import style, io -from . import lib from .constants import ( PROJECT_IS_ACTIVE_ROLE, PROJECT_NAME_ROLE,