forked from shotgunsoftware/tk-multi-loader2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_entity.py
More file actions
135 lines (119 loc) · 5.02 KB
/
Copy pathmodel_entity.py
File metadata and controls
135 lines (119 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Copyright (c) 2015 Shotgun Software Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
# Source Code License included in this distribution package. See LICENSE.
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.
import sgtk
from sgtk.platform.qt import QtCore, QtGui
# import the shotgun_model module from the shotgun utils framework
shotgun_model = sgtk.platform.import_framework(
"tk-framework-shotgunutils", "shotgun_model"
)
ShotgunModel = shotgun_model.ShotgunModel
class SgEntityModel(ShotgunModel):
"""
This model represents the data which is displayed inside one of the treeview tabs
on the left hand side.
"""
def __init__(self, parent, entity_type, filters, hierarchy, bg_task_manager):
"""
Constructor
"""
# folder icon
self._default_icon = QtGui.QIcon(QtGui.QPixmap(":/res/icon_Folder.png"))
# shotgun entity icons
self._entity_icons = {}
self._entity_icons["Shot"] = QtGui.QIcon(
QtGui.QPixmap(":/res/icon_Shot_dark.png")
)
self._entity_icons["Asset"] = QtGui.QIcon(
QtGui.QPixmap(":/res/icon_Asset_dark.png")
)
self._entity_icons["EventLogEntry"] = QtGui.QIcon(
QtGui.QPixmap(":/res/icon_EventLogEntry_dark.png")
)
self._entity_icons["Group"] = QtGui.QIcon(
QtGui.QPixmap(":/res/icon_Group_dark.png")
)
self._entity_icons["HumanUser"] = QtGui.QIcon(
QtGui.QPixmap(":/res/icon_HumanUser_dark.png")
)
self._entity_icons["Note"] = QtGui.QIcon(
QtGui.QPixmap(":/res/icon_Note_dark.png")
)
self._entity_icons["Project"] = QtGui.QIcon(
QtGui.QPixmap(":/res/icon_Project_dark.png")
)
self._entity_icons["Sequence"] = QtGui.QIcon(
QtGui.QPixmap(":/res/icon_Sequence_dark.png")
)
self._entity_icons["Task"] = QtGui.QIcon(
QtGui.QPixmap(":/res/icon_Task_dark.png")
)
self._entity_icons["Ticket"] = QtGui.QIcon(
QtGui.QPixmap(":/res/icon_Ticket_dark.png")
)
self._entity_icons["Version"] = QtGui.QIcon(
QtGui.QPixmap(":/res/icon_Version_dark.png")
)
ShotgunModel.__init__(
self,
parent,
download_thumbs=False,
schema_generation=4,
bg_load_thumbs=True,
bg_task_manager=bg_task_manager,
)
fields = ["image", "sg_status_list", "description"]
self._load_data(entity_type, filters, hierarchy, fields)
############################################################################################
# public methods
def async_refresh(self):
"""
Trigger an asynchronous refresh of the model
"""
self._refresh_data()
############################################################################################
# subclassed methods
def _populate_default_thumbnail(self, item):
"""
Whenever an item is constructed, this methods is called. It allows subclasses to intercept
the construction of a QStandardItem and add additional metadata or make other changes
that may be useful. Nothing needs to be returned.
:param item: QStandardItem that is about to be added to the model. This has been primed
with the standard settings that the ShotgunModel handles.
:param sg_data: Shotgun data dictionary that was received from Shotgun given the fields
and other settings specified in load_data()
"""
found_icon = False
# get the associated field data with this node
field_data = shotgun_model.get_sanitized_data(
item, self.SG_ASSOCIATED_FIELD_ROLE
)
# get the full sg data for this node (leafs only)
sg_data = shotgun_model.get_sg_data(item)
# {'name': 'sg_sequence', 'value': {'type': 'Sequence', 'id': 11, 'name': 'bunny_080'}}
field_value = field_data["value"]
if (
isinstance(field_value, dict)
and "name" in field_value
and "type" in field_value
):
# this is an intermediate node which is an entity type link
if field_value.get("type") in self._entity_icons:
# use sg icon!
item.setIcon(self._entity_icons[field_value.get("type")])
found_icon = True
elif sg_data:
# this is a leaf node!
if sg_data.get("type") in self._entity_icons:
# use sg icon!
item.setIcon(self._entity_icons[sg_data.get("type")])
found_icon = True
# for all items where we didn't find the icon, fall back onto the default
if not found_icon:
item.setIcon(self._default_icon)