def Changed(self, field: QtWidgets.QWidget, value: str, option: Option) -> None: if field.error is not None: field.error.hide() field.has_error = False if option.value_type == "int": if option.value_count > 1: value = str(value).strip() if (value.startswith("(") and value.endswith(")")) or (value.startswith("[") and value.endswith("]")): value = value[1:-1].strip() if value.endswith(","): value = value[:-1].strip() try: value = [int(v) for v in value.split(",")] except ValueError: field.setStyleSheet("background-color: #FDD;") for v in value.split(","): try: int(v) except ValueError: self.ShowFieldError( field, "Only <b>integer</b> values are allowed.<br/>'%s' can't be parsed as an int." % v.strip()) field.has_error = True return if len(value) != option.value_count: field.setStyleSheet("background-color: #FDD;") self.ShowFieldError( field, "The field needs <b>%d integers</b>,<br/>but %d are provided." % (option.value_count, len(value))) field.has_error = True return else: field.setStyleSheet("") else: value = int(value) if option.value_type == "choice": value = int(value) if option.value_type == "float": value = float(value) if option.value_type == "bool": value = bool(value) if option.key == "buffer_size": self.ShowFieldError(field, "Estimated memory usage:<br/>%s" % PrittyPrintSize(value * self.window.im.nbytes), width=140, normal_msg=True) if option.key == "buffer_mode": self.edits_by_name["buffer_size"].setDisabled(value != 1) self.edits_by_name["buffer_memory"].setDisabled(value != 2) field.current_value = value self.button_apply.setDisabled(False)
def updateEditField(self, edit: QtWidgets.QWidget, value: Any, option: Option) -> None: print(option.value_type, value, edit) edit.setValue(value) edit.current_value = value