mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
views are propagating context changes
This commit is contained in:
parent
cc3aa6936e
commit
a21341ad15
5 changed files with 49 additions and 35 deletions
|
|
@ -22,6 +22,7 @@ Only one item can be selected at a time.
|
|||
|
||||
import re
|
||||
import collections
|
||||
from typing import Dict
|
||||
|
||||
from qtpy import QtWidgets, QtCore
|
||||
|
||||
|
|
@ -217,11 +218,18 @@ class InstanceGroupWidget(BaseGroupWidget):
|
|||
def update_icons(self, group_icons):
|
||||
self._group_icons = group_icons
|
||||
|
||||
def update_instance_values(self, context_info_by_id):
|
||||
def update_instance_values(
|
||||
self, context_info_by_id, instance_items_by_id, instance_ids
|
||||
):
|
||||
"""Trigger update on instance widgets."""
|
||||
|
||||
for instance_id, widget in self._widgets_by_id.items():
|
||||
widget.update_instance_values(context_info_by_id[instance_id])
|
||||
if instance_ids is not None and instance_id not in instance_ids:
|
||||
continue
|
||||
widget.update_instance(
|
||||
instance_items_by_id[instance_id],
|
||||
context_info_by_id[instance_id]
|
||||
)
|
||||
|
||||
def update_instances(self, instances, context_info_by_id):
|
||||
"""Update instances for the group.
|
||||
|
|
@ -391,9 +399,6 @@ class ConvertorItemCardWidget(CardWidget):
|
|||
self._icon_widget = icon_widget
|
||||
self._label_widget = label_widget
|
||||
|
||||
def update_instance_values(self, context_info):
|
||||
pass
|
||||
|
||||
|
||||
class InstanceCardWidget(CardWidget):
|
||||
"""Card widget representing instance."""
|
||||
|
|
@ -461,7 +466,7 @@ class InstanceCardWidget(CardWidget):
|
|||
self._active_checkbox = active_checkbox
|
||||
self._expand_btn = expand_btn
|
||||
|
||||
self.update_instance_values(context_info)
|
||||
self._update_instance_context(context_info)
|
||||
|
||||
def set_active_toggle_enabled(self, enabled):
|
||||
self._active_checkbox.setEnabled(enabled)
|
||||
|
|
@ -486,7 +491,7 @@ class InstanceCardWidget(CardWidget):
|
|||
def update_instance(self, instance, context_info):
|
||||
"""Update instance object and update UI."""
|
||||
self.instance = instance
|
||||
self.update_instance_values(context_info)
|
||||
self._update_instance_context(context_info)
|
||||
|
||||
def _validate_context(self, context_info):
|
||||
valid = context_info.is_valid
|
||||
|
|
@ -522,7 +527,7 @@ class InstanceCardWidget(CardWidget):
|
|||
QtCore.Qt.NoTextInteraction
|
||||
)
|
||||
|
||||
def update_instance_values(self, context_info):
|
||||
def _update_instance_context(self, context_info):
|
||||
"""Update instance data"""
|
||||
self._update_product_name()
|
||||
self.set_active(self.instance.is_active)
|
||||
|
|
@ -596,7 +601,7 @@ class InstanceCardView(AbstractInstanceView):
|
|||
self._context_widget = None
|
||||
self._convertor_items_group = None
|
||||
self._active_toggle_enabled = True
|
||||
self._widgets_by_group = {}
|
||||
self._widgets_by_group: Dict[str, InstanceGroupWidget] = {}
|
||||
self._ordered_groups = []
|
||||
|
||||
self._explicitly_selected_instance_ids = []
|
||||
|
|
@ -702,7 +707,7 @@ class InstanceCardView(AbstractInstanceView):
|
|||
# Prepare instances by group and identifiers by group
|
||||
instances_by_group = collections.defaultdict(list)
|
||||
identifiers_by_group = collections.defaultdict(set)
|
||||
for instance in self._controller.get_instances():
|
||||
for instance in self._controller.get_instance_items():
|
||||
group_name = instance.group_label
|
||||
instances_by_group[group_name].append(instance)
|
||||
identifiers_by_group[group_name].add(
|
||||
|
|
@ -817,11 +822,18 @@ class InstanceCardView(AbstractInstanceView):
|
|||
|
||||
self._convertor_items_group.update_items(convertor_items)
|
||||
|
||||
def refresh_instance_states(self):
|
||||
def refresh_instance_states(self, instance_ids=None):
|
||||
"""Trigger update of instances on group widgets."""
|
||||
if instance_ids is not None:
|
||||
instance_ids = set(instance_ids)
|
||||
context_info_by_id = self._controller.get_instances_context_info()
|
||||
instance_items_by_id = self._controller.get_instance_items_by_id(
|
||||
instance_ids
|
||||
)
|
||||
for widget in self._widgets_by_group.values():
|
||||
widget.update_instance_values(context_info_by_id)
|
||||
widget.update_instance_values(
|
||||
context_info_by_id, instance_items_by_id, instance_ids
|
||||
)
|
||||
|
||||
def _on_active_changed(self, group_name, instance_id, value):
|
||||
group_widget = self._widgets_by_group[group_name]
|
||||
|
|
|
|||
|
|
@ -191,9 +191,9 @@ class InstanceListItemWidget(QtWidgets.QWidget):
|
|||
def update_instance(self, instance, context_info):
|
||||
"""Update instance object."""
|
||||
self.instance = instance
|
||||
self.update_instance_values(context_info)
|
||||
self._update_instance_values(context_info)
|
||||
|
||||
def update_instance_values(self, context_info):
|
||||
def _update_instance_values(self, context_info):
|
||||
"""Update instance data propagated to widgets."""
|
||||
# Check product name
|
||||
label = self.instance.label
|
||||
|
|
@ -873,12 +873,21 @@ class InstanceListView(AbstractInstanceView):
|
|||
widget = self._group_widgets.pop(group_name)
|
||||
widget.deleteLater()
|
||||
|
||||
def refresh_instance_states(self):
|
||||
def refresh_instance_states(self, instance_ids=None):
|
||||
"""Trigger update of all instances."""
|
||||
if instance_ids is not None:
|
||||
instance_ids = set(instance_ids)
|
||||
context_info_by_id = self._controller.get_instances_context_info()
|
||||
instance_items_by_id = self._controller.get_instance_items_by_id(
|
||||
instance_ids
|
||||
)
|
||||
for instance_id, widget in self._widgets_by_id.items():
|
||||
context_info = context_info_by_id[instance_id]
|
||||
widget.update_instance_values(context_info)
|
||||
if instance_ids is not None and instance_id not in instance_ids:
|
||||
continue
|
||||
widget.update_instance(
|
||||
instance_items_by_id[instance_id],
|
||||
context_info_by_id[instance_id],
|
||||
)
|
||||
|
||||
def _on_active_changed(self, changed_instance_id, new_value):
|
||||
selected_instance_ids, _, _ = self.get_selected_items()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ from .product_info import ProductInfoWidget
|
|||
|
||||
class OverviewWidget(QtWidgets.QFrame):
|
||||
active_changed = QtCore.Signal()
|
||||
instance_context_changed = QtCore.Signal()
|
||||
create_requested = QtCore.Signal()
|
||||
convert_requested = QtCore.Signal()
|
||||
publish_tab_requested = QtCore.Signal()
|
||||
|
|
@ -134,9 +133,6 @@ class OverviewWidget(QtWidgets.QFrame):
|
|||
self._on_active_changed
|
||||
)
|
||||
# Instance context has changed
|
||||
product_attributes_widget.instance_context_changed.connect(
|
||||
self._on_instance_context_change
|
||||
)
|
||||
product_attributes_widget.convert_requested.connect(
|
||||
self._on_convert_requested
|
||||
)
|
||||
|
|
@ -163,6 +159,10 @@ class OverviewWidget(QtWidgets.QFrame):
|
|||
"create.context.removed.instance",
|
||||
self._on_instances_removed
|
||||
)
|
||||
controller.register_event_callback(
|
||||
"create.model.instances.context.changed",
|
||||
self._on_instance_context_change
|
||||
)
|
||||
|
||||
self._product_content_widget = product_content_widget
|
||||
self._product_content_layout = product_content_layout
|
||||
|
|
@ -362,7 +362,7 @@ class OverviewWidget(QtWidgets.QFrame):
|
|||
self._current_state == "publish"
|
||||
)
|
||||
|
||||
def _on_instance_context_change(self):
|
||||
def _on_instance_context_change(self, event):
|
||||
current_idx = self._product_views_layout.currentIndex()
|
||||
for idx in range(self._product_views_layout.count()):
|
||||
if idx == current_idx:
|
||||
|
|
@ -372,9 +372,7 @@ class OverviewWidget(QtWidgets.QFrame):
|
|||
widget.set_refreshed(False)
|
||||
|
||||
current_widget = self._product_views_layout.widget(current_idx)
|
||||
current_widget.refresh_instance_states()
|
||||
|
||||
self.instance_context_changed.emit()
|
||||
current_widget.refresh_instance_states(event["instance_ids"])
|
||||
|
||||
def _on_convert_requested(self):
|
||||
self.convert_requested.emit()
|
||||
|
|
|
|||
|
|
@ -621,7 +621,6 @@ class GlobalAttrsWidget(QtWidgets.QWidget):
|
|||
product name: [ immutable ]
|
||||
[Submit] [Cancel]
|
||||
"""
|
||||
instance_context_changed = QtCore.Signal()
|
||||
|
||||
multiselection_text = "< Multiselection >"
|
||||
unknown_value = "N/A"
|
||||
|
|
@ -775,7 +774,6 @@ class GlobalAttrsWidget(QtWidgets.QWidget):
|
|||
|
||||
self._controller.set_instances_context_info(changes_by_id)
|
||||
self._refresh_items()
|
||||
self.instance_context_changed.emit()
|
||||
|
||||
def _on_cancel(self):
|
||||
"""Cancel changes and set back to their irigin value."""
|
||||
|
|
@ -933,4 +931,3 @@ class GlobalAttrsWidget(QtWidgets.QWidget):
|
|||
if changed:
|
||||
self._refresh_items()
|
||||
self._refresh_content()
|
||||
self.instance_context_changed.emit()
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ class ProductInfoWidget(QtWidgets.QWidget):
|
|||
│ │ attributes │
|
||||
└───────────────────────────────┘
|
||||
"""
|
||||
instance_context_changed = QtCore.Signal()
|
||||
convert_requested = QtCore.Signal()
|
||||
|
||||
def __init__(
|
||||
|
|
@ -123,13 +122,14 @@ class ProductInfoWidget(QtWidgets.QWidget):
|
|||
self._context_selected = False
|
||||
self._all_instances_valid = True
|
||||
|
||||
global_attrs_widget.instance_context_changed.connect(
|
||||
self._on_instance_context_changed
|
||||
)
|
||||
convert_btn.clicked.connect(self._on_convert_click)
|
||||
thumbnail_widget.thumbnail_created.connect(self._on_thumbnail_create)
|
||||
thumbnail_widget.thumbnail_cleared.connect(self._on_thumbnail_clear)
|
||||
|
||||
controller.register_event_callback(
|
||||
"create.model.instances.context.changed",
|
||||
self._on_instance_context_change
|
||||
)
|
||||
controller.register_event_callback(
|
||||
"instance.thumbnail.changed",
|
||||
self._on_thumbnail_changed
|
||||
|
|
@ -196,7 +196,7 @@ class ProductInfoWidget(QtWidgets.QWidget):
|
|||
|
||||
self._update_thumbnails()
|
||||
|
||||
def _on_instance_context_changed(self):
|
||||
def _on_instance_context_change(self):
|
||||
instance_ids = {
|
||||
instance.id
|
||||
for instance in self._current_instances
|
||||
|
|
@ -214,8 +214,6 @@ class ProductInfoWidget(QtWidgets.QWidget):
|
|||
self.creator_attrs_widget.set_instances_valid(all_valid)
|
||||
self.publish_attrs_widget.set_instances_valid(all_valid)
|
||||
|
||||
self.instance_context_changed.emit()
|
||||
|
||||
def _on_convert_click(self):
|
||||
self.convert_requested.emit()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue