Ejemplo n.º 1
0
    def saveFileAs(self):
        dir = QDir()
        docsPath = '{}/Documents'.format(dir.homePath())
        if not dir.exists(docsPath):
            docsPath = '{}/Documentos'.format(dir.homePath())

        #Regresa una tupla (filename, filter)
        filename = QFileDialog.getSaveFileName(self, 'Guardar como', docsPath,
                                               self.fileFilter)
        if not filename: return

        if self.filename:
            windowTitle = self.windowTitle().split('-')[0]
            self.setWindowTitle('{} - {}'.format(windowTitle, filename[0]))
        else:
            self.setWindowTitle('{} - {}'.format(self.windowTitle(),
                                                 filename[0]))

        self.filename = filename[0]

        file = QFile(self.filename)
        if not file.open(QIODevice.WriteOnly): return

        data = self.textContent.toPlainText()

        stream = QTextStream(file)
        stream.setCodec('UTF-8')
        stream << data

        file.flush()
        file.close()
        self.showMessage('Archivo guardado')
Ejemplo n.º 2
0
    def saveFile(self):
        if not self.filename:
            self.saveFileAs()
            return

        file = QFile(self.filename)
        if not file.open(QIODevice.WriteOnly): return

        data = self.textContent.toPlainText()

        stream = QTextStream(file)
        stream.setCodec('UTF-8')
        stream << data

        file.flush()
        file.close()
        self.showMessage('Archivo guardado')