本文整理汇总了Python中processing.gui.DestinationSelectionPanel.DestinationSelectionPanel类的典型用法代码示例。如果您正苦于以下问题:Python DestinationSelectionPanel类的具体用法?Python DestinationSelectionPanel怎么用?Python DestinationSelectionPanel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DestinationSelectionPanel类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRasterDestination
def testRasterDestination(self):
param = QgsProcessingParameterRasterDestination('test')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
panel = DestinationSelectionPanel(param, alg)
panel.setValue('/home/me/test.tif')
v = panel.getValue()
self.assertIsInstance(v, QgsProcessingOutputLayerDefinition)
self.assertEqual(v.createOptions, {'fileEncoding': 'System'})
self.assertEqual(v.sink.staticValue(), '/home/me/test.tif')
panel.setValue(QgsProcessing.TEMPORARY_OUTPUT)
v = panel.getValue()
self.assertIsInstance(v, QgsProcessingOutputLayerDefinition)
self.assertEqual(v.sink.staticValue(), QgsProcessing.TEMPORARY_OUTPUT)
ProcessingConfig.setSettingValue(ProcessingConfig.OUTPUT_FOLDER, testDataPath)
panel.setValue('test.tif')
v = panel.getValue()
self.assertIsInstance(v, QgsProcessingOutputLayerDefinition)
self.assertEqual(v.createOptions, {'fileEncoding': 'System'})
self.assertEqual(v.sink.staticValue(), os.path.join(testDataPath, 'test.tif'))
示例2: testFileDestination
def testFileDestination(self):
param = QgsProcessingParameterFileDestination('test')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
panel = DestinationSelectionPanel(param, alg)
panel.setValue('/home/me/test.tif')
v = panel.getValue()
self.assertEqual(v, '/home/me/test.tif')
ProcessingConfig.setSettingValue(ProcessingConfig.OUTPUT_FOLDER, testDataPath)
panel.setValue('test.tif')
v = panel.getValue()
self.assertEqual(v, os.path.join(testDataPath, 'test.tif'))
示例3: setupUi
#.........这里部分代码省略.........
self.verticalLayout.addWidget(self.defaultEdit)
self.verticalLayout.addWidget(QLabel(self.tr('Parent layer')))
self.parentCombo = QComboBox()
self.parentCombo.addItem(self.tr("None"), None)
idx = 1
for param in list(self.alg.parameterComponents().values()):
definition = self.alg.parameterDefinition(param.parameterName())
if isinstance(definition, (QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer)):
self.parentCombo.addItem(definition.description(), definition.name())
if self.param is not None:
if self.param.parentLayerParameterName() == definition.name():
self.parentCombo.setCurrentIndex(idx)
idx += 1
self.verticalLayout.addWidget(self.parentCombo)
elif (self.paramType == parameters.PARAMETER_STRING or
isinstance(self.param, QgsProcessingParameterString)):
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.defaultTextBox = QLineEdit()
if self.param is not None:
self.defaultTextBox.setText(self.param.defaultValue())
self.verticalLayout.addWidget(self.defaultTextBox)
elif (self.paramType == parameters.PARAMETER_FILE or
isinstance(self.param, QgsProcessingParameterFile)):
self.verticalLayout.addWidget(QLabel(self.tr('Type')))
self.fileFolderCombo = QComboBox()
self.fileFolderCombo.addItem(self.tr('File'))
self.fileFolderCombo.addItem(self.tr('Folder'))
if self.param is not None:
self.fileFolderCombo.setCurrentIndex(
1 if self.param.behavior() == QgsProcessingParameterFile.Folder else 0)
self.verticalLayout.addWidget(self.fileFolderCombo)
elif (self.paramType == parameters.PARAMETER_POINT or
isinstance(self.param, QgsProcessingParameterPoint)):
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.defaultTextBox = QLineEdit()
if self.param is not None:
self.defaultTextBox.setText(self.param.defaultValue())
self.verticalLayout.addWidget(self.defaultTextBox)
elif (self.paramType == parameters.PARAMETER_CRS or
isinstance(self.param, QgsProcessingParameterCrs)):
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.selector = QgsProjectionSelectionWidget()
if self.param is not None:
self.selector.setCrs(QgsCoordinateReferenceSystem(self.param.defaultValue()))
else:
self.selector.setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
self.verticalLayout.addWidget(self.selector)
elif self.paramType == parameters.PARAMETER_ENUM or \
isinstance(self.param, QgsProcessingParameterEnum):
self.widget = EnumModelerWidget(self)
if self.param is not None:
self.widget.setAllowMultiple(bool(self.param.allowMultiple()))
self.widget.setOptions(self.param.options())
self.widget.setDefault(self.param.defaultValue())
self.verticalLayout.addWidget(self.widget)
elif self.paramType == parameters.PARAMETER_MATRIX or \
isinstance(self.param, QgsProcessingParameterMatrix):
self.widget = MatrixModelerWidget(self)
if self.param is not None:
self.widget.setValue(self.param.defaultValue())
self.widget.setHeaders(self.param.headers())
self.widget.setFixedRows(self.param.hasFixedNumberRows())
self.verticalLayout.addWidget(self.widget)
elif isinstance(self.param, QgsProcessingDestinationParameter):
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.defaultWidget = DestinationSelectionPanel(self.param, self.alg, default_selection=True)
self.verticalLayout.addWidget(self.defaultWidget)
self.verticalLayout.addSpacing(20)
self.requiredCheck = QCheckBox()
self.requiredCheck.setText(self.tr('Mandatory'))
self.requiredCheck.setChecked(True)
if self.param is not None:
self.requiredCheck.setChecked(not self.param.flags() & QgsProcessingParameterDefinition.FlagOptional)
self.verticalLayout.addWidget(self.requiredCheck)
# If child algorithm output is mandatory, disable checkbox
if isinstance(self.param, QgsProcessingDestinationParameter):
provider_name, child_name, output_name = self.param.name().split(':')
child = self.alg.childAlgorithms()['{}:{}'.format(provider_name, child_name)]
model_output = child.modelOutput(output_name)
param_def = child.algorithm().parameterDefinition(model_output.childOutputName())
if not (param_def.flags() & QgsProcessingParameterDefinition.FlagOptional):
self.requiredCheck.setEnabled(False)
self.requiredCheck.setChecked(True)
self.buttonBox = QDialogButtonBox(self)
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel |
QDialogButtonBox.Ok)
self.buttonBox.setObjectName('buttonBox')
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
self.verticalLayout.addStretch()
self.verticalLayout.addWidget(self.buttonBox)
self.setLayout(self.verticalLayout)
示例4: testVectorDestination
def testVectorDestination(self):
param = QgsProcessingParameterVectorDestination('test')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
panel = DestinationSelectionPanel(param, alg)
panel.setValue(QgsProcessing.TEMPORARY_OUTPUT)
v = panel.getValue()
self.assertIsInstance(v, QgsProcessingOutputLayerDefinition)
self.assertEqual(v.sink.staticValue(), QgsProcessing.TEMPORARY_OUTPUT)
panel.setValue('''ogr:dbname='/me/a.gpkg' table="d" (geom) sql=''')
v = panel.getValue()
self.assertIsInstance(v, QgsProcessingOutputLayerDefinition)
self.assertEqual(v.createOptions, {'fileEncoding': 'System'})
self.assertEqual(v.sink.staticValue(), '''ogr:dbname='/me/a.gpkg' table="d" (geom) sql=''')
panel.setValue('''postgis:dbname='oraclesux' host=10.1.1.221 port=5432 user='qgis' password='qgis' table="stufff"."output" (the_geom) sql=''')
v = panel.getValue()
self.assertIsInstance(v, QgsProcessingOutputLayerDefinition)
self.assertEqual(v.createOptions, {'fileEncoding': 'System'})
self.assertEqual(v.sink.staticValue(), '''postgis:dbname='oraclesux' host=10.1.1.221 port=5432 user='qgis' password='qgis' table="stufff"."output" (the_geom) sql=''')
panel.setValue('/home/me/test.shp')
v = panel.getValue()
self.assertIsInstance(v, QgsProcessingOutputLayerDefinition)
self.assertEqual(v.createOptions, {'fileEncoding': 'System'})
self.assertEqual(v.sink.staticValue(), '/home/me/test.shp')
ProcessingConfig.setSettingValue(ProcessingConfig.OUTPUT_FOLDER, testDataPath)
panel.setValue('test.shp')
v = panel.getValue()
self.assertIsInstance(v, QgsProcessingOutputLayerDefinition)
self.assertEqual(v.createOptions, {'fileEncoding': 'System'})
self.assertEqual(v.sink.staticValue(), os.path.join(testDataPath, 'test.shp'))
示例5: ModelerParameterDefinitionDialog
#.........这里部分代码省略.........
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.defaultTextBox = QLineEdit()
if self.param is not None:
self.defaultTextBox.setText(self.param.defaultValue())
self.verticalLayout.addWidget(self.defaultTextBox)
elif (self.paramType == parameters.PARAMETER_CRS or
isinstance(self.param, QgsProcessingParameterCrs)):
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.selector = QgsProjectionSelectionWidget()
if self.param is not None:
self.selector.setCrs(QgsCoordinateReferenceSystem(self.param.defaultValue()))
else:
self.selector.setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
self.verticalLayout.addWidget(self.selector)
elif self.paramType == parameters.PARAMETER_ENUM or \
isinstance(self.param, QgsProcessingParameterEnum):
self.widget = EnumModelerWidget(self)
if self.param is not None:
self.widget.setAllowMultiple(bool(self.param.allowMultiple()))
self.widget.setOptions(self.param.options())
self.widget.setDefault(self.param.defaultValue())
self.verticalLayout.addWidget(self.widget)
elif self.paramType == parameters.PARAMETER_MATRIX or \
isinstance(self.param, QgsProcessingParameterMatrix):
self.widget = MatrixModelerWidget(self)
if self.param is not None:
self.widget.setValue(self.param.defaultValue())
self.widget.setHeaders(self.param.headers())
self.widget.setFixedRows(self.param.hasFixedNumberRows())
self.verticalLayout.addWidget(self.widget)
elif isinstance(self.param, QgsProcessingDestinationParameter):
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.defaultWidget = DestinationSelectionPanel(self.param, self.alg, default_selection=True)
self.verticalLayout.addWidget(self.defaultWidget)
self.verticalLayout.addSpacing(20)
self.requiredCheck = QCheckBox()
self.requiredCheck.setText(self.tr('Mandatory'))
self.requiredCheck.setChecked(True)
if self.param is not None:
self.requiredCheck.setChecked(not self.param.flags() & QgsProcessingParameterDefinition.FlagOptional)
self.verticalLayout.addWidget(self.requiredCheck)
# If child algorithm output is mandatory, disable checkbox
if isinstance(self.param, QgsProcessingDestinationParameter):
provider_name, child_name, output_name = self.param.name().split(':')
child = self.alg.childAlgorithms()['{}:{}'.format(provider_name, child_name)]
model_output = child.modelOutput(output_name)
param_def = child.algorithm().parameterDefinition(model_output.childOutputName())
if not (param_def.flags() & QgsProcessingParameterDefinition.FlagOptional):
self.requiredCheck.setEnabled(False)
self.requiredCheck.setChecked(True)
self.buttonBox = QDialogButtonBox(self)
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel |
QDialogButtonBox.Ok)
self.buttonBox.setObjectName('buttonBox')
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
self.verticalLayout.addStretch()
self.verticalLayout.addWidget(self.buttonBox)
self.setLayout(self.verticalLayout)