added warning image to resources and utils function to load it

This commit is contained in:
Jakub Trllo 2022-01-26 11:18:22 +01:00
parent 716bd5b492
commit 6a03efa7e6
8 changed files with 36 additions and 53 deletions

View file

@ -14,6 +14,15 @@ def get_resource(*args):
return os.path.normpath(os.path.join(RESOURCES_DIR, *args)) return os.path.normpath(os.path.join(RESOURCES_DIR, *args))
def get_image_path(*args):
"""Helper function to get images.
Args:
*<str>: Filepath part items.
"""
return get_resource("images", *args)
def get_liberation_font_path(bold=False, italic=False): def get_liberation_font_path(bold=False, italic=False):
font_name = "LiberationSans" font_name = "LiberationSans"
suffix = "" suffix = ""

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View file

@ -1,8 +1,8 @@
import os import os
from Qt import QtCore, QtGui from Qt import QtCore, QtGui
from openpype.style import get_objected_colors
from avalon.vendor import qtawesome from avalon.vendor import qtawesome
from openpype.tools.utils import paint_image_with_color
class ResourceCache: class ResourceCache:
@ -91,17 +91,6 @@ class ResourceCache:
icon.addPixmap(disabled_pix, QtGui.QIcon.Disabled, QtGui.QIcon.Off) icon.addPixmap(disabled_pix, QtGui.QIcon.Disabled, QtGui.QIcon.Off)
return icon 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(): def get_remove_image():
image_path = os.path.join( image_path = os.path.join(
@ -110,36 +99,3 @@ def get_remove_image():
"bin.png" "bin.png"
) )
return QtGui.QImage(image_path) 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

View file

@ -4,14 +4,16 @@ from .constants import (
NAME_ALLOWED_SYMBOLS, NAME_ALLOWED_SYMBOLS,
NAME_REGEX NAME_REGEX
) )
from .style import ResourceCache
from openpype.lib import ( from openpype.lib import (
create_project, create_project,
PROJECT_NAME_ALLOWED_SYMBOLS, PROJECT_NAME_ALLOWED_SYMBOLS,
PROJECT_NAME_REGEX PROJECT_NAME_REGEX
) )
from openpype.style import load_stylesheet 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 avalon.api import AvalonMongoDB
from Qt import QtWidgets, QtCore, QtGui from Qt import QtWidgets, QtCore, QtGui
@ -338,7 +340,7 @@ class ConfirmProjectDeletion(QtWidgets.QDialog):
top_widget = QtWidgets.QWidget(self) top_widget = QtWidgets.QWidget(self)
warning_pixmap = ResourceCache.get_warning_pixmap() warning_pixmap = get_warning_pixmap()
warning_icon_label = PixmapLabel(warning_pixmap, top_widget) warning_icon_label = PixmapLabel(warning_pixmap, top_widget)
message_label = QtWidgets.QLabel(top_widget) message_label = QtWidgets.QLabel(top_widget)

View file

@ -8,7 +8,8 @@ from .widgets import (
from .error_dialog import ErrorMessageBox from .error_dialog import ErrorMessageBox
from .lib import ( from .lib import (
WrappedCallbackItem, WrappedCallbackItem,
paint_image_with_color paint_image_with_color,
get_warning_pixmap
) )
@ -22,4 +23,5 @@ __all__ = (
"WrappedCallbackItem", "WrappedCallbackItem",
"paint_image_with_color", "paint_image_with_color",
"get_warning_pixmap",
) )

View file

@ -7,7 +7,6 @@ import Qt
from Qt import QtWidgets, QtGui, QtCore from Qt import QtWidgets, QtGui, QtCore
from avalon.lib import HeroVersionType from avalon.lib import HeroVersionType
from openpype.style import get_objected_colors
from .models import TreeModel from .models import TreeModel
from . import lib from . import lib

View file

@ -14,6 +14,8 @@ from openpype.api import (
Logger Logger
) )
from openpype.lib import filter_profiles from openpype.lib import filter_profiles
from openpype.style import get_objected_colors
from openpype.resources import get_image_path
def center_window(window): def center_window(window):
@ -670,3 +672,19 @@ class WrappedCallbackItem:
finally: finally:
self._done = True 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)

View file

@ -3,9 +3,6 @@ import logging
import Qt import Qt
from Qt import QtCore, QtGui from Qt import QtCore, QtGui
from avalon.vendor import qtawesome
from avalon import style, io
from . import lib
from .constants import ( from .constants import (
PROJECT_IS_ACTIVE_ROLE, PROJECT_IS_ACTIVE_ROLE,
PROJECT_NAME_ROLE, PROJECT_NAME_ROLE,