Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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
Esempio n. 4
0
 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
Esempio n. 5
0
 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
Esempio n. 6
0
 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
Esempio n. 7
0
 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
Esempio n. 8
0
 def load(self, url=None, encoding=None, keepUndo=False):
     super(EditorDocument, self).load(url, encoding, keepUndo)
     self.loaded()
     app.documentLoaded(self)
Esempio n. 9
0
 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
Esempio n. 10
0
 def load(self, url=None, encoding=None, keepUndo=False):
     super(EditorDocument, self).load(url, encoding, keepUndo)
     self.loaded()
     app.documentLoaded(self)
Esempio n. 11
0
 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