def showSelectionDialog(self):
        if isinstance(self.output, OutputDirectory):
            self.selectDirectory()
            return

        filefilter = self.output.getFileFilter(self.alg)
        settings = QSettings()
        if settings.contains('/Processing/LastBatchOutputPath'):
            path = str(settings.value('/Processing/LastBatchOutputPath'))
        else:
            path = ''
        filename, selectedFileFilter = QFileDialog.getSaveFileName(self,
                                                                   self.tr('Save file'), path, filefilter)
        if filename:
            if not filename.lower().endswith(
                    tuple(re.findall("\*(\.[a-z]{1,10})", filefilter))):
                ext = re.search("\*(\.[a-z]{1,10})", selectedFileFilter)
                if ext:
                    filename += ext.group(1)
            settings.setValue('/Processing/LastBatchOutputPath', os.path.dirname(filename))
            dlg = AutofillDialog(self.alg)
            dlg.exec_()
            if dlg.mode is not None:
                try:
                    if dlg.mode == AutofillDialog.DO_NOT_AUTOFILL:
                        self.table.cellWidget(self.row,
                                              self.col).setValue(filename)
                    elif dlg.mode == AutofillDialog.FILL_WITH_NUMBERS:
                        n = self.table.rowCount() - self.row
                        for i in range(n):
                            name = filename[:filename.rfind('.')] \
                                + str(i + 1) + filename[filename.rfind('.'):]
                            self.table.cellWidget(i + self.row,
                                                  self.col).setValue(name)
                    elif dlg.mode == AutofillDialog.FILL_WITH_PARAMETER:
                        n = self.table.rowCount() - self.row
                        for i in range(n):
                            widget = self.table.cellWidget(i + self.row,
                                                           dlg.param)
                            param = self.alg.parameters[dlg.param]
                            if isinstance(param, (ParameterRaster,
                                                  ParameterVector, ParameterTable,
                                                  ParameterMultipleInput)):
                                s = str(widget.getText())
                                s = os.path.basename(s)
                                s = os.path.splitext(s)[0]
                            elif isinstance(param, ParameterBoolean):
                                s = str(widget.currentIndex() == 0)
                            elif isinstance(param, ParameterSelection):
                                s = str(widget.currentText())
                            elif isinstance(param, ParameterFixedTable):
                                s = str(widget.table)
                            else:
                                s = str(widget.text())
                            name = filename[:filename.rfind('.')] + s \
                                + filename[filename.rfind('.'):]
                            self.table.cellWidget(i + self.row,
                                                  self.col).setValue(name)
                except:
                    pass
