checkbox key in dict works

This commit is contained in:
iLLiCiTiT 2021-01-29 10:53:24 +01:00
parent 1b5cf7bc61
commit 8d97ecc9ba
2 changed files with 23 additions and 1 deletions

View file

@ -256,6 +256,20 @@ class DictImmutableKeysEntity(ItemEntity):
)
def schema_validations(self):
if self.checkbox_key:
checkbox_child = self.non_gui_children.get(self.checkbox_key)
if not checkbox_child:
raise ValueError(
"{}: Checkbox children \"{}\" was not found.".format(
self.path, self.checkbox_key
)
)
from .input_entities import BoolEntity
if not isinstance(checkbox_child, BoolEntity):
raise TypeError((
"{}: Checkbox children \"{}\" is not `boolean` type."
).format(self.path, self.checkbox_key))
super(DictImmutableKeysEntity, self).schema_validations()
for child_obj in self.children:
child_obj.schema_validations()

View file

@ -43,12 +43,16 @@ from .lib import CHILD_OFFSET
class DictImmutableKeysWidget(BaseWidget):
def create_ui(self):
self.input_fields = []
self.checkbox_child = None
if not self.entity.is_dynamic_item and not self.entity.label:
self._ui_item_without_label()
else:
self._ui_item_or_as_widget()
if not self.entity.is_dynamic_item:
self.checkbox_child = self.entity.non_gui_children.get(
self.entity.checkbox_key
)
for child_obj in self.entity.children:
self.input_fields.append(
@ -122,6 +126,10 @@ class DictImmutableKeysWidget(BaseWidget):
def add_widget_to_layout(self, widget, label=None):
row = self.content_layout.rowCount()
if self.checkbox_child and widget.entity is self.checkbox_child:
self.body_widget.add_widget_before_label(widget)
return
if label:
label_widget = GridLabelWidget(label, widget)
label_widget.input_field = widget