def _check_preset( self, preset: KnechtItem, depth: int = 0 ) -> Union[Tuple[KnechtItem, KnechtItem], Tuple[None, None]]: if depth > 10: return None, None for child in preset.iter_children(): ref_id = child.reference if not isinstance(ref_id, QUuid): continue if ref_id == self.check_recurring_id: return preset, child referenced_preset = self.get_preset_from_id(ref_id) if referenced_preset: depth += 1 recursive_preset, recursive_child = self._check_preset( referenced_preset, depth) if recursive_preset: return recursive_preset, recursive_child return None, None
def elements_from_item(self, item: KnechtItem): element = self._create_element_from_item(item) for child in item.iter_children(): e = self._create_element_from_item(child) if e is not None: element.append(e) return element
def _add_camera_variants(item: KnechtItem, variants: KnechtVariantList, src_model: KnechtModel) -> None: """ Convert Camera Preset items to camera command variants """ for child in item.iter_children(): camera_tag, camera_value = child.data(Kg.NAME), child.data(Kg.VALUE) if camera_tag in KnechtImageCameraInfo.rtt_camera_cmds: index = src_model.get_index_from_item(child) camera_cmd = KnechtImageCameraInfo.rtt_camera_cmds.get(camera_tag) camera_value = camera_value.replace(' ', '') try: camera_cmd = camera_cmd.format(*camera_value.split(',')) except Exception as e: LOGGER.warning('Camera Info Tag Value does not match %s\n%s', camera_value, e) variants.add(index, camera_tag, camera_cmd, 'camera_command') LOGGER.debug('Collecting Camera Command %s: %s', camera_tag, camera_cmd)
def _order_children(cls, preset_item: KnechtItem) -> List[KnechtItem]: """ The children list of an item corresponds to the source indices which do not necessarily reflect the item order by order column. We create a list ordered by the order column value of each child. """ return cls.order_items_by_order_column(preset_item.iter_children())