def setModelData(self, editor, model, idx): #item = self.attrs_widget.model.itemFromIndex(idx) attr, dv = model.data(idx, Qt.UserRole) if attr == ua.AttributeIds.NodeClass: dv.Value.Value = ua.NodeClass[editor.currentText()] text = editor.currentText() elif attr == ua.AttributeIds.DataType: dv.Value.Value = editor.get_node().nodeid text = data_type_to_string(dv) elif attr in (ua.AttributeIds.AccessLevel, ua.AttributeIds.UserAccessLevel, ua.AttributeIds.WriteMask, ua.AttributeIds.UserWriteMask, ua.AttributeIds.EventNotifier): #attr_name = attr.name #if attr_name.startswith("User"): #attr_name = attr_name[4:] #attr_enum = getattr(ua, attr_name) #string = ", ".join([e.name for e in attr_enum.parse_bitfield(dv.Value.Value)]) raise NotImplementedError else: if isinstance(editor, QComboBox): text = editor.currentText() else: text = editor.text() dv.Value = string_to_variant(text, dv.Value.VariantType) #model.setItemData(idx, [text, (attr, dv)], [Qt.DisplayRole, Qt.UserRole]) model.setItemData(idx, {Qt.DisplayRole: text, Qt.UserRole: (attr, dv)})
def setModelData(self, editor, model, idx): #item = self.attrs_widget.model.itemFromIndex(idx) attr, dv = model.data(idx, Qt.UserRole) if attr == ua.AttributeIds.NodeClass: dv.Value.Value = ua.NodeClass[editor.currentText()] text = editor.currentText() elif attr == ua.AttributeIds.DataType: dv.Value.Value = editor.get_node().nodeid text = data_type_to_string(dv) elif attr in (ua.AttributeIds.AccessLevel, ua.AttributeIds.UserAccessLevel, ua.AttributeIds.WriteMask, ua.AttributeIds.UserWriteMask, ua.AttributeIds.EventNotifier): dv.Value.Value = editor.get_byte() text = enum_to_string(attr, dv) else: if isinstance(editor, QComboBox): text = editor.currentText() else: text = editor.text() try: dv.Value = string_to_variant(text, dv.Value.VariantType) except Exception as ex: self.error.emit(ex) raise model.setItemData(idx, {Qt.DisplayRole: text, Qt.UserRole: (attr, dv)})
def get_args(self): nodeid, bname = self.get_nodeid_and_bname() dtype = self.dataTypeButton.get_node() vtype = data_type_to_variant_type(dtype) if vtype == ua.VariantType.ExtensionObject: # we currently cannot construct a complex object from a string var = ua.Variant() else: var = string_to_variant(self.valLineEdit.text(), vtype) return nodeid, bname, var, vtype, dtype.nodeid
def get_args(self): args = self.get_ns_and_name() dtype = self.dataTypeButton.get_node() self.settings.setValue("last_datatype", dtype.nodeid.to_string()) vtype = dtype_to_vtype(self.server, dtype) var = string_to_variant(self.valLineEdit.text(), vtype) args.append(var) args.append(vtype) args.append(dtype.nodeid) print("NewUaVariable returns:", args) return args
def _call(self): parent = self.node.get_parent() args = [] for inp in self.inputs: val = string_to_variant(inp.text(), data_type_to_variant_type(inp.data_type)) args.append(val) result = call_method_full(parent, self.node, *args) self.result_label.setText(str(result.StatusCode)) for idx, res in enumerate(result.OutputArguments): self.outputs[idx].setText(val_to_string(res))
def edit_attr_finished(self, item): if not self._check_edit(item): return try: var = item.data() val = item.text() var = string_to_variant(val, var.VariantType) self.current_node.set_value(var) except Exception as ex: self.window.show_error(ex) raise finally: dv = self.current_node.get_data_value() item.setText(variant_to_string(dv.Value)) name_item = self.model.item(item.row(), 0) name_item.child(0, 1).setText(val_to_string(dv.ServerTimestamp)) name_item.child(1, 1).setText(val_to_string(dv.SourceTimestamp))