Ejemplo n.º 1
0
    def loadFile(self, fileName):
        qfile = QtCore.QFile(fileName)
        if not qfile.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text):
            QtWidgets.QMessageBox.warning(
                self, self.tr('MDI'),
                self.tr('Cannot read file %s:\n%s.') %
                (fileName, qfile.errorString()))
            return False

        instr = QtCore.QTextStream(qfile)
        QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
        self.setPlainText(instr.readAll())
        QtWidgets.QApplication.restoreOverrideCursor()

        self.setCurrentFile(fileName)
        return True
Ejemplo n.º 2
0
    def saveFile(self, fileName):
        qfile = QtCore.QFile(fileName)

        if not qfile.open(QtCore.QFile.WriteOnly | QtCore.QFile.Text):
            QtWidgets.QMessageBox.warning(
                self, self.tr('MDI'),
                self.tr('Cannot write file %s:\n%s.') %
                (fileName, qfile.errorString()))
            return False

        outstr = QtCore.QTextStream(qfile)
        QtCore.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
        outstr << self.toPlainText()
        QtCore.QApplication.restoreOverrideCursor()

        self.setCurrentFile(fileName)
        return True