Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

NewPublisher: Groups work and enum multivalue #3501

Merged
merged 8 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion openpype/tools/publisher/widgets/card_view_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def update_instances(self, instances):
instances(list<CreatedInstance>): List of instances in
CreateContext.
"""

# Store instances by id and by subset name
instances_by_id = {}
instances_by_subset_name = collections.defaultdict(list)
Expand Down Expand Up @@ -142,6 +143,7 @@ def update_instances(self, instances):

class CardWidget(BaseClickableFrame):
"""Clickable card used as bigger button."""

selected = QtCore.Signal(str, str)
# Group identifier of card
# - this must be set because if send when mouse is released with card id
Expand Down Expand Up @@ -178,6 +180,7 @@ class ContextCardWidget(CardWidget):

Is not visually under group widget and is always at the top of card view.
"""

def __init__(self, parent):
super(ContextCardWidget, self).__init__(parent)

Expand All @@ -204,13 +207,14 @@ def __init__(self, parent):

class InstanceCardWidget(CardWidget):
"""Card widget representing instance."""

active_changed = QtCore.Signal()

def __init__(self, instance, group_icon, parent):
super(InstanceCardWidget, self).__init__(parent)

self._id = instance.id
self._group_identifier = instance.creator_label
self._group_identifier = instance.group_label
self._group_icon = group_icon

self.instance = instance
Expand Down
2 changes: 2 additions & 0 deletions openpype/tools/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .widgets import (
CustomTextComboBox,
PlaceholderLineEdit,
BaseClickableFrame,
ClickableFrame,
Expand Down Expand Up @@ -28,6 +29,7 @@


__all__ = (
"CustomTextComboBox",
"PlaceholderLineEdit",
"BaseClickableFrame",
"ClickableFrame",
Expand Down
22 changes: 22 additions & 0 deletions openpype/tools/utils/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@
log = logging.getLogger(__name__)


class CustomTextComboBox(QtWidgets.QComboBox):
"""Combobox which can have different text showed."""

def __init__(self, *args, **kwargs):
self._custom_text = None
super(CustomTextComboBox, self).__init__(*args, **kwargs)

def set_custom_text(self, text=None):
if self._custom_text != text:
self._custom_text = text
self.repaint()

def paintEvent(self, event):
painter = QtWidgets.QStylePainter(self)
option = QtWidgets.QStyleOptionComboBox()
self.initStyleOption(option)
if self._custom_text is not None:
option.currentText = self._custom_text
painter.drawComplexControl(QtWidgets.QStyle.CC_ComboBox, option)
painter.drawControl(QtWidgets.QStyle.CE_ComboBoxLabel, option)


class PlaceholderLineEdit(QtWidgets.QLineEdit):
"""Set placeholder color of QLineEdit in Qt 5.12 and higher."""
def __init__(self, *args, **kwargs):
Expand Down
23 changes: 20 additions & 3 deletions openpype/widgets/attribute_defs/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
UISeparatorDef,
UILabelDef
)
from openpype.tools.utils import CustomTextComboBox
from openpype.widgets.nice_checkbox import NiceCheckbox

from .files_widget import FilesWidget
Expand Down Expand Up @@ -369,8 +370,12 @@ def set_value(self, value, multivalue=False):


class EnumAttrWidget(_BaseAttrDefWidget):
def __init__(self, *args, **kwargs):
self._multivalue = False
super(EnumAttrWidget, self).__init__(*args, **kwargs)

def _ui_init(self):
input_widget = QtWidgets.QComboBox(self)
input_widget = CustomTextComboBox(self)
combo_delegate = QtWidgets.QStyledItemDelegate(input_widget)
input_widget.setItemDelegate(combo_delegate)

Expand All @@ -394,21 +399,33 @@ def _ui_init(self):

def _on_value_change(self):
new_value = self.current_value()
if self._multivalue:
self._multivalue = False
self._input_widget.set_custom_text(None)
self.value_changed.emit(new_value, self.attr_def.id)

def current_value(self):
idx = self._input_widget.currentIndex()
return self._input_widget.itemData(idx)

def set_value(self, value, multivalue=False):
if multivalue:
set_value = set(value)
if len(set_value) == 1:
multivalue = False
value = tuple(set_value)[0]

if not multivalue:
idx = self._input_widget.findData(value)
cur_idx = self._input_widget.currentIndex()
if idx != cur_idx and idx >= 0:
self._input_widget.setCurrentIndex(idx)

else:
self._input_widget.lineEdit().setText("Multiselection")
custom_text = None
if multivalue:
custom_text = "< Multiselection >"
self._input_widget.set_custom_text(custom_text)
self._multivalue = multivalue


class UnknownAttrWidget(_BaseAttrDefWidget):
Expand Down