mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 13:52:15 +01:00
added icons from creators next to instances
This commit is contained in:
parent
065f582579
commit
0c4f604b4c
5 changed files with 94 additions and 31 deletions
|
|
@ -777,7 +777,9 @@ QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
|
|||
#PublishCommentInput {
|
||||
padding: 0.2em;
|
||||
}
|
||||
|
||||
#FamilyIconLabel {
|
||||
font-size: 14pt;
|
||||
}
|
||||
#ArrowBtn, #ArrowBtn:disabled, #ArrowBtn:hover {
|
||||
background: transparent;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from Qt import QtCore
|
|||
|
||||
# ID of context item in instance view
|
||||
CONTEXT_ID = "context"
|
||||
CONTEXT_LABEL = "Publish options"
|
||||
CONTEXT_LABEL = "Options"
|
||||
|
||||
# Allowed symbols for subset name (and variant)
|
||||
# - characters, numbers, unsercore and dash
|
||||
|
|
|
|||
|
|
@ -563,6 +563,12 @@ class PublisherController:
|
|||
))
|
||||
return output
|
||||
|
||||
def get_icon_for_family(self, family):
|
||||
creator = self.creators.get(family)
|
||||
if creator is not None:
|
||||
return creator.get_icon()
|
||||
return None
|
||||
|
||||
def create(self, family, subset_name, instance_data, options):
|
||||
# QUESTION Force to return instances or call `list_instances` on each
|
||||
# creation? (`list_instances` may slow down...)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ from openpype.widgets.nice_checkbox import NiceCheckbox
|
|||
from .widgets import (
|
||||
AbstractInstanceView,
|
||||
ContextWarningLabel,
|
||||
ClickableFrame
|
||||
ClickableFrame,
|
||||
IconValuePixmapLabel,
|
||||
TransparentPixmapLabel
|
||||
)
|
||||
from ..constants import (
|
||||
CONTEXT_ID,
|
||||
|
|
@ -15,32 +17,11 @@ from ..constants import (
|
|||
)
|
||||
|
||||
|
||||
class FamilyLabel(QtWidgets.QWidget):
|
||||
def __init__(self, family, parent):
|
||||
super(FamilyLabel, self).__init__(parent)
|
||||
|
||||
label_widget = QtWidgets.QLabel(family, self)
|
||||
|
||||
line_widget = QtWidgets.QWidget(self)
|
||||
line_widget.setObjectName("Separator")
|
||||
line_widget.setMinimumHeight(2)
|
||||
line_widget.setMaximumHeight(2)
|
||||
|
||||
layout = QtWidgets.QHBoxLayout(self)
|
||||
layout.setAlignment(QtCore.Qt.AlignCenter)
|
||||
layout.setSpacing(10)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.addWidget(label_widget, 0)
|
||||
layout.addWidget(line_widget, 1)
|
||||
|
||||
self._label_widget = label_widget
|
||||
|
||||
|
||||
class FamilyWidget(QtWidgets.QWidget):
|
||||
selected = QtCore.Signal(str, str)
|
||||
active_changed = QtCore.Signal()
|
||||
|
||||
def __init__(self, family, parent):
|
||||
def __init__(self, family, family_icon, parent):
|
||||
super(FamilyWidget, self).__init__(parent)
|
||||
|
||||
label_widget = QtWidgets.QLabel(family, self)
|
||||
|
|
@ -61,6 +42,9 @@ class FamilyWidget(QtWidgets.QWidget):
|
|||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.addLayout(label_layout, 0)
|
||||
|
||||
self._family = family
|
||||
self._family_icon = family_icon
|
||||
|
||||
self._widgets_by_id = {}
|
||||
|
||||
self._label_widget = label_widget
|
||||
|
|
@ -98,7 +82,9 @@ class FamilyWidget(QtWidgets.QWidget):
|
|||
widget = self._widgets_by_id[instance.id]
|
||||
widget.update_instance(instance)
|
||||
else:
|
||||
widget = InstanceCardWidget(instance, self)
|
||||
widget = InstanceCardWidget(
|
||||
instance, self._family_icon, self
|
||||
)
|
||||
widget.selected.connect(self.selected)
|
||||
widget.active_changed.connect(self.active_changed)
|
||||
self._widgets_by_id[instance.id] = widget
|
||||
|
|
@ -135,7 +121,7 @@ class ContextCardWidget(CardWidget):
|
|||
self._id = CONTEXT_ID
|
||||
self._family = ""
|
||||
|
||||
icon_widget = QtWidgets.QLabel(self)
|
||||
icon_widget = TransparentPixmapLabel(self)
|
||||
|
||||
label_widget = QtWidgets.QLabel(CONTEXT_LABEL, self)
|
||||
|
||||
|
|
@ -155,18 +141,19 @@ class ContextCardWidget(CardWidget):
|
|||
class InstanceCardWidget(CardWidget):
|
||||
active_changed = QtCore.Signal()
|
||||
|
||||
def __init__(self, instance, parent):
|
||||
def __init__(self, instance, family_icon, parent):
|
||||
super(InstanceCardWidget, self).__init__(parent)
|
||||
|
||||
self._id = instance.id
|
||||
self._family = instance.data["family"]
|
||||
self._family_icon = family_icon
|
||||
|
||||
self.instance = instance
|
||||
|
||||
icon_widget = QtWidgets.QLabel(self)
|
||||
icon_widget = IconValuePixmapLabel(family_icon, self)
|
||||
|
||||
icon_layout = QtWidgets.QHBoxLayout()
|
||||
icon_layout.setContentsMargins(5, 5, 5, 5)
|
||||
icon_layout.setContentsMargins(10, 5, 5, 5)
|
||||
icon_layout.addWidget(icon_widget)
|
||||
|
||||
label_widget = QtWidgets.QLabel(instance.data["subset"], self)
|
||||
|
|
@ -334,7 +321,10 @@ class InstanceCardView(AbstractInstanceView):
|
|||
widget_idx = 1
|
||||
for family in sorted_families:
|
||||
if family not in self._widgets_by_family:
|
||||
family_widget = FamilyWidget(family, self._content_widget)
|
||||
family_icon = self.controller.get_icon_for_family(family)
|
||||
family_widget = FamilyWidget(
|
||||
family, family_icon, self._content_widget
|
||||
)
|
||||
family_widget.active_changed.connect(self._on_active_changed)
|
||||
family_widget.selected.connect(self._on_widget_selection)
|
||||
self._content_layout.insertWidget(widget_idx, family_widget)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
import os
|
||||
import re
|
||||
import copy
|
||||
import collections
|
||||
from Qt import QtWidgets, QtCore, QtGui
|
||||
|
||||
from avalon.vendor import qtawesome
|
||||
|
||||
from openpype.widgets.attribute_defs import create_widget_for_attr_def
|
||||
from openpype.tools.flickcharm import FlickCharm
|
||||
|
||||
|
|
@ -37,6 +40,68 @@ class PixmapLabel(QtWidgets.QLabel):
|
|||
super(PixmapLabel, self).resizeEvent(event)
|
||||
|
||||
|
||||
class TransparentPixmapLabel(QtWidgets.QLabel):
|
||||
"""Label resizing to width and height of font."""
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(TransparentPixmapLabel, self).__init__(*args, **kwargs)
|
||||
|
||||
self.setObjectName("FamilyIconLabel")
|
||||
|
||||
def resizeEvent(self, event):
|
||||
size = self.fontMetrics().height()
|
||||
size += size % 2
|
||||
pix = QtGui.QPixmap(size, size)
|
||||
pix.fill(QtCore.Qt.transparent)
|
||||
self.setPixmap(pix)
|
||||
super(TransparentPixmapLabel, self).resizeEvent(event)
|
||||
|
||||
|
||||
class IconValuePixmapLabel(PixmapLabel):
|
||||
"""Label resizing to width and height of font."""
|
||||
fa_prefixes = ["", "fa."]
|
||||
default_size = 200
|
||||
|
||||
def __init__(self, icon_def, parent):
|
||||
source_pixmap = self._parse_icon_def(icon_def)
|
||||
|
||||
super(IconValuePixmapLabel, self).__init__(source_pixmap, parent)
|
||||
|
||||
self.setObjectName("FamilyIconLabel")
|
||||
|
||||
def _default_pixmap(self):
|
||||
pix = QtGui.QPixmap(1, 1)
|
||||
pix.fill(QtCore.Qt.transparent)
|
||||
return pix
|
||||
|
||||
def _parse_icon_def(self, icon_def):
|
||||
if not icon_def:
|
||||
return self._default_pixmap()
|
||||
|
||||
if isinstance(icon_def, QtGui.QPixmap):
|
||||
return icon_def
|
||||
|
||||
if isinstance(icon_def, QtGui.QIcon):
|
||||
return icon_def.pixmap(self.default_size, self.default_size)
|
||||
|
||||
try:
|
||||
if os.path.exists(icon_def):
|
||||
return QtGui.QPixmap(icon_def)
|
||||
except Exception:
|
||||
# TODO logging
|
||||
pass
|
||||
|
||||
for prefix in self.fa_prefixes:
|
||||
try:
|
||||
icon_name = "{}{}".format(prefix, icon_def)
|
||||
icon = qtawesome.icon(icon_name, color="white")
|
||||
return icon.pixmap(self.default_size, self.default_size)
|
||||
except Exception:
|
||||
# TODO logging
|
||||
continue
|
||||
|
||||
return self._default_pixmap()
|
||||
|
||||
|
||||
class IconButton(QtWidgets.QPushButton):
|
||||
"""PushButton with icon and size of font.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue