Skip to content
This repository was archived by the owner on Oct 10, 2024. It is now read-only.

Commit 235785b

Browse files
committed
master merge fixes
1 parent c64ef2b commit 235785b

File tree

8 files changed

+1223
-202
lines changed

8 files changed

+1223
-202
lines changed

avalon/pipeline.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -978,9 +978,6 @@ def update_current_task(task=None, asset=None, app=None):
978978
"type": "asset"})
979979
assert asset_document, "Asset must exist"
980980
changed["AVALON_SILO"] = asset_document.get("silo") or ""
981-
parents = asset_document["data"]["parents"]
982-
hierarchy = os.path.sep.join(parents) or ""
983-
changed['AVALON_HIERARCHY'] = hierarchy
984981

985982
# Compute work directory (with the temporary changed session so far)
986983
project = io.find_one({"type": "project"},
@@ -995,10 +992,8 @@ def update_current_task(task=None, asset=None, app=None):
995992
if not os.path.exists(workdir):
996993
os.makedirs(workdir)
997994

998-
parents = asset_document['data'].get('parents', [])
999-
hierarchy = ""
1000-
if len(parents) > 0:
1001-
hierarchy = os.path.sep.join(parents)
995+
parents = asset_document["data"].get("parents") or []
996+
hierarchy = os.path.sep.join(parents) or ""
1002997
changed['AVALON_HIERARCHY'] = hierarchy
1003998

1004999
# Update the full session in one go to avoid half updates

avalon/tools/contextmanager/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def show(parent=None):
226226

227227
with lib.application():
228228
window = App(parent)
229-
window.show()
230229
window.setStyleSheet(style.load_stylesheet())
230+
window.show()
231231

232232
module.window = window

avalon/tools/creator/app.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,6 @@ def _on_data_changed(self):
362362
else:
363363
subset.as_new()
364364

365-
# Indicate subset existence
366-
if not subset_name:
367-
subset.as_empty()
368-
elif subset_name in existed_subsets:
369-
subset.as_exists()
370-
else:
371-
subset.as_new()
372-
373365
item.setData(ExistsRole, True)
374366

375367
else:
@@ -636,8 +628,8 @@ def show(debug=False, parent=None):
636628

637629
with lib.application():
638630
window = Window(parent)
631+
window.setStyleSheet(style.load_stylesheet())
639632
window.refresh()
640633
window.show()
641-
window.setStyleSheet(style.load_stylesheet())
642634

643635
module.window = window

avalon/tools/loader/app.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def show(debug=False, parent=None, use_context=False):
492492
module.window.refresh()
493493
return
494494
except RuntimeError as e:
495-
if not str(e).rstrip().endswith("already deleted."):
495+
if not e.message.rstrip().endswith("already deleted."):
496496
raise
497497

498498
# Garbage collected
@@ -502,7 +502,12 @@ def show(debug=False, parent=None, use_context=False):
502502
import traceback
503503
sys.excepthook = lambda typ, val, tb: traceback.print_last()
504504

505-
with lib.application():
505+
io.install()
506+
507+
any_project = next(
508+
project for project in io.projects()
509+
if project.get("active", True) is not False
510+
)
506511

507512
api.Session["AVALON_PROJECT"] = any_project["name"]
508513
module.project = any_project["name"]
@@ -516,7 +521,6 @@ def show(debug=False, parent=None, use_context=False):
516521
window = Window(parent)
517522
window.setStyleSheet(style.load_stylesheet())
518523
window.show()
519-
window.setStyleSheet(style.load_stylesheet())
520524

521525
if use_context:
522526
context = {"asset": api.Session["AVALON_ASSET"]}

avalon/tools/loader/delegates.py

Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
from datetime import datetime
33
import logging
44

5-
from ...vendor.Qt import QtWidgets
5+
from ...vendor.Qt import QtWidgets, QtGui, QtCore
6+
from ...vendor import Qt
7+
from ..models import AssetModel
68

79
log = logging.getLogger(__name__)
810

@@ -100,3 +102,149 @@ class PrettyTimeDelegate(QtWidgets.QStyledItemDelegate):
100102

101103
def displayText(self, value, locale):
102104
return pretty_timestamp(value)
105+
106+
107+
class AssetDelegate(QtWidgets.QItemDelegate):
108+
bar_height = 3
109+
110+
def sizeHint(self, option, index):
111+
result = super(AssetDelegate, self).sizeHint(option, index)
112+
height = result.height()
113+
result.setHeight(height + self.bar_height)
114+
115+
return result
116+
117+
def paint(self, painter, option, index):
118+
painter.save()
119+
120+
item_rect = QtCore.QRect(option.rect)
121+
item_rect.setHeight(option.rect.height() - self.bar_height)
122+
123+
subset_colors = index.data(AssetModel.subsetColorsRole)
124+
subset_colors_width = 0
125+
if subset_colors:
126+
subset_colors_width = option.rect.width()/len(subset_colors)
127+
128+
subset_rects = []
129+
counter = 0
130+
for subset_c in subset_colors:
131+
new_color = None
132+
new_rect = None
133+
if subset_c:
134+
new_color = QtGui.QColor(*subset_c)
135+
136+
new_rect = QtCore.QRect(
137+
option.rect.left() + (counter * subset_colors_width),
138+
option.rect.top() + (option.rect.height()-self.bar_height),
139+
subset_colors_width,
140+
self.bar_height
141+
)
142+
subset_rects.append((new_color, new_rect))
143+
counter += 1
144+
145+
# Background
146+
bg_color = QtGui.QColor(60, 60, 60)
147+
if option.state & QtWidgets.QStyle.State_Selected:
148+
if len(subset_colors) == 0:
149+
item_rect.setTop(item_rect.top() + (self.bar_height / 2))
150+
if option.state & QtWidgets.QStyle.State_MouseOver:
151+
bg_color.setRgb(70, 70, 70)
152+
else:
153+
item_rect.setTop(item_rect.top() + (self.bar_height / 2))
154+
if option.state & QtWidgets.QStyle.State_MouseOver:
155+
bg_color.setAlpha(100)
156+
else:
157+
bg_color.setAlpha(0)
158+
159+
# # -- When not needed to do a rounded corners (easier and without painter restore):
160+
# painter.fillRect(
161+
# item_rect,
162+
# QtGui.QBrush(bg_color)
163+
# )
164+
pen = painter.pen()
165+
pen.setStyle(QtCore.Qt.NoPen)
166+
pen.setWidth(0)
167+
painter.setPen(pen)
168+
painter.setBrush(QtGui.QBrush(bg_color))
169+
painter.drawRoundedRect(option.rect, 3, 3)
170+
171+
if option.state & QtWidgets.QStyle.State_Selected:
172+
for color, subset_rect in subset_rects:
173+
if not color or not subset_rect:
174+
continue
175+
painter.fillRect(subset_rect, QtGui.QBrush(color))
176+
177+
painter.restore()
178+
painter.save()
179+
180+
# Icon
181+
icon_index = index.model().index(
182+
index.row(), index.column(), index.parent()
183+
)
184+
# - Default icon_rect if not icon
185+
icon_rect = QtCore.QRect(
186+
item_rect.left(),
187+
item_rect.top(),
188+
# To make sure it's same size all the time
189+
option.rect.height() - self.bar_height,
190+
option.rect.height() - self.bar_height
191+
)
192+
icon = index.model().data(icon_index, QtCore.Qt.DecorationRole)
193+
194+
if icon:
195+
margin = 0
196+
mode = QtGui.QIcon.Normal
197+
198+
if not (option.state & QtWidgets.QStyle.State_Enabled):
199+
mode = QtGui.QIcon.Disabled
200+
elif option.state & QtWidgets.QStyle.State_Selected:
201+
mode = QtGui.QIcon.Selected
202+
203+
if isinstance(icon, QtGui.QPixmap):
204+
icon = QtGui.QIcon(icon)
205+
option.decorationSize = icon.size() / icon.devicePixelRatio()
206+
207+
elif isinstance(icon, QtGui.QColor):
208+
pixmap = QtGui.QPixmap(option.decorationSize)
209+
pixmap.fill(icon)
210+
icon = QtGui.QIcon(pixmap)
211+
212+
elif isinstance(icon, QtGui.QImage):
213+
icon = QtGui.QIcon(QtGui.QPixmap.fromImage(icon))
214+
option.decorationSize = icon.size() / icon.devicePixelRatio()
215+
216+
elif isinstance(icon, QtGui.QIcon):
217+
state = QtGui.QIcon.Off
218+
if option.state & QtWidgets.QStyle.State_Open:
219+
state = QtGui.QIcon.On
220+
actualSize = option.icon.actualSize(
221+
option.decorationSize, mode, state
222+
)
223+
option.decorationSize = QtCore.QSize(
224+
min(option.decorationSize.width(), actualSize.width()),
225+
min(option.decorationSize.height(), actualSize.height())
226+
)
227+
228+
state = QtGui.QIcon.Off
229+
if option.state & QtWidgets.QStyle.State_Open:
230+
state = QtGui.QIcon.On
231+
232+
icon.paint(
233+
painter, icon_rect,
234+
QtCore.Qt.AlignLeft , mode, state
235+
)
236+
237+
# Text
238+
text_rect = QtCore.QRect(
239+
icon_rect.left() + icon_rect.width() + 2,
240+
item_rect.top(),
241+
item_rect.width(),
242+
item_rect.height()
243+
)
244+
245+
painter.drawText(
246+
text_rect, QtCore.Qt.AlignVCenter,
247+
index.data(QtCore.Qt.DisplayRole)
248+
)
249+
250+
painter.restore()

0 commit comments

Comments
 (0)