def load(self, url=None, encoding=None, keepUndo=False): """Load the specified or current url (if None was specified). Currently only local files are supported. An IOError is raised when trying to load a nonlocal URL. If loading succeeds and an url was specified, the url is make the current url (by calling setUrl() internally). If keepUndo is True, the loading can be undone (with Ctrl-Z). """ if url is None: url = QUrl() u = url if not url.isEmpty() else self.url() text = self.load_data(u, encoding or self._encoding) if keepUndo: c = QTextCursor(self) c.select(QTextCursor.Document) c.insertText(text) else: self.setPlainText(text) self.setModified(False) if not url.isEmpty(): self.setUrl(url) self.loaded() app.documentLoaded(self)
def load(self, keepUndo=False): """Loads the current url. Returns True if loading succeeded, False if an error occurred, and None when the current url is empty or non-local. Currently only local files are supported. If keepUndo is True, the loading can be undone (with Ctrl-Z). """ fileName = self.url().toLocalFile() if fileName: try: with open(fileName) as f: data = f.read() except (IOError, OSError): return False # errors are caught in MainWindow.openUrl() text = util.decode(data) if keepUndo: c = QTextCursor(self) c.select(QTextCursor.Document) c.insertText(text) else: self.setPlainText(text) self.setModified(False) self.loaded() app.documentLoaded(self) return True
def new_from_url(cls, url, encoding=None): """Create and return a new document, loaded from url. This is intended to open a new Document without instantiating one if loading the contents fails. """ text = cls.load_data(url, encoding) d = cls(url, encoding) d.setPlainText(text) d.setModified(False) d.loaded() app.documentLoaded(d) return d
def new_from_url(cls, url, encoding=None): """Create and return a new document, loaded from url. This is intended to open a new Document without instantiating one if loading the contents fails. """ if not url.isEmpty(): text = cls.load_data(url, encoding) d = cls(url, encoding) if not url.isEmpty(): d.setPlainText(text) d.setModified(False) d.loaded() app.documentLoaded(d) return d
def load(self): """Loads the current url. Returns True if loading succeeded, False if an error occurred, and None when the current url is empty or non-local. Currently only local files are supported. """ fileName = self.url().toLocalFile() if fileName: try: with open(fileName) as f: data = f.read() except (IOError, OSError): return False # errors are caught in MainWindow.openUrl() self.setPlainText(util.decode(data)) self.setModified(False) self.loaded() app.documentLoaded(self) return True
def load(self, url=None, encoding=None, keepUndo=False): super(EditorDocument, self).load(url, encoding, keepUndo) self.loaded() app.documentLoaded(self)
def new_from_url(cls, url, encoding=None): d = super(EditorDocument, cls).new_from_url(url, encoding) if not url.isEmpty(): d.loaded() app.documentLoaded(d) return d