def set_filename(self, filename): """Opens filename. Returns ``True`` if the file was successfully opened. Otherwise ``False``. """ msg = None if not os.path.isfile(filename): msg = _(u'No such file: %(name)s') elif not os.access(filename, os.R_OK): msg = _(u'File is not readable: %(name)s') if msg is not None: dialogs.error(_(u"Failed to open file"), msg % {'name': filename}) return False self._filename = filename if filename: f = open(self._filename) a = f.read() f.close() else: a = "" self._filecontent_read = a self.set_text(a) self.app.recent_manager.add_item(to_uri(filename)) return True
def save_file(self, parent=None, default_name=None): if not self._filename: return self.save_file_as(parent=parent, default_name=default_name) buffer = self.get_buffer() a = buffer.get_text(*buffer.get_bounds()) f = open(self._filename, "w") f.write(a) f.close() self.app.recent_manager.add_item(to_uri(self._filename)) self._filecontent_read = a gobject.idle_add(buffer.emit, "changed") return True