def createWidget(self): if self.dialogType == DIALOG_STANDARD: if self.param.multiline: widget = QPlainTextEdit() if self.param.default: widget.setPlainText(self.param.default) else: widget = StringInputPanel(self.param) if self.param.default: widget.setValue(self.param.default) elif self.dialogType == DIALOG_BATCH: widget = QLineEdit() if self.param.default: widget.setText(self.param.default) else: strings = self.dialog.getAvailableValuesOfType(ParameterString, OutputString) options = [(self.dialog.resolveValueDescription(s), s) for s in strings] if self.param.multiline: widget = MultilineTextPanel(options) widget.setText(self.param.default or "") else: widget = QComboBox() widget.setEditable(True) for desc, val in options: widget.addItem(desc, val) widget.setEditText(self.param.default or "") return widget
def createWidget(self): if self.dialogType == DIALOG_STANDARD: if self.param.multiline: widget = QPlainTextEdit() if self.param.default: widget.setPlainText(self.param.default) else: widget = StringInputPanel(self.param) if self.param.default: widget.setValue(self.param.default) elif self.dialogType == DIALOG_BATCH: widget = QLineEdit() if self.param.default: widget.setText(self.param.default) else: # strings, numbers, files and table fields are all allowed input types strings = self.dialog.getAvailableValuesOfType([ ParameterString, ParameterNumber, ParameterFile, ParameterTableField, ParameterExpression ], OutputString) options = [(self.dialog.resolveValueDescription(s), s) for s in strings] if self.param.multiline: widget = MultilineTextPanel(options) widget.setText(self.param.default or "") else: widget = QComboBox() widget.setEditable(True) for desc, val in options: widget.addItem(desc, val) widget.setEditText(self.param.default or "") return widget
def getWidgetFromParameter(self, param): if isinstance(param, ParameterRaster): item = QtGui.QComboBox() layers = self.getRasterLayers() if param.optional: item.addItem(self.NOT_SELECTED, None) for layer in layers: item.addItem(layer.name(), layer) elif isinstance(param, ParameterVector): item = QtGui.QComboBox() layers = self.getVectorLayers() if param.optional: item.addItem(self.NOT_SELECTED, None) for layer in layers: item.addItem(layer.name(), layer) elif isinstance(param, ParameterTable): item = QtGui.QComboBox() item.setEditable(True) layers = self.getTables() if param.optional: item.addItem(self.NOT_SELECTED, None) for layer in layers: item.addItem(layer.name(), layer) elif isinstance(param, ParameterBoolean): item = QtGui.QComboBox() item.addItem('Yes') item.addItem('No') bools = self.getBooleans() for b in bools: item.addItem(b.name(), b) elif isinstance(param, ParameterSelection): item = QtGui.QComboBox() item.addItems(param.options) elif isinstance(param, ParameterFixedTable): item = FixedTablePanel(param) elif isinstance(param, ParameterRange): item = RangePanel(param) elif isinstance(param, ParameterMultipleInput): if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY: options = self.getVectorLayers() else: options = self.getRasterLayers() opts = [] for opt in options: opts.append(opt.name()) item = MultipleInputPanel(opts) elif isinstance(param, ParameterString): strings = self.getStrings() if param.multiline: item = MultilineTextPanel(strings, self.model) item.setText(str(param.default)) else: item = QtGui.QComboBox() item.setEditable(True) for s in strings: item.addItem(s.name(), s) item.setEditText(str(param.default)) elif isinstance(param, ParameterTableField): item = QtGui.QComboBox() item.setEditable(True) fields = self.getTableFields() for f in fields: item.addItem(f.name(), f) elif isinstance(param, ParameterNumber): item = QtGui.QComboBox() item.setEditable(True) numbers = self.getNumbers() for n in numbers: item.addItem(n.name(), n) item.setEditText(str(param.default)) elif isinstance(param, ParameterCrs): item = CrsSelectionPanel(param.default) elif isinstance(param, ParameterExtent): item = QtGui.QComboBox() item.setEditable(True) extents = self.getExtents() if self.canUseAutoExtent(): item.addItem(self.USE_MIN_COVERING_EXTENT, None) for ex in extents: item.addItem(ex.name(), ex) if not self.canUseAutoExtent(): item.setEditText(str(param.default)) elif isinstance(param, ParameterFile): item = QtGui.QComboBox() item.setEditable(True) files = self.getFiles() for f in files: item.addItem(f.name(), f) else: item = QtGui.QLineEdit() try: item.setText(str(param.default)) except: pass return item
def getWidgetFromParameter(self, param): if isinstance(param, ParameterRaster): item = QComboBox() layers = self.getAvailableValuesOfType(ParameterRaster, OutputRaster) if param.optional: item.addItem(self.NOT_SELECTED, None) for layer in layers: item.addItem(self.resolveValueDescription(layer), layer) elif isinstance(param, ParameterVector): item = QComboBox() layers = self.getAvailableValuesOfType(ParameterVector, OutputVector) if param.optional: item.addItem(self.NOT_SELECTED, None) for layer in layers: item.addItem(self.resolveValueDescription(layer), layer) elif isinstance(param, ParameterTable): item = QComboBox() tables = self.getAvailableValuesOfType(ParameterTable, OutputTable) layers = self.getAvailableValuesOfType(ParameterVector, OutputVector) if param.optional: item.addItem(self.NOT_SELECTED, None) for table in tables: item.addItem(self.resolveValueDescription(table), table) for layer in layers: item.addItem(self.resolveValueDescription(layer), layer) elif isinstance(param, ParameterBoolean): item = QComboBox() item.addItem('Yes') item.addItem('No') bools = self.getAvailableValuesOfType(ParameterBoolean, None) for b in bools: item.addItem(self.resolveValueDescription(b), b) if param.default: item.setCurrentIndex(0) else: item.setCurrentIndex(1) elif isinstance(param, ParameterSelection): item = QComboBox() item.addItems(param.options) item.setCurrentIndex(param.default or 1) elif isinstance(param, ParameterFixedTable): item = FixedTablePanel(param) elif isinstance(param, ParameterRange): item = RangePanel(param) elif isinstance(param, ParameterMultipleInput): if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY: options = self.getAvailableValuesOfType( ParameterVector, OutputVector) else: options = self.getAvailableValuesOfType( ParameterRaster, OutputRaster) opts = [] for opt in options: opts.append(self.resolveValueDescription(opt)) item = MultipleInputPanel(opts) elif isinstance(param, ParameterString): strings = self.getAvailableValuesOfType(ParameterString, OutputString) options = [(self.resolveValueDescription(s), s) for s in strings] if param.multiline: item = MultilineTextPanel(options) item.setText(unicode(param.default or "")) else: item = QComboBox() item.setEditable(True) for desc, val in options: item.addItem(desc, val) item.setEditText(unicode(param.default or "")) elif isinstance(param, ParameterTableField): item = QComboBox() item.setEditable(True) fields = self.getAvailableValuesOfType(ParameterTableField, None) for f in fields: item.addItem(self.resolveValueDescription(f), f) elif isinstance(param, ParameterNumber): item = QComboBox() item.setEditable(True) numbers = self.getAvailableValuesOfType(ParameterNumber, OutputNumber) for n in numbers: item.addItem(self.resolveValueDescription(n), n) item.setEditText(unicode(param.default)) elif isinstance(param, ParameterCrs): item = CrsSelectionPanel(param.default) elif isinstance(param, ParameterExtent): item = QComboBox() item.setEditable(True) extents = self.getAvailableValuesOfType(ParameterExtent, OutputExtent) if self.canUseAutoExtent(): item.addItem(self.USE_MIN_COVERING_EXTENT, None) for ex in extents: item.addItem(self.resolveValueDescription(ex), ex) if not self.canUseAutoExtent(): item.setEditText(unicode(param.default)) elif isinstance(param, ParameterPoint): item = QComboBox() item.setEditable(True) points = self.getAvailableValuesOfType(ParameterPoint) for p in points: item.addItem(self.resolveValueDescription(p), p) item.setEditText(unicode(param.default)) elif isinstance(param, ParameterFile): item = QComboBox() item.setEditable(True) files = self.getAvailableValuesOfType(ParameterFile, OutputFile) for f in files: item.addItem(self.resolveValueDescription(f), f) elif isinstance(param, ParameterGeometryPredicate): item = GeometryPredicateSelectionPanel(param.enabledPredicates) else: item = QLineEdit() try: item.setText(unicode(param.default)) except: pass return item