folder and task icon is not set on their items

This commit is contained in:
iLLiCiTiT 2024-06-02 15:11:15 +02:00
parent 8f83fa5d43
commit 22b6663850
3 changed files with 37 additions and 34 deletions

View file

@ -5,7 +5,6 @@ from abc import ABCMeta, abstractmethod
import ayon_api
import six
from ayon_core.style import get_default_entity_icon_color
from ayon_core.lib import NestedCacheItem
HIERARCHY_MODEL_SENDER = "hierarchy.model"
@ -31,11 +30,10 @@ class FolderItem:
path (str): Folder path.
folder_type (str): Type of folder.
label (Union[str, None]): Folder label.
icon (Union[dict[str, Any], None]): Icon definition.
"""
def __init__(
self, entity_id, parent_id, name, path, folder_type, label, icon
self, entity_id, parent_id, name, path, folder_type, label
):
self.entity_id = entity_id
self.parent_id = parent_id
@ -43,13 +41,6 @@ class FolderItem:
self.path = path
self.folder_type = folder_type
self.label = label or name
if not icon:
icon = {
"type": "awesome-font",
"name": "fa.folder",
"color": get_default_entity_icon_color()
}
self.icon = icon
def to_data(self):
"""Converts folder item to data.
@ -65,7 +56,6 @@ class FolderItem:
"path": self.path,
"folder_type": self.folder_type,
"label": self.label,
"icon": self.icon,
}
@classmethod
@ -95,23 +85,15 @@ class TaskItem:
name (str): Name of task.
task_type (str): Type of task.
parent_id (str): Parent folder id.
icon (Union[dict[str, Any], None]): Icon definitions.
"""
def __init__(
self, task_id, name, task_type, parent_id, icon
self, task_id, name, task_type, parent_id
):
self.task_id = task_id
self.name = name
self.task_type = task_type
self.parent_id = parent_id
if icon is None:
icon = {
"type": "awesome-font",
"name": "fa.male",
"color": get_default_entity_icon_color()
}
self.icon = icon
self._label = None
@ -149,7 +131,6 @@ class TaskItem:
"name": self.name,
"parent_id": self.parent_id,
"task_type": self.task_type,
"icon": self.icon,
}
@classmethod
@ -180,8 +161,7 @@ def _get_task_items_from_tasks(tasks):
task["id"],
task["name"],
task["type"],
folder_id,
None
folder_id
))
return output
@ -197,8 +177,7 @@ def _get_folder_item_from_hierarchy_item(item):
name,
path,
item["folderType"],
item["label"],
None,
item["label"]
)
@ -210,8 +189,7 @@ def _get_folder_item_from_entity(entity):
name,
entity["path"],
entity["folderType"],
entity["label"] or name,
None,
entity["label"] or name
)

View file

@ -3,6 +3,7 @@ import collections
from qtpy import QtWidgets, QtGui, QtCore
from ayon_core.lib.events import QueuedEventSystem
from ayon_core.style import get_default_entity_icon_color
from ayon_core.tools.common_models import (
HierarchyModel,
HierarchyExpectedSelection,
@ -25,8 +26,9 @@ class FoldersQtModel(QtGui.QStandardItemModel):
Args:
controller (AbstractWorkfilesFrontend): The control object.
"""
"""
_default_folder_icon = None
refreshed = QtCore.Signal()
def __init__(self, controller):
@ -149,6 +151,16 @@ class FoldersQtModel(QtGui.QStandardItemModel):
thread.refresh_finished.connect(self._on_refresh_thread)
thread.start()
@classmethod
def _get_default_folder_icon(cls):
if cls._default_folder_icon is None:
cls._default_folder_icon = get_qt_icon({
"type": "awesome-font",
"name": "fa.folder",
"color": get_default_entity_icon_color()
})
return cls._default_folder_icon
def _on_refresh_thread(self, thread_id):
"""Callback when refresh thread is finished.
@ -179,9 +191,9 @@ class FoldersQtModel(QtGui.QStandardItemModel):
Args:
item (QtGui.QStandardItem): Item to fill data.
folder_item (FolderItem): Folder item.
"""
icon = get_qt_icon(folder_item.icon)
"""
icon = self._get_default_folder_icon()
item.setData(folder_item.entity_id, FOLDER_ID_ROLE)
item.setData(folder_item.name, FOLDER_NAME_ROLE)
item.setData(folder_item.path, FOLDER_PATH_ROLE)

View file

@ -1,6 +1,9 @@
from qtpy import QtWidgets, QtGui, QtCore
from ayon_core.style import get_disabled_entity_icon_color
from ayon_core.style import (
get_disabled_entity_icon_color,
get_default_entity_icon_color,
)
from .views import DeselectableTreeView
from .lib import RefreshThread, get_qt_icon
@ -17,8 +20,9 @@ class TasksQtModel(QtGui.QStandardItemModel):
Args:
controller (AbstractWorkfilesFrontend): The control object.
"""
"""
_default_task_icon = None
refreshed = QtCore.Signal()
def __init__(self, controller):
@ -185,6 +189,16 @@ class TasksQtModel(QtGui.QStandardItemModel):
thread.refresh_finished.connect(self._on_refresh_thread)
thread.start()
@classmethod
def _get_default_task_icon(cls):
if cls._default_task_icon is None:
cls._default_task_icon = get_qt_icon({
"type": "awesome-font",
"name": "fa.male",
"color": get_default_entity_icon_color()
})
return cls._default_task_icon
def _fill_data_from_thread(self, thread):
task_items = thread.get_result()
# Task items are refreshed
@ -209,8 +223,7 @@ class TasksQtModel(QtGui.QStandardItemModel):
new_items.append(item)
self._items_by_name[name] = item
# TODO cache locally
icon = get_qt_icon(task_item.icon)
icon = self._get_default_task_icon()
item.setData(task_item.label, QtCore.Qt.DisplayRole)
item.setData(name, ITEM_NAME_ROLE)
item.setData(task_item.id, ITEM_ID_ROLE)