Exemple #2
0
    def showSelectionDialog(self):
        if isinstance(self.output, OutputDirectory):
            self.selectDirectory()
            return

        filefilter = self.output.getFileFilter(self.alg)
        settings = QSettings()
        if settings.contains('/Processing/LastBatchOutputPath'):
            path = str(settings.value('/Processing/LastBatchOutputPath'))
        else:
            path = ''
        filename, selectedFileFilter = QFileDialog.getSaveFileName(self,
                                                                   self.tr('Save file'), path, filefilter)
        if filename:
            if not filename.lower().endswith(
                    tuple(re.findall("\*(\.[a-z]{1,10})", filefilter))):
                ext = re.search("\*(\.[a-z]{1,10})", selectedFileFilter)
                if ext:
                    filename += ext.group(1)
            settings.setValue('/Processing/LastBatchOutputPath', os.path.dirname(filename))
            dlg = AutofillDialog(self.alg)
            dlg.exec_()
            if dlg.mode is not None:
                try:
                    if dlg.mode == AutofillDialog.DO_NOT_AUTOFILL:
                        self.table.cellWidget(self.row,
                                              self.col).setValue(filename)
                    elif dlg.mode == AutofillDialog.FILL_WITH_NUMBERS:
                        n = self.table.rowCount() - self.row
                        for i in range(n):
                            name = filename[:filename.rfind('.')] \
                                + str(i + 1) + filename[filename.rfind('.'):]
                            self.table.cellWidget(i + self.row,
                                                  self.col).setValue(name)
                    elif dlg.mode == AutofillDialog.FILL_WITH_PARAMETER:
                        n = self.table.rowCount() - self.row
                        for i in range(n):
                            widget = self.table.cellWidget(i + self.row,
                                                           dlg.param)
                            param = self.alg.parameters[dlg.param]
                            if isinstance(param, (ParameterRaster,
                                                  ParameterVector, ParameterTable,
                                                  ParameterMultipleInput)):
                                s = str(widget.getText())
                                s = os.path.basename(s)
                                s = os.path.splitext(s)[0]
                            elif isinstance(param, ParameterBoolean):
                                s = str(widget.currentIndex() == 0)
                            elif isinstance(param, ParameterSelection):
                                s = str(widget.currentText())
                            elif isinstance(param, ParameterFixedTable):
                                s = str(widget.table)
                            else:
                                s = str(widget.text())
                            name = filename[:filename.rfind('.')] + s \
                                + filename[filename.rfind('.'):]
                            self.table.cellWidget(i + self.row,
                                                  self.col).setValue(name)
                except:
                    pass
    def showSelectionDialog(self):
        if isinstance(self.output, QgsProcessingParameterFolderDestination):
            self.selectDirectory()
            return

        filefilter = getFileFilter(self.output)
        settings = QgsSettings()
        if settings.contains('/Processing/LastBatchOutputPath'):
            path = str(settings.value('/Processing/LastBatchOutputPath'))
        else:
            path = ''
        filename, selectedFileFilter = QFileDialog.getSaveFileName(
            self, self.tr('Save File'), path, filefilter)
        if filename:
            if not filename.lower().endswith(
                    tuple(re.findall("\\*(\\.[a-z]{1,10})", filefilter))):
                ext = re.search("\\*(\\.[a-z]{1,10})", selectedFileFilter)
                if ext:
                    filename += ext.group(1)
            settings.setValue('/Processing/LastBatchOutputPath',
                              os.path.dirname(filename))
            dlg = AutofillDialog(self.alg)
            dlg.exec_()
            if dlg.mode is not None:
                if dlg.mode == AutofillDialog.DO_NOT_AUTOFILL:
                    self.table.cellWidget(self.row,
                                          self.col).setValue(filename)
                elif dlg.mode == AutofillDialog.FILL_WITH_NUMBERS:
                    n = self.table.rowCount() - self.row
                    for i in range(n):
                        name = filename[:filename.rfind('.')] \
                            + str(i + 1) + filename[filename.rfind('.'):]
                        self.table.cellWidget(i + self.row,
                                              self.col).setValue(name)
                elif dlg.mode == AutofillDialog.FILL_WITH_PARAMETER:
                    for row in range(self.row, self.table.rowCount()):
                        v = self.panel.valueForParameter(
                            row - 1, dlg.param_name)
                        param = self.alg.parameterDefinition(dlg.param_name)
                        if isinstance(param,
                                      (QgsProcessingParameterRasterLayer,
                                       QgsProcessingParameterFeatureSource,
                                       QgsProcessingParameterVectorLayer,
                                       QgsProcessingParameterMultipleLayers)):
                            if isinstance(v, QgsMapLayer):
                                s = v.name()
                            else:
                                s = os.path.basename(v)
                                s = os.path.splitext(s)[0]
                        elif isinstance(param, QgsProcessingParameterBoolean):
                            s = 'true' if v else 'false'
                        elif isinstance(param, QgsProcessingParameterEnum):
                            s = param.options()[v]
                        else:
                            s = str(v)
                        name = filename[:filename.rfind('.')] + s \
                            + filename[filename.rfind('.'):]
                        self.table.cellWidget(row, self.col).setValue(name)
Exemple #4
0
 def showSelectionDialog(self):
     filefilter = self.output.getFileFilter(self.alg)
     filename = QtGui.QFileDialog.getSaveFileName(self, "Save file", "",
                                                  filefilter)
     if filename:
         filename = unicode(filename)
         dlg = AutofillDialog(self.alg)
         dlg.exec_()
         if dlg.mode != None:
             try:
                 if dlg.mode == AutofillDialog.DO_NOT_AUTOFILL:
                     #self.text.setValue(filename)
                     self.table.cellWidget(self.row,
                                           self.col).setValue(filename)
                 elif dlg.mode == AutofillDialog.FILL_WITH_NUMBERS:
                     n = self.table.rowCount() - self.row
                     for i in range(n):
                         name = filename[:filename.rfind(".")] + str(
                             i + 1) + filename[filename.rfind("."):]
                         self.table.cellWidget(i + self.row,
                                               self.col).setValue(name)
                 elif dlg.mode == AutofillDialog.FILL_WITH_PARAMETER:
                     n = self.table.rowCount() - self.row
                     for i in range(n):
                         widget = self.table.cellWidget(
                             i + self.row, dlg.param)
                         param = self.alg.parameters[dlg.param]
                         if isinstance(
                                 param,
                             (ParameterRaster, ParameterVector,
                              ParameterTable, ParameterMultipleInput)):
                             s = unicode(widget.getText())
                             s = os.path.basename(s)
                             s = s[:s.rfind(".")]
                         elif isinstance(param, ParameterBoolean):
                             s = str(widget.currentIndex() == 0)
                         elif isinstance(param, ParameterSelection):
                             s = unicode(widget.currentText())
                         elif isinstance(param, ParameterFixedTable):
                             s = unicode(widget.table)
                         else:
                             s = unicode(widget.text())
                         name = filename[:filename.rfind(
                             ".")] + s + filename[filename.rfind("."):]
                         self.table.cellWidget(i + self.row,
                                               self.col).setValue(name)
             except:
                 pass
 def showSelectionDialog(self):
     filefilter = self.output.getFileFilter(self.alg)
     filename = QtGui.QFileDialog.getSaveFileName(self, self.tr('Save file'), '',
             filefilter)
     if filename:
         filename = unicode(filename)
         dlg = AutofillDialog(self.alg)
         dlg.exec_()
         if dlg.mode is not None:
             try:
                 if dlg.mode == AutofillDialog.DO_NOT_AUTOFILL:
                     self.table.cellWidget(self.row,
                             self.col).setValue(filename)
                 elif dlg.mode == AutofillDialog.FILL_WITH_NUMBERS:
                     n = self.table.rowCount() - self.row
                     for i in range(n):
                         name = filename[:filename.rfind('.')] \
                             + str(i + 1) + filename[filename.rfind('.'):]
                         self.table.cellWidget(i + self.row,
                                 self.col).setValue(name)
                 elif dlg.mode == AutofillDialog.FILL_WITH_PARAMETER:
                     n = self.table.rowCount() - self.row
                     for i in range(n):
                         widget = self.table.cellWidget(i + self.row,
                                 dlg.param)
                         param = self.alg.parameters[dlg.param]
                         if isinstance(param, (ParameterRaster,
                                 ParameterVector, ParameterTable,
                                 ParameterMultipleInput)):
                             s = unicode(widget.getText())
                             s = os.path.basename(s)
                             s = os.path.splitext()[0]
                         elif isinstance(param, ParameterBoolean):
                             s = str(widget.currentIndex() == 0)
                         elif isinstance(param, ParameterSelection):
                             s = unicode(widget.currentText())
                         elif isinstance(param, ParameterFixedTable):
                             s = unicode(widget.table)
                         else:
                             s = unicode(widget.text())
                         name = filename[:filename.rfind('.')] + s \
                             + filename[filename.rfind('.'):]
                         self.table.cellWidget(i + self.row,
                                 self.col).setValue(name)
             except:
                 pass
