def openFile(self, path: str) -> None: f = QFile(path) if not f.open(QIODevice.ReadOnly): QMessageBox.warning( self, self.windowTitle(), self.tr("Could not open file %s: %s" % (QDir.toNativeSeparators(path), f.errorString())), ) return self.m_filePath = path self.editor.setPlainText(f.readAll().data().decode())
def onFileSave(self): if not self.m_filePath: self.onFileSaveAs() return f = QFile(self.m_filePath) if not f.open(QIODevice.WriteOnly | QIODevice.Text): QMessageBox.warning( self, self.windowTitle(), self.tr("Could not write to file %s: %s" % (QDir.toNativeSeparators( self.m_filePath), f.errorString())), ) return text = QTextStream(f) text << self.editor.toPlainText() self.editor.document().setModified(False)