def save(self, url=None, encoding=None): """Saves the document to the specified or current url. Currently only local files are supported. An IOError is raised when trying to save a nonlocal URL. If saving succeeds and an url was specified, the url is made the current url (by calling setUrl() internally). """ if url is None: url = QUrl() u = url if not url.isEmpty() else self.url() filename = u.toLocalFile() # currently, we do not support non-local files if not filename: raise IOError("not a local file") # keep the url if specified when we didn't have one, even if saving # would fail if self.url().isEmpty() and not url.isEmpty(): self.setUrl(url) with app.documentSaving(self): with open(filename, "wb") as f: f.write(self.encodedText()) f.flush() os.fsync(f.fileno()) self.setModified(False) if not url.isEmpty(): self.setUrl(url) self.saved() app.documentSaved(self)
def save(self, url=None, encoding=None): """Saves the document to the specified or current url. Currently only local files are supported. An IOError is raised when trying to save a nonlocal URL. If saving succeeds and an url was specified, the url is made the current url (by calling setUrl() internally). """ if url is None: url = QUrl() u = url if not url.isEmpty() else self.url() filename = u.toLocalFile() # currently, we do not support non-local files if not filename: raise IOError("not a local file") # keep the url if specified when we didn't have one, even if saving # would fail if self.url().isEmpty() and not url.isEmpty(): self.setUrl(url) with self.saving(), app.documentSaving(self): with open(filename, "wb") as f: f.write(self.encodedText()) f.flush() os.fsync(f.fileno()) self.setModified(False) if not url.isEmpty(): self.setUrl(url) self.saved() app.documentSaved(self)
def save(self): """Saves the document to the current url. Returns True if saving succeeded, False if an error occurred, and None when the current url is empty or non-local. Currently only local files are supported. """ with app.documentSaving(self): fileName = self.url().toLocalFile() if fileName: try: with open(fileName, "w") as f: f.write(self.encodedText()) f.flush() os.fsync(f.fileno()) except (IOError, OSError): return False self.setModified(False) self.saved() app.documentSaved(self) return True
def save(self, url=None, encoding=None): url, filename = super().save(url, encoding) with self.saving(), app.documentSaving(self): self._save(url, filename) self.saved() app.documentSaved(self)