Exemple #6
0
    def showSelectionDialog(self):
        if isinstance(self.output, QgsProcessingParameterFolderDestination):
            self.selectDirectory()
            return

        filefilter = self.output.createFileFilter()
        settings = QgsSettings()
        if settings.contains('/Processing/LastBatchOutputPath'):
            path = str(settings.value('/Processing/LastBatchOutputPath'))
        else:
            path = ''
        filename, selectedFileFilter = QFileDialog.getSaveFileName(
            self, self.tr('Save File'), path, filefilter)
        if filename:
            if not filename.lower().endswith(
                    tuple(re.findall("\\*(\\.[a-z]{1,10})", filefilter))):
                ext = re.search("\\*(\\.[a-z]{1,10})", selectedFileFilter)
                if ext:
                    filename += ext.group(1)
            settings.setValue('/Processing/LastBatchOutputPath',
                              os.path.dirname(filename))
            dlg = AutofillDialog(self.alg)
            dlg.exec_()
            if dlg.mode is not None:
                if dlg.mode == AutofillDialog.DO_NOT_AUTOFILL:
                    self.table.cellWidget(self.row,
                                          self.col).setValue(filename)
                elif dlg.mode == AutofillDialog.FILL_WITH_NUMBERS:
                    n = self.table.rowCount() - self.row
                    for i in range(n):
                        name = filename[:filename.rfind('.')] \
                            + str(i + 1) + filename[filename.rfind('.'):]
                        self.table.cellWidget(i + self.row,
                                              self.col).setValue(name)
                elif dlg.mode == AutofillDialog.FILL_WITH_PARAMETER:
                    for row in range(self.row, self.table.rowCount()):
                        v = self.panel.valueForParameter(
                            row - 1, dlg.param_name)
                        param = self.alg.parameterDefinition(dlg.param_name)
                        if isinstance(param,
                                      (QgsProcessingParameterRasterLayer,
                                       QgsProcessingParameterFeatureSource,
                                       QgsProcessingParameterVectorLayer,
                                       QgsProcessingParameterMultipleLayers,
                                       QgsProcessingParameterMapLayer)):
                            if isinstance(v, QgsMapLayer):
                                s = v.name()
                            else:
                                if v in QgsProject.instance().mapLayers():
                                    layer = QgsProject.instance().mapLayer(v)
                                    # value is a layer ID, but we'd prefer to show a layer name if it's unique in the project
                                    if len([
                                            l for _, l in QgsProject.instance(
                                            ).mapLayers().items()
                                            if l.name().lower() ==
                                            layer.name().lower()
                                    ]) == 1:
                                        s = layer.name()
                                    else:
                                        # otherwise fall back to layer id
                                        s = v
                                else:
                                    # else try to use file base name
                                    # TODO: this is bad for database sources!!
                                    s = os.path.basename(v)
                                    s = os.path.splitext(s)[0]
                        elif isinstance(param, QgsProcessingParameterBoolean):
                            s = 'true' if v else 'false'
                        elif isinstance(param, QgsProcessingParameterEnum):
                            s = param.options()[v]
                        else:
                            s = str(v)
                        name = filename[:filename.rfind('.')] + s \
                            + filename[filename.rfind('.'):]
                        self.table.cellWidget(row, self.col).setValue(name)