Exemplo n.º 1
0
 def gpapinput(self):
     """
     Load gpap database and collect field notes
     """
     options = QFileDialog.Options()
     options |= QFileDialog.DontUseNativeDialog
     gpapfile, _filter = QFileDialog.getOpenFileName(self.dlg,
                                                     "Select database", "",
                                                     "Geopaparazzi-Smash databases (*.gpap);;gpap Files (*.gpap)",
                                                     options=options)
     self.dlg.gpapinput.setText(gpapfile)
     con = sqlite3.connect(str(gpapfile))
     sel = 'SELECT * FROM' + ' ' + 'notes'
     notes = []
     with con:
         cur = con.cursor()
         cur.execute(sel)
         rows = cur.fetchall()
         for row in rows:
             jsnst = row[7]
             topy = json.loads(jsnst)
             notes.append(topy['sectionname'])
     frecuenciapalab = [notes.count(p) for p in notes]
     listanotas = dict(zip(notes, frecuenciapalab))
     aux = [(listanotas[key], key) for key in listanotas]
     aux.sort()
     aux.reverse()
     for dat in aux:
         self.dlg.formatosjson.addItem(dat[1])
Exemplo n.º 2
0
def selectFileNameToSave(
    line_edit_widget,
    title,
    file_filter,
    parent,
    extension,
    extensions,
    dont_confirm_overwrite,
):
    filename, matched_filter = QFileDialog.getSaveFileName(
        parent,
        title,
        line_edit_widget.text(),
        file_filter,
        options=QFileDialog.DontConfirmOverwrite
        if dont_confirm_overwrite
        else QFileDialog.Options(),
    )
    extension_valid = False

    if not extensions:
        extensions = [extension]

    if extensions:
        extension_valid = any(filename.endswith(ext) for ext in extensions)

    if not extension_valid and filename:
        filename = filename + extension

    line_edit_widget.setText(filename)
    def selectDirectory(self):
        # self.archivo = QtGui.QFileDialog.getOpenFileName(self, 'Abir Archivo')

        options = QFileDialog.Options()
        options |= QFileDialog.Directory
        options |= QFileDialog.ShowDirsOnly
        directory = QFileDialog.getExistingDirectory(self.dlg, "Elige un directorio", options=options)

        if directory:
            self.directorioAGuardar = directory
            self.dlg.fldDirectorio.setText(directory)
Exemplo n.º 4
0
    def savedata(self):
        try:
            layer = self.overlaylayer
        except:
            self.iface.messageBar().pushMessage(
                "Atitude correction",
                "Overlay layer does not exist - run overlay",
                level=Qgis.Critical,
                duration=3)
            return
        options = QFileDialog.Options()
        options |= QFileDialog.DontUseNativeDialog
        fileName, _ = QFileDialog.getSaveFileName(
            self.dlg,
            "Save tab separated data file",
            "",
            "data files (*.dat);;All Files (*)",
            options=options)
        if not fileName:
            return
        script = self.dlg.teRscript.toPlainText()
        scriptlines = script.split("\n")
        scriptlines[0] = 'filename="{}"'.format(fileName)
        self.dlg.teRscript.setText('\n'.join(scriptlines))

        features = layer.getFeatures()
        valueidx = layer.fields().indexFromName(
            self.dlg.fcbMeasure.currentField())
        altidx = layer.fields().indexFromName(
            self.dlg.fcbAltitude.currentField())
        typeidx = layer.fields().indexFromName(self.dlg.fcbArea.currentField())
        ididx = layer.fields().indexFromName("id")
        idfield = ididx >= 0
        id = 0
        sep = '\t'
        with open(fileName, "w") as outfile:
            outfile.write(sep.join(["id", "altitude", "measure", "type\n"]))
            for feat in features:
                attrs = feat.attributes()
                if idfield:
                    id = attrs[ididx]
                else:
                    id = +1
                linedata = [id, attrs[altidx], attrs[valueidx], attrs[typeidx]]
                linedata = [str(t) for t in linedata]
                outfile.write(sep.join(linedata))
                outfile.write("\n")
Exemplo n.º 5
0
 def saveImage(self):
     options = QFileDialog.Options()
     options |= QFileDialog.DontUseNativeDialog
     fileName, _ = QFileDialog.getSaveFileName(
         self,
         "QFileDialog.getSaveFileName()",
         "",
         "Image files (*.png);;All Files (*)",
         options=options)
     if not fileName:
         return
     # Get region of scene to capture from somewhere.
     area = self.scene().sceneRect()
     # Create a QImage to render to and fix up a QPainter for it.
     image = QImage(area.width(), area.height(),
                    QImage.Format_ARGB32_Premultiplied)
     painter = QPainter(image)
     # Render the region of interest to the QImage.
     self.scene().render(painter)
     painter.end()
     # Save the image to a file.
     image.save(fileName)