From 2aba6484515b7f5962849feee13c97d53ab81565 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 3 May 2015 10:07:36 -0600 Subject: [PATCH] let user choose the theme --- gui/__init__.py | 1 + gui/params.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ gui/source.py | 13 +++++++++++ 3 files changed, 75 insertions(+) create mode 100644 gui/params.py diff --git a/gui/__init__.py b/gui/__init__.py index ecd60d1..eea8e1c 100644 --- a/gui/__init__.py +++ b/gui/__init__.py @@ -19,5 +19,6 @@ self_dir = os.path.abspath(os.path.dirname(__file__)) # Import anything that defines a command or parameter. import gui.commands +import gui.params import gui.toplevel import gui.framecache diff --git a/gui/params.py b/gui/params.py new file mode 100644 index 0000000..a5c5d11 --- /dev/null +++ b/gui/params.py @@ -0,0 +1,61 @@ +# 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 . + +# Parameters + +import gdb +from gi.repository import GtkSource +import gui.startup +from gui.startup import in_gdb_thread, in_gtk_thread + +class _SetBase(gdb.Command): + def __init__(self): + super(_SetBase, self).__init__('set gui', gdb.COMMAND_NONE, + prefix = True) + +class _ShowBase(gdb.Command): + def __init__(self): + super(_ShowBase, self).__init__('show gui', gdb.COMMAND_NONE, + prefix = True) + +class _Theme(gdb.Parameter): + def __init__(self): + self.manager = GtkSource.StyleSchemeManager.get_default() + super(_Theme, self).__init__('gui theme', gdb.COMMAND_NONE, + gdb.PARAM_ENUM, + # Probably the wrong thread. + self.manager.get_scheme_ids()) + + @in_gdb_thread + def set_buffer_manager(self, b): + self.buffer_manager = b + + @in_gtk_thread + def get_scheme(self): + # Sorta racy + return self.manager.get_scheme(self.value) + + @in_gdb_thread + def get_show_string(self, pvalue): + return "The current theme is: " + self.value + + @in_gdb_thread + def get_set_string(self): + self.buffer_manager.change_theme() + return "" + +_SetBase() +_ShowBase() +source_theme = _Theme() diff --git a/gui/source.py b/gui/source.py index 6a2f679..112c49f 100644 --- a/gui/source.py +++ b/gui/source.py @@ -26,6 +26,7 @@ import gui.toplevel import gui.events import os.path import gui.gdbutil +import gui.params from gi.repository import Gtk, GtkSource, GObject, Gdk, GdkPixbuf, Pango @@ -33,6 +34,7 @@ class BufferManager: def __init__(self): self.buffers = {} self.lang_manager = None + gui.params.source_theme.set_buffer_manager(self) def release_buffer(self, buff): # FIXME: we should be smart about buffer caching. @@ -63,6 +65,7 @@ class BufferManager: buff = GtkSource.Buffer() buff.set_language(self.lang_manager.guess_language(filename)) + buff.set_style_scheme(gui.params.source_theme.get_scheme()) buff.begin_not_undoable_action() try: contents = open(filename).read() @@ -79,6 +82,16 @@ class BufferManager: self.buffers[filename] = buff return buff + @in_gtk_thread + def _do_change_theme(self): + new_scheme = gui.params.source_theme.get_scheme() + for filename in self.buffers: + self.buffers[filename].set_style_scheme(new_scheme) + + @in_gdb_thread + def change_theme(self): + gui.startup.send_to_gtk(self._do_change_theme) + buffer_manager = BufferManager() # Return (FRAME, SYMTAB, FILE, LINE) for the selected frame, or, if