def add_fields_to_component(component: Group, fields_widget: QListWidget, component_model: NexusTreeModel = None): """ Adds fields from a list widget to a component. :param component: Component to add the field to. :param fields_widget: The field list widget to extract field information such the name and value of each field. """ for i in range(fields_widget.count()): widget = fields_widget.itemWidget(fields_widget.item(i)) try: if not isinstance(widget.value, (Link, Dataset)): stream_module = deepcopy(widget.value) stream_module.parent_node = component component.children.append(stream_module) else: component[widget.name] = widget.value except ValueError as error: show_warning_dialog( f"Warning: field {widget.name} not added", title="Field invalid", additional_info=str(error), parent=fields_widget.parent().parent(), ) if component_model and component_model.current_nxs_obj[1]: row = component_model.rowCount(component_model.current_nxs_obj[1]) component_model.createIndex(row, 0, component_model.current_nxs_obj[1])
def add_fields_to_component(component: Component, fields_widget: QListWidget): """ Adds fields from a list widget to a component. :param component: Component to add the field to. :param fields_widget: The field list widget to extract field information such the name and value of each field. """ for i in range(fields_widget.count()): widget = fields_widget.itemWidget(fields_widget.item(i)) try: component.set_field( name=widget.name, value=widget.value, dtype=widget.dtype ) except ValueError as error: show_warning_dialog( f"Warning: field {widget.name} not added", title="Field invalid", additional_info=str(error), parent=fields_widget.parent().parent(), )