コード例 #1
0
ファイル: basic_edit.py プロジェクト: zencephalon/DeftDraft-1
    def save_file(self):
        """ Save file """
        try:
            buf = self.buffers[self.current]
            if buf.filename != FILE_UNNAMED:
                buffer_file = open(buf.filename, 'w')
                txt = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
                buffer_file.write(txt)
                if self.recent_manager:
                    self.recent_manager.add_full(
                        "file://" + urllib.quote(buf.filename), {
                            'mime_type': 'text/plain',
                            'app_name': 'cdraft',
                            'app_exec': '%F',
                            'is_private': False,
                            'display_name': os.path.basename(buf.filename),
                        })
                buffer_file.close()
                #buf.begin_not_undoable_action()
                #buf.end_not_undoable_action()
                self.status.set_text(_('File %s saved') % buf.filename)
            else:
                self.save_file_as()
                return
        except IOError, (errno, strerror):
            errortext = _('Unable to save %(filename)s.') % {
                'filename': buf.filename
            }
            if errno == 13:
                errortext += _(' You do not have permission to write to \
the file.')
            raise CDraftError(errortext)
コード例 #2
0
ファイル: gui.py プロジェクト: zencephalon/DeftDraft-1
 def __init__(self, theme_name):
     dict.__init__(self)
     theme_filename = self._lookup_theme(theme_name)
     if not theme_filename:
         raise CDraftError(_('theme not found: %s') % theme_name)
     theme_file = ConfigParser.SafeConfigParser()
     theme_file.read(theme_filename)
     self.update(theme_file.items('theme'))
コード例 #3
0
ファイル: autosave.py プロジェクト: zencephalon/DeftDraft-1
def autosave(edit_instance):
    """save all open files that have been saved before"""
    for buf in edit_instance.buffers:
        if not buf.filename == edit_instance.UNNAMED_FILENAME:
            backup_file = open(get_autosave_filename(buf.filename), 'w')
            try:
                try:
                    backup_file.write(
                        buf.get_text(buf.get_start_iter(), buf.get_end_iter()))
                except IOError:
                    raise CDraftError(
                        _("Could not autosave file %s") % buf.filename)
            finally:
                backup_file.close()
コード例 #4
0
ファイル: basic_edit.py プロジェクト: zencephalon/DeftDraft-1
 def close_buffer(self):
     """ Close current buffer """
     autosave_fname = autosave.get_autosave_filename(
         self.buffers[self.current].filename)
     if os.path.isfile(autosave_fname):
         try:
             os.remove(autosave_fname)
         except OSError:
             raise CDraftError(_('Could not delete autosave file.'))
     if len(self.buffers) > 1:
         self.buffers.pop(self.current)
         self.current = min(len(self.buffers) - 1, self.current)
         self.set_buffer(self.current)
     else:
         quit()
コード例 #5
0
    def set_preferences(self, widget, data=None):
        """save preferences"""
        autosavepref = int(self.autosave.get_active())
        config.set("editor", "autosave", str(autosavepref))
        autosave_time = self.autosave_spinbutton.get_value_as_int()
        config.set("editor", "autosavetime", str(autosave_time))

        if self.presetscombobox.get_active_text().lower() == 'custom':
            custom_theme = open(
                os.path.join(state['themes_dir'], 'custom.theme'), "w")
            self.customfile.write(custom_theme)
        self.dlg.hide()
        try:
            config_file = open(os.path.join(state['conf_dir'], "cdraft.conf"),
                               "w")
            config.write(config_file)
        except IOError:
            raise CDraftError(_("Could not save preferences file."))
コード例 #6
0
ファイル: basic_edit.py プロジェクト: zencephalon/DeftDraft-1
    def open_file_no_chooser(self, filename):
        """ Open specified file """
        def check_backup(filename):
            """check if restore from backup is an option

            returns backup filename if there's a backup file and
                    user wants to restore from it, else original filename
            """
            fname = autosave.get_autosave_filename(filename)
            if os.path.isfile(fname):
                if self.ask_restore():
                    return fname
                else:
                    os.remove(fname)
            return filename

        buf = self.new_buffer()
        buf.filename = filename
        filename_to_open = check_backup(filename)

        try:
            buffer_file = open(filename_to_open, 'r')
            buf = self.buffers[self.current]
            #buf.begin_not_undoable_action()
            utf8 = unicode(buffer_file.read(), 'utf-8')
            buf.set_text(utf8)
            #buf.end_not_undoable_action()
            buffer_file.close()
        except IOError, (errno, strerror):
            errortext = _('Unable to open %(filename)s.') % {
                'filename': filename_to_open
            }
            if errno == 13:
                errortext += _(' You do not have permission to open \
the file.')
            if not errno == 2:
                raise CDraftError(errortext)
コード例 #7
0
ファイル: basic_edit.py プロジェクト: zencephalon/DeftDraft-1
            #buf.begin_not_undoable_action()
            utf8 = unicode(buffer_file.read(), 'utf-8')
            buf.set_text(utf8)
            #buf.end_not_undoable_action()
            buffer_file.close()
        except IOError, (errno, strerror):
            errortext = _('Unable to open %(filename)s.') % {
                'filename': filename_to_open
            }
            if errno == 13:
                errortext += _(' You do not have permission to open \
the file.')
            if not errno == 2:
                raise CDraftError(errortext)
        except:
            raise CDraftError(_('Unable to open %s\n') % filename_to_open)
        else:
            self.status.set_text(_('File %s open') % filename_to_open)

    def save_file(self):
        """ Save file """
        try:
            buf = self.buffers[self.current]
            if buf.filename != FILE_UNNAMED:
                buffer_file = open(buf.filename, 'w')
                txt = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
                buffer_file.write(txt)
                if self.recent_manager:
                    self.recent_manager.add_full(
                        "file://" + urllib.quote(buf.filename), {
                            'mime_type': 'text/plain',