Ejemplo n.º 1
0
 def __init__(self, theme_name):
     theme_filename = self._lookup_theme(theme_name)
     if not theme_filename:
         raise PyroomError(_('theme not found: %s') % theme_name)
     theme_file = ConfigParser.SafeConfigParser()
     theme_file.read(theme_filename)
     self.update(theme_file.items('theme'))
Ejemplo n.º 2
0
    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':'pyroom',
                            '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 PyroomError(errortext)
Ejemplo n.º 3
0
    def set_preferences(self, widget, data=None):
        """save preferences"""
        self.getcustomdata()
        self.autosavepref = self.autosave.get_active()
        if self.autosavepref == True:
            self.autosavepref = 1
        else:
            self.autosavepref = 0
        self.config.set("editor", "autosave", str(self.autosavepref))
        self.config.set("visual", "linespacing", str(int(self.linespacing)))

        autosave_time = self.autosave_spinbutton.get_value_as_int()
        self.config.set("editor", "autosavetime", str(autosave_time))

        if self.presetscombobox.get_active_text().lower() == 'custom':
            custom_theme = open(
                os.path.join(self.pyroom_config.themes_dir, 'custom.theme'),
                "w")
            self.customfile.set("theme", "background", self.bgname)
            self.customfile.set("theme", "foreground", self.colorname)
            self.customfile.set("theme", "textboxbg", self.textboxbgname)
            self.customfile.set("theme", "border", self.bordername)
            self.customfile.set("theme", "padding", str(self.paddingname))
            self.customfile.set("theme", "width", str(self.widthname))
            self.customfile.set("theme", "height", str(self.heightname))
            self.customfile.write(custom_theme)
        self.dlg.hide()
        try:
            config_file = open(
                os.path.join(self.pyroom_config.conf_dir, "pyroom.conf"), "w")
            self.config.write(config_file)
        except IOError:
            raise PyroomError(_("Could not save preferences file."))
Ejemplo n.º 4
0
    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
            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 PyroomError(errortext)
Ejemplo n.º 5
0
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 PyroomError(
                        _("Could not autosave file %s") % buf.filename)
            finally:
                backup_file.close()
Ejemplo n.º 6
0
 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 PyroomError(_('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()
Ejemplo n.º 7
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'], "pyroom.conf"), "w"
            )
            config.write(config_file)
        except IOError:
            raise PyroomError(_("Could not save preferences file."))
Ejemplo n.º 8
0
            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 PyroomError(errortext)
        except:
            raise PyroomError(_('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),