mirror of
https://github.com/tromey/gdb-gui.git
synced 2025-12-16 07:10:04 +01:00
add "set gui theme"
This commit is contained in:
@@ -19,6 +19,7 @@ import gdb
|
|||||||
from gi.repository import GtkSource
|
from gi.repository import GtkSource
|
||||||
import gui.startup
|
import gui.startup
|
||||||
from gui.startup import in_gdb_thread, in_gtk_thread
|
from gui.startup import in_gdb_thread, in_gtk_thread
|
||||||
|
import gui.storage
|
||||||
|
|
||||||
class _SetBase(gdb.Command):
|
class _SetBase(gdb.Command):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -33,10 +34,14 @@ class _ShowBase(gdb.Command):
|
|||||||
class _Theme(gdb.Parameter):
|
class _Theme(gdb.Parameter):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.manager = GtkSource.StyleSchemeManager.get_default()
|
self.manager = GtkSource.StyleSchemeManager.get_default()
|
||||||
|
self.storage = gui.storage.storage_manager
|
||||||
super(_Theme, self).__init__('gui theme', gdb.COMMAND_NONE,
|
super(_Theme, self).__init__('gui theme', gdb.COMMAND_NONE,
|
||||||
gdb.PARAM_ENUM,
|
gdb.PARAM_ENUM,
|
||||||
# Probably the wrong thread.
|
# Probably the wrong thread.
|
||||||
self.manager.get_scheme_ids())
|
self.manager.get_scheme_ids())
|
||||||
|
val = self.storage.get('theme')
|
||||||
|
if val is not None:
|
||||||
|
self.value = val
|
||||||
|
|
||||||
@in_gdb_thread
|
@in_gdb_thread
|
||||||
def set_buffer_manager(self, b):
|
def set_buffer_manager(self, b):
|
||||||
@@ -53,6 +58,7 @@ class _Theme(gdb.Parameter):
|
|||||||
|
|
||||||
@in_gdb_thread
|
@in_gdb_thread
|
||||||
def get_set_string(self):
|
def get_set_string(self):
|
||||||
|
self.storage.set('theme', self.value)
|
||||||
self.buffer_manager.change_theme()
|
self.buffer_manager.change_theme()
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|||||||
52
gui/storage.py
Normal file
52
gui/storage.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
# Copyright (C) 2015 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# 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()
|
||||||
Reference in New Issue
Block a user