handle mandatory property in publisher

This commit is contained in:
Jakub Trllo 2025-07-02 16:59:40 +02:00
parent 541c7c328a
commit 9f69202538
5 changed files with 41 additions and 1 deletions

View file

@ -53,6 +53,7 @@ class PublisherController(
changed.
"create.context.create.attrs.changed" - Create attributes changed.
"create.context.publish.attrs.changed" - Publish attributes changed.
"create.context.instance.state.changed" - Instance state changed.
"create.context.removed.instance" - Instance removed from context.
"create.model.instances.context.changed" - Instances changed context.
like folder, task or variant.

View file

@ -217,6 +217,7 @@ class InstanceItem:
folder_path: Optional[str],
task_name: Optional[str],
is_active: bool,
is_mandatory: bool,
has_promised_context: bool,
):
self._instance_id: str = instance_id
@ -229,6 +230,7 @@ class InstanceItem:
self._folder_path: Optional[str] = folder_path
self._task_name: Optional[str] = task_name
self._is_active: bool = is_active
self._is_mandatory: bool = is_mandatory
self._has_promised_context: bool = has_promised_context
@property
@ -251,6 +253,10 @@ class InstanceItem:
def product_type(self):
return self._product_type
@property
def is_mandatory(self):
return self._is_mandatory
@property
def has_promised_context(self):
return self._has_promised_context
@ -304,6 +310,7 @@ class InstanceItem:
instance["folderPath"],
instance["task"],
instance["active"],
instance.is_mandatory,
instance.has_promised_context,
)
@ -476,6 +483,9 @@ class CreateModel:
self._create_context.add_publish_attr_defs_change_callback(
self._cc_publish_attr_changed
)
self._create_context.add_instance_state_change_callback(
self._cc_instance_state_changed
)
self._create_context.reset_finalization()
@ -1171,6 +1181,16 @@ class CreateModel:
event_data,
)
def _cc_instance_state_changed(self, event):
instance_ids = {
instance.id
for instance in event.data["instances"]
}
self._emit_event(
"create.context.instance.state.changed",
{"instance_ids": instance_ids},
)
def _get_allowed_creators_pattern(self) -> Union[Pattern, None]:
"""Provide regex pattern for configured creator labels in this context

View file

@ -482,6 +482,9 @@ class InstanceCardWidget(CardWidget):
if checkbox_value != new_value:
self._active_checkbox.setChecked(new_value)
def _set_is_mandatory(self, is_mandatory: bool) -> None:
self._active_checkbox.setVisible(not is_mandatory)
def update_instance(self, instance, context_info):
"""Update instance object and update UI."""
self.instance = instance
@ -525,6 +528,7 @@ class InstanceCardWidget(CardWidget):
"""Update instance data"""
self._update_product_name()
self._set_active(self.instance.is_active)
self._set_is_mandatory(self.instance.is_mandatory)
self._validate_context(context_info)
def _set_expanded(self, expanded=None):

View file

@ -132,6 +132,7 @@ class InstanceListItemWidget(QtWidgets.QWidget):
active_checkbox = NiceCheckbox(parent=self)
active_checkbox.setChecked(instance.is_active)
active_checkbox.setVisible(not instance.is_mandatory)
layout = QtWidgets.QHBoxLayout(self)
content_margins = layout.contentsMargins()
@ -192,6 +193,7 @@ class InstanceListItemWidget(QtWidgets.QWidget):
self._instance_label_widget.setText(html_escape(label))
# Check active state
self.set_active(instance.is_active)
self._set_is_mandatory(instance.is_mandatory)
# Check valid states
self._set_valid_property(context_info.is_valid)
@ -203,6 +205,9 @@ class InstanceListItemWidget(QtWidgets.QWidget):
def set_active_toggle_enabled(self, enabled):
self._active_checkbox.setEnabled(enabled)
def _set_is_mandatory(self, is_mandatory: bool) -> None:
self._active_checkbox.setVisible(not is_mandatory)
class ListContextWidget(QtWidgets.QFrame):
"""Context (or global attributes) widget."""

View file

@ -155,6 +155,10 @@ class OverviewWidget(QtWidgets.QFrame):
"create.model.instances.context.changed",
self._on_instance_context_change
)
controller.register_event_callback(
"create.model.instance.state.changed",
self._on_instance_state_changed
)
self._product_content_widget = product_content_widget
self._product_content_layout = product_content_layout
@ -352,6 +356,12 @@ class OverviewWidget(QtWidgets.QFrame):
)
def _on_instance_context_change(self, event):
self._refresh_instance_states(event["instance_ids"])
def _on_instance_state_changed(self, event):
self._refresh_instance_states(event["instance_ids"])
def _refresh_instance_states(self, instance_ids):
current_idx = self._product_views_layout.currentIndex()
for idx in range(self._product_views_layout.count()):
if idx == current_idx:
@ -361,7 +371,7 @@ class OverviewWidget(QtWidgets.QFrame):
widget.set_refreshed(False)
current_widget = self._product_views_layout.widget(current_idx)
current_widget.refresh_instance_states(event["instance_ids"])
current_widget.refresh_instance_states(instance_ids)
def _on_convert_requested(self):
self.convert_requested.emit()