def executeAlgorithmAsBatchProcess(self): item = self.algorithmTree.currentItem() if isinstance(item, TreeAlgorithmItem): alg = QgsApplication.processingRegistry().algorithmById(item.alg.id()) dlg = BatchAlgorithmDialog(alg) dlg.show() dlg.exec_()
def executeAlgorithmAsBatchProcess(self): item = self.algorithmTree.currentItem() if isinstance(item, TreeAlgorithmItem): alg = Processing.getAlgorithm(item.alg.commandLineName()) alg = alg.getCopy() dlg = BatchAlgorithmDialog(alg) dlg.exec_()
def checkConstructWrapper(self, param, expected_wrapper_class): alg = QgsApplication.processingRegistry().algorithmById( 'native:centroids') # algorithm dialog dlg = AlgorithmDialog(alg) wrapper = WidgetWrapperFactory.create_wrapper_from_class(param, dlg) self.assertIsNotNone(wrapper) self.assertIsInstance(wrapper, expected_wrapper_class) self.assertEqual(wrapper.dialog, dlg) self.assertIsNotNone(wrapper.widget) # batch dialog dlg = BatchAlgorithmDialog(alg) wrapper = WidgetWrapperFactory.create_wrapper_from_class(param, dlg) self.assertIsNotNone(wrapper) self.assertIsInstance(wrapper, expected_wrapper_class) self.assertEqual(wrapper.dialog, dlg) self.assertIsNotNone(wrapper.widget) # modeler dialog model = QgsProcessingModelAlgorithm() dlg = ModelerParametersDialog(alg, model) wrapper = WidgetWrapperFactory.create_wrapper_from_class(param, dlg) self.assertIsNotNone(wrapper) self.assertIsInstance(wrapper, expected_wrapper_class) self.assertEqual(wrapper.dialog, dlg) self.assertIsNotNone(wrapper.widget)
def test_OTBParameterChoice_Gui(self): """ This test is similar to GuiTests in processing that is done on other parameter widget in processing Main difference is this test uses create_wrapper_from_metadata() rather than create_wrapper_from_class() like rest of processing widgets. """ param = OtbParameterChoice('test') alg = QgsApplication.processingRegistry().createAlgorithmById('otb:Smoothing') # algorithm dialog dlg = AlgorithmDialog(alg) wrapper = WidgetWrapperFactory.create_wrapper_from_metadata(param, dlg) self.assertIsNotNone(wrapper) self.assertIsInstance(wrapper, OtbChoiceWidgetWrapper) self.assertEqual(wrapper.dialog, dlg) self.assertIsNotNone(wrapper.widget) alg = QgsApplication.processingRegistry().createAlgorithmById('otb:Smoothing') # batch dialog dlg = BatchAlgorithmDialog(alg) wrapper = WidgetWrapperFactory.create_wrapper_from_metadata(param, dlg) self.assertIsNotNone(wrapper) self.assertIsInstance(wrapper, OtbChoiceWidgetWrapper) self.assertEqual(wrapper.dialog, dlg) self.assertIsNotNone(wrapper.widget) alg = QgsApplication.processingRegistry().createAlgorithmById('otb:Smoothing') # modeler dialog model = QgsProcessingModelAlgorithm() dlg = ModelerParametersDialog(alg, model) wrapper = WidgetWrapperFactory.create_wrapper_from_metadata(param, dlg) self.assertIsNotNone(wrapper) self.assertIsInstance(wrapper, OtbChoiceWidgetWrapper) self.assertEqual(wrapper.dialog, dlg) self.assertIsNotNone(wrapper.widget)
def executeAlgorithmAsBatchProcess(self): alg = self.algorithmTree.selectedAlgorithm().create() if self.algorithmTree.selectedAlgorithm() is not None else None if alg is not None: dlg = BatchAlgorithmDialog(alg, iface.mainWindow()) dlg.setAttribute(Qt.WA_DeleteOnClose) dlg.show() dlg.exec_()
def executeAlgorithmAsBatchProcess(self): item = self.algorithmTree.currentItem() if isinstance(item, TreeAlgorithmItem): alg = QgsApplication.processingRegistry().createAlgorithmById(item.alg.id()) if alg: dlg = BatchAlgorithmDialog(alg) dlg.show() dlg.exec_() # have to manually delete the dialog - otherwise it's owned by the # iface mainWindow and never deleted dlg.deleteLater()
def executeAlgorithmAsBatchProcess(self): item = self.algorithmTree.currentItem() if isinstance(item, TreeAlgorithmItem): alg = Processing.getAlgorithm(item.alg.commandLineName()) alg = alg.getCopy() dlg = BatchAlgorithmDialog(alg) dlg.show() dlg.exec_()
def executeAlgorithmAsBatchProcess(self): item = self.algorithmTree.currentItem() if isinstance(item, TreeAlgorithmItem): alg = QgsApplication.processingRegistry().algorithmById(item.alg.id()) #hack - remove when getCopy is removed provider = alg.provider() alg = alg.getCopy() #hack pt 2 alg.setProvider(provider) dlg = BatchAlgorithmDialog(alg) dlg.show() dlg.exec_()
def runAsBatch(self): self.close() dlg = BatchAlgorithmDialog(self.algorithm().create(), parent=iface.mainWindow()) dlg.show() dlg.exec_()
def runAsBatch(self): self.close() dlg = BatchAlgorithmDialog(self.algorithm()) dlg.show() dlg.exec_()
class StepDialog(QtGui.QDialog): def __init__(self, alg, mainDialog, canEdit=True): self.alg = alg self.mainDialog = mainDialog self.goForward = False self.goBackward = False QtGui.QDialog.__init__(self) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMinMaxButtonsHint) # create a tab for this algorithm self.tabLayout = QtGui.QGridLayout() self.algInstructions = QtGui.QTextEdit() self.algInstructions.setMinimumWidth(250) self.algInstructions.setMaximumWidth(250) self.algInstructions.setFontPointSize(10) if not canEdit: self.algInstructions.setReadOnly(True) self.normalModeDialog = alg.getCustomParametersDialog() if not self.normalModeDialog: self.normalModeDialog = AlgorithmDialog(alg) self.batchModeDialog = BatchAlgorithmDialog(alg) self.batchModeDialog.setHidden(True) # forwardButton does the job of cancel/close button try: if self.alg.name == "Field calculator": self.normalModeDialog.mButtonBox.removeButton(self.normalModeDialog.mButtonBox.button(QtGui.QDialogButtonBox.Cancel)) else: self.normalModeDialog.buttonBox.removeButton(self.normalModeDialog.buttonBox.button(QtGui.QDialogButtonBox.Close)) self.batchModeDialog.buttonBox.removeButton(self.batchModeDialog.buttonBox.button(QtGui.QDialogButtonBox.Close)) # forwardButton does this job except: # Not all dialogs might have buttonBox pass if canEdit: try: self.normalModeDialog.progressBar.hide() self.batchModeDialog.progressBar.hide() if self.alg.name == "Field calculator": self.normalModeDialog.mButtonBox.hide() else: self.normalModeDialog.buttonBox.hide() self.batchModeDialog.buttonBox.hide() except: # Not all dialogs might have buttonBox pass self.normalModeDialog.connect(self.normalModeDialog, QtCore.SIGNAL("finished(int)"), self.forward) self.batchModeDialog.connect(self.batchModeDialog, QtCore.SIGNAL("finished(int)"), self.forward) self.tabLayout.addWidget(self.algInstructions,0,0) self.tabLayout.addWidget(self.normalModeDialog, 0, 1) self.tabLayout.addWidget(self.batchModeDialog, 0, 1) self.algMode = QtGui.QComboBox() self.algMode.addItems([NORMAL_MODE, BATCH_MODE]) if canEdit: self.algMode.connect(self.algMode, QtCore.SIGNAL("currentIndexChanged(QString)"), self.mainDialog.changeAlgMode) self.tabLayout.addWidget(self.algMode, 1, 1) else: self.buttonBox = QtGui.QDialogButtonBox() self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.backwardButton = QtGui.QPushButton() self.backwardButton.setText("< Previous step") self.buttonBox.addButton(self.backwardButton, QtGui.QDialogButtonBox.ActionRole) QtCore.QObject.connect(self.backwardButton, QtCore.SIGNAL("clicked()"), self.backward) self.forwardButton = QtGui.QPushButton() self.forwardButton.setText("Skip step >") self.buttonBox.addButton(self.forwardButton, QtGui.QDialogButtonBox.ActionRole) QtCore.QObject.connect(self.forwardButton, QtCore.SIGNAL("clicked()"), self.forward) self.closeButton = QtGui.QPushButton() self.closeButton.setText("Finish Workflow") self.buttonBox.addButton(self.closeButton, QtGui.QDialogButtonBox.ActionRole) QtCore.QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.close) self.tabLayout.addWidget(self.buttonBox, 1, 1) self.setLayout(self.tabLayout) self.executed = self.normalModeDialog.executed def forward(self): self.goForward = True self.close() def backward(self): self.goBackward = True self.close() def getMode(self): return self.algMode.currentText() def setMode(self, mode): if mode == NORMAL_MODE and not self.normalModeDialog.isVisible(): self.batchModeDialog.setHidden(True) self.normalModeDialog.setVisible(True) elif mode == BATCH_MODE and not self.batchModeDialog.isVisible(): self.normalModeDialog.setHidden(True) self.batchModeDialog.setVisible(True) self.resize(1050, 500) def getInstructions(self): return self.algInstructions.toPlainText() def setInstructions(self, instructions): self.algInstructions.setText(instructions) # not used for now def addRasterInputs(self, inputs): if self.getMode() == NORMAL_MODE: panelList = self.normalModeDialog.mainWidget.findChildren(InputLayerSelectorPanel) else: panelList = self.normalBatchDialog.mainWidget.findChildren(InputLayerSelectorPanel) for panel in panelList: comboBox = panel.text for myInput in inputs: comboBox.addItem(myInput, myInput)
def executeAlgorithmAsBatchProcess(self): alg = self.algorithmTree.selectedAlgorithm() if alg is not None: dlg = BatchAlgorithmDialog(alg) dlg.show() dlg.exec_()
def runAsBatch(self): dlg = BatchAlgorithmDialog(self.alg) dlg.exec_()
def __init__(self, alg, mainDialog, canEdit=True): self.alg = alg self.mainDialog = mainDialog self.goForward = False self.goBackward = False QtGui.QDialog.__init__(self) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMinMaxButtonsHint) # create a tab for this algorithm self.tabLayout = QtGui.QGridLayout() self.algInstructions = QtGui.QTextEdit() self.algInstructions.setMinimumWidth(250) self.algInstructions.setMaximumWidth(250) self.algInstructions.setFontPointSize(10) if not canEdit: self.algInstructions.setReadOnly(True) self.normalModeDialog = alg.getCustomParametersDialog() if not self.normalModeDialog: self.normalModeDialog = AlgorithmDialog(alg) self.batchModeDialog = BatchAlgorithmDialog(alg) self.batchModeDialog.setHidden(True) # forwardButton does the job of cancel/close button try: if self.alg.name == "Field calculator": self.normalModeDialog.mButtonBox.removeButton(self.normalModeDialog.mButtonBox.button(QtGui.QDialogButtonBox.Cancel)) else: self.normalModeDialog.buttonBox.removeButton(self.normalModeDialog.buttonBox.button(QtGui.QDialogButtonBox.Close)) self.batchModeDialog.buttonBox.removeButton(self.batchModeDialog.buttonBox.button(QtGui.QDialogButtonBox.Close)) # forwardButton does this job except: # Not all dialogs might have buttonBox pass if canEdit: try: self.normalModeDialog.progressBar.hide() self.batchModeDialog.progressBar.hide() if self.alg.name == "Field calculator": self.normalModeDialog.mButtonBox.hide() else: self.normalModeDialog.buttonBox.hide() self.batchModeDialog.buttonBox.hide() except: # Not all dialogs might have buttonBox pass self.normalModeDialog.connect(self.normalModeDialog, QtCore.SIGNAL("finished(int)"), self.forward) self.batchModeDialog.connect(self.batchModeDialog, QtCore.SIGNAL("finished(int)"), self.forward) self.tabLayout.addWidget(self.algInstructions,0,0) self.tabLayout.addWidget(self.normalModeDialog, 0, 1) self.tabLayout.addWidget(self.batchModeDialog, 0, 1) self.algMode = QtGui.QComboBox() self.algMode.addItems([NORMAL_MODE, BATCH_MODE]) if canEdit: self.algMode.connect(self.algMode, QtCore.SIGNAL("currentIndexChanged(QString)"), self.mainDialog.changeAlgMode) self.tabLayout.addWidget(self.algMode, 1, 1) else: self.buttonBox = QtGui.QDialogButtonBox() self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.backwardButton = QtGui.QPushButton() self.backwardButton.setText("< Previous step") self.buttonBox.addButton(self.backwardButton, QtGui.QDialogButtonBox.ActionRole) QtCore.QObject.connect(self.backwardButton, QtCore.SIGNAL("clicked()"), self.backward) self.forwardButton = QtGui.QPushButton() self.forwardButton.setText("Skip step >") self.buttonBox.addButton(self.forwardButton, QtGui.QDialogButtonBox.ActionRole) QtCore.QObject.connect(self.forwardButton, QtCore.SIGNAL("clicked()"), self.forward) self.closeButton = QtGui.QPushButton() self.closeButton.setText("Finish Workflow") self.buttonBox.addButton(self.closeButton, QtGui.QDialogButtonBox.ActionRole) QtCore.QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.close) self.tabLayout.addWidget(self.buttonBox, 1, 1) self.setLayout(self.tabLayout) self.executed = self.normalModeDialog.executed
def executeAlgorithm(self, alg_id, parent, in_place=False, as_batch=False): """Executes a project model with GUI interaction if needed. :param alg_id: algorithm id :type alg_id: string :param parent: parent widget :type parent: QWidget :param in_place: in place flag, defaults to False :type in_place: bool, optional :param as_batch: execute as batch flag, defaults to False :type as_batch: bool, optional """ config = {} if in_place: config['IN_PLACE'] = True alg = QgsApplication.instance().processingRegistry().createAlgorithmById(alg_id, config) if alg is not None: ok, message = alg.canExecute() if not ok: dlg = MessageDialog() dlg.setTitle(self.tr('Error executing algorithm')) dlg.setMessage( self.tr('<h3>This algorithm cannot ' 'be run :-( </h3>\n{0}').format(message)) dlg.exec_() return if as_batch: dlg = BatchAlgorithmDialog(alg, iface.mainWindow()) dlg.show() dlg.exec_() else: in_place_input_parameter_name = 'INPUT' if hasattr(alg, 'inputParameterName'): in_place_input_parameter_name = alg.inputParameterName() if in_place and not [d for d in alg.parameterDefinitions() if d.name() not in (in_place_input_parameter_name, 'OUTPUT')]: parameters = {} feedback = MessageBarProgress(algname=alg.displayName()) ok, results = execute_in_place(alg, parameters, feedback=feedback) if ok: iface.messageBar().pushSuccess('', self.tr('{algname} completed. %n feature(s) processed.', n=results['__count']).format(algname=alg.displayName())) feedback.close() # MessageBarProgress handles errors return if alg.countVisibleParameters() > 0: dlg = alg.createCustomParametersWidget(parent) if not dlg: dlg = AlgorithmDialog(alg, in_place, iface.mainWindow()) canvas = iface.mapCanvas() prevMapTool = canvas.mapTool() dlg.show() dlg.exec_() if canvas.mapTool() != prevMapTool: try: canvas.mapTool().reset() except Exception: pass canvas.setMapTool(prevMapTool) else: feedback = MessageBarProgress(algname=alg.displayName()) context = dataobjects.createContext(feedback) parameters = {} ret, results = execute(alg, parameters, context, feedback) handleAlgorithmResults(alg, context, feedback) feedback.close()
def _runProcessingBatch(): alg = QgsApplication.processingRegistry().createAlgorithmById( 'native:buffer') dlg = BatchAlgorithmDialog(alg.create(), parent=iface.mainWindow()) dlg.show() dlg.exec_()