mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Optimize use of cache by allowing to copy only the part of the data you need
This commit is contained in:
parent
15105b36d9
commit
24d9e5017d
10 changed files with 30 additions and 21 deletions
|
|
@ -82,11 +82,25 @@ def _convert_color_values_to_objects(value):
|
|||
return parse_color(value)
|
||||
|
||||
|
||||
def get_objected_colors():
|
||||
def get_objected_colors(*keys):
|
||||
"""Colors parsed from stylesheet data into color definitions.
|
||||
|
||||
You can pass multiple arguments to get a key from the data dict's colors.
|
||||
Because this functions returns a deep copy of the cached data this allows
|
||||
a much smaller dataset to be copied and thus result in a faster function.
|
||||
It is however a micro-optimization in the area of 0.001s and smaller.
|
||||
|
||||
For example:
|
||||
>>> get_colors_data() # copy of full colors dict
|
||||
>>> get_colors_data("font")
|
||||
>>> get_colors_data("loader", "asset-view")
|
||||
|
||||
Args:
|
||||
*keys: Each key argument will return a key nested deeper in the
|
||||
objected colors data.
|
||||
|
||||
Returns:
|
||||
dict: Parsed color objects by keys in data.
|
||||
Any: Parsed color objects by keys in data.
|
||||
"""
|
||||
if _Cache.objected_colors is None:
|
||||
colors_data = get_colors_data()
|
||||
|
|
@ -96,7 +110,10 @@ def get_objected_colors():
|
|||
|
||||
_Cache.objected_colors = output
|
||||
|
||||
return copy.deepcopy(_Cache.objected_colors)
|
||||
output = _Cache.objected_colors
|
||||
for key in keys:
|
||||
output = output[key]
|
||||
return copy.deepcopy(output)
|
||||
|
||||
|
||||
def _load_stylesheet():
|
||||
|
|
|
|||
|
|
@ -158,8 +158,7 @@ class BorderedLabelWidget(QtWidgets.QFrame):
|
|||
"""
|
||||
def __init__(self, label, parent):
|
||||
super(BorderedLabelWidget, self).__init__(parent)
|
||||
colors_data = get_objected_colors()
|
||||
color_value = colors_data.get("border")
|
||||
color_value = get_objected_colors("border")
|
||||
color = None
|
||||
if color_value:
|
||||
color = color_value.get_qcolor()
|
||||
|
|
|
|||
|
|
@ -54,8 +54,7 @@ class ListItemDelegate(QtWidgets.QStyledItemDelegate):
|
|||
def __init__(self, parent):
|
||||
super(ListItemDelegate, self).__init__(parent)
|
||||
|
||||
colors_data = get_objected_colors()
|
||||
group_color_info = colors_data["publisher"]["list-view-group"]
|
||||
colors_data = get_objected_colors("publisher", "list-view-group")
|
||||
|
||||
self._group_colors = {
|
||||
key: value.get_qcolor()
|
||||
|
|
|
|||
|
|
@ -323,7 +323,7 @@ class SettingsToolBtn(ImageButton):
|
|||
@classmethod
|
||||
def _get_icon_type(cls, btn_type):
|
||||
if btn_type not in cls._cached_icons:
|
||||
settings_colors = get_objected_colors()["settings"]
|
||||
settings_colors = get_objected_colors("settings")
|
||||
normal_color = settings_colors["image-btn"].get_qcolor()
|
||||
hover_color = settings_colors["image-btn-hover"].get_qcolor()
|
||||
disabled_color = settings_colors["image-btn-disabled"].get_qcolor()
|
||||
|
|
@ -789,8 +789,7 @@ class ProjectModel(QtGui.QStandardItemModel):
|
|||
self._items_by_name = {}
|
||||
self._versions_by_project = {}
|
||||
|
||||
colors = get_objected_colors()
|
||||
font_color = colors["font"].get_qcolor()
|
||||
font_color = get_objected_colors("font").get_qcolor()
|
||||
font_color.setAlpha(67)
|
||||
self._version_font_color = font_color
|
||||
self._current_version = get_openpype_version()
|
||||
|
|
|
|||
|
|
@ -144,8 +144,7 @@ class VersionUpdateDialog(QtWidgets.QDialog):
|
|||
"gifts.png"
|
||||
)
|
||||
src_image = QtGui.QImage(image_path)
|
||||
colors = style.get_objected_colors()
|
||||
color_value = colors["font"]
|
||||
color_value = style.get_objected_colors("font")
|
||||
|
||||
return paint_image_with_color(
|
||||
src_image,
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ class UnderlinesAssetDelegate(QtWidgets.QItemDelegate):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(UnderlinesAssetDelegate, self).__init__(*args, **kwargs)
|
||||
asset_view_colors = get_objected_colors()["loader"]["asset-view"]
|
||||
asset_view_colors = get_objected_colors("loader", "asset-view")
|
||||
self._selected_color = (
|
||||
asset_view_colors["selected"].get_qcolor()
|
||||
)
|
||||
|
|
|
|||
|
|
@ -822,8 +822,6 @@ def get_warning_pixmap(color=None):
|
|||
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()
|
||||
color = get_objected_colors("delete-btn-bg").get_qcolor()
|
||||
|
||||
return paint_image_with_color(src_image, color)
|
||||
|
|
|
|||
|
|
@ -14,8 +14,7 @@ class CloseButton(QtWidgets.QFrame):
|
|||
|
||||
def __init__(self, parent):
|
||||
super(CloseButton, self).__init__(parent)
|
||||
colors = get_objected_colors()
|
||||
close_btn_color = colors["overlay-messages"]["close-btn"]
|
||||
close_btn_color = get_objected_colors("overlay-messages", "close-btn")
|
||||
self._color = close_btn_color.get_qcolor()
|
||||
self._mouse_pressed = False
|
||||
policy = QtWidgets.QSizePolicy(
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class PlaceholderLineEdit(QtWidgets.QLineEdit):
|
|||
# Change placeholder palette color
|
||||
if hasattr(QtGui.QPalette, "PlaceholderText"):
|
||||
filter_palette = self.palette()
|
||||
color_obj = get_objected_colors()["font"]
|
||||
color_obj = get_objected_colors("font")
|
||||
color = color_obj.get_qcolor()
|
||||
color.setAlpha(67)
|
||||
filter_palette.setColor(
|
||||
|
|
|
|||
|
|
@ -66,8 +66,7 @@ class NiceCheckbox(QtWidgets.QFrame):
|
|||
if cls._checked_bg_color is not None:
|
||||
return
|
||||
|
||||
colors_data = get_objected_colors()
|
||||
colors_info = colors_data["nice-checkbox"]
|
||||
colors_info = get_objected_colors("nice-checkbox")
|
||||
|
||||
cls._checked_bg_color = colors_info["bg-checked"].get_qcolor()
|
||||
cls._unchecked_bg_color = colors_info["bg-unchecked"].get_qcolor()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue