From 6ee0bec04adb6d08eabb6038c81fe8d27b860d1f Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 3 May 2015 17:21:10 -0600 Subject: [PATCH] add "set gui theme" --- gui/params.py | 6 ++++++ gui/storage.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 gui/storage.py diff --git a/gui/params.py b/gui/params.py index a5c5d11..bdb69f2 100644 --- a/gui/params.py +++ b/gui/params.py @@ -19,6 +19,7 @@ import gdb from gi.repository import GtkSource import gui.startup from gui.startup import in_gdb_thread, in_gtk_thread +import gui.storage class _SetBase(gdb.Command): def __init__(self): @@ -33,10 +34,14 @@ class _ShowBase(gdb.Command): class _Theme(gdb.Parameter): def __init__(self): self.manager = GtkSource.StyleSchemeManager.get_default() + self.storage = gui.storage.storage_manager super(_Theme, self).__init__('gui theme', gdb.COMMAND_NONE, gdb.PARAM_ENUM, # Probably the wrong thread. self.manager.get_scheme_ids()) + val = self.storage.get('theme') + if val is not None: + self.value = val @in_gdb_thread def set_buffer_manager(self, b): @@ -53,6 +58,7 @@ class _Theme(gdb.Parameter): @in_gdb_thread def get_set_string(self): + self.storage.set('theme', self.value) self.buffer_manager.change_theme() return "" diff --git a/gui/storage.py b/gui/storage.py new file mode 100644 index 0000000..3bb119a --- /dev/null +++ b/gui/storage.py @@ -0,0 +1,52 @@ +# Copyright (C) 2015 Tom Tromey + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Storage management. + +from gi.repository import GLib +import os +import errno +import ConfigParser +import atexit + +class StorageManager: + def __init__(self): + self.dir = os.path.join(GLib.get_user_config_dir(), 'gdb') + self.file = os.path.join(self.dir, 'settings') + try: + os.mkdir(self.dir, 0700) + except OSError as exc: + if exc.errno is not errno.EEXIST: + self.file = None + self.config = ConfigParser.RawConfigParser() + if self.file is not None: + self.config.read(self.file) + if not self.config.has_section('general'): + self.config.add_section('general') + atexit.register(self.write) + + def get(self, name): + if self.config.has_option('general', name): + return self.config.get('general', name) + return None + + def set(self, name, value): + self.config.set('general', name, value) + + def write(self): + with open(self.file, 'wb') as save_file: + self.config.write(save_file) + +storage_manager = StorageManager()