def __init__(self, param): super(NumberInputPanel, self).__init__(None) self.setupUi(self) self.layer = None self.spnValue.setExpressionsEnabled(True) self.param = param if self.param.dataType() == QgsProcessingParameterNumber.Integer: self.spnValue.setDecimals(0) else: # Guess reasonable step value if self.param.maximum() is not None and self.param.minimum() is not None: try: self.spnValue.setSingleStep(self.calculateStep(float(self.param.minimum()), float(self.param.maximum()))) except: pass if self.param.maximum() is not None: self.spnValue.setMaximum(self.param.maximum()) else: self.spnValue.setMaximum(999999999) if self.param.minimum() is not None: self.spnValue.setMinimum(self.param.minimum()) else: self.spnValue.setMinimum(-999999999) self.allowing_null = False # set default value if param.flags() & QgsProcessingParameterDefinition.FlagOptional: self.spnValue.setShowClearButton(True) min = self.spnValue.minimum() - 1 self.spnValue.setMinimum(min) self.spnValue.setValue(min) self.spnValue.setSpecialValueText(self.tr('Not set')) self.allowing_null = True if param.defaultValue() is not None: self.setValue(param.defaultValue()) if not self.allowing_null: try: self.spnValue.setClearValue(float(param.defaultValue())) except: pass elif self.param.minimum() is not None and not self.allowing_null: try: self.setValue(float(self.param.minimum())) if not self.allowing_null: self.spnValue.setClearValue(float(self.param.minimum())) except: pass elif not self.allowing_null: self.setValue(0) self.spnValue.setClearValue(0) # we don't show the expression button outside of modeler self.layout().removeWidget(self.btnSelect) sip.delete(self.btnSelect) self.btnSelect = None if not self.param.isDynamic(): # only show data defined button for dynamic properties self.layout().removeWidget(self.btnDataDefined) sip.delete(self.btnDataDefined) self.btnDataDefined = None else: self.btnDataDefined.init(0, QgsProperty(), self.param.dynamicPropertyDefinition()) self.btnDataDefined.registerEnabledWidget(self.spnValue, False) self.spnValue.valueChanged.connect(lambda: self.hasChanged.emit())