[gnome-tweak-tool] Add a switch to globally enable the dark theme preference
- From: John Stowers <jstowers src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tweak-tool] Add a switch to globally enable the dark theme preference
- Date: Tue, 3 Jul 2012 16:17:14 +0000 (UTC)
commit ece8c9458b752d97d1918ae0ef2ebd541ae96308
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Jul 2 22:02:27 2012 -0400
Add a switch to globally enable the dark theme preference
https://bugzilla.gnome.org/show_bug.cgi?id=677803
gtweak/gtksettings.py | 56 ++++++++++++++++++++++++++++++++++++++
gtweak/tweaks/tweak_interface.py | 3 +-
gtweak/widgets.py | 26 +++++++++++++++++-
3 files changed, 83 insertions(+), 2 deletions(-)
---
diff --git a/gtweak/gtksettings.py b/gtweak/gtksettings.py
new file mode 100644
index 0000000..775b2d2
--- /dev/null
+++ b/gtweak/gtksettings.py
@@ -0,0 +1,56 @@
+# This file is part of gnome-tweak-tool.
+#
+# Copyright (c) 2012 Cosimo Cecchi
+#
+# gnome-tweak-tool 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.
+#
+# gnome-tweak-tool 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 gnome-tweak-tool. If not, see <http://www.gnu.org/licenses/>.
+
+import os.path
+
+from gi.repository import GLib
+
+import gtweak.utils
+
+SETTINGS_GROUP_NAME = "Settings"
+
+ gtweak utils singleton
+class GtkSettingsManager:
+ def __init__(self):
+ self._path = os.path.join(GLib.get_user_config_dir(),
+ "gtk-3.0",
+ "settings.ini")
+ def _get_keyfile(self):
+ keyfile = GLib.KeyFile()
+ try:
+ keyfile.load_from_file(self._path, 0)
+ finally:
+ return keyfile
+
+ def get_integer(self, key):
+ keyfile = self._get_keyfile()
+ try:
+ result = keyfile.get_integer(SETTINGS_GROUP_NAME, key)
+ except:
+ result = 0
+
+ return result
+
+ def set_integer(self, key, value):
+ keyfile = self._get_keyfile()
+ keyfile.set_integer(SETTINGS_GROUP_NAME, key, value)
+
+ try:
+ data = keyfile.to_data()
+ GLib.file_set_contents(self._path, data[0])
+ except:
+ raise
diff --git a/gtweak/tweaks/tweak_interface.py b/gtweak/tweaks/tweak_interface.py
index f6c7672..537ed48 100644
--- a/gtweak/tweaks/tweak_interface.py
+++ b/gtweak/tweaks/tweak_interface.py
@@ -22,7 +22,7 @@ from gi.repository import Gtk
import gtweak
from gtweak.utils import walk_directories, make_combo_list_with_default
from gtweak.tweakmodel import TWEAK_GROUP_THEME
-from gtweak.widgets import GSettingsSwitchTweak, GSettingsComboTweak
+from gtweak.widgets import GSettingsSwitchTweak, GSettingsComboTweak, DarkThemeSwitcher
class GtkThemeSwitcher(GSettingsComboTweak):
def __init__(self, **options):
@@ -98,6 +98,7 @@ class KeyThemeSwitcher(GSettingsComboTweak):
TWEAKS = (
GSettingsSwitchTweak("org.gnome.desktop.interface", "menus-have-icons", group_name=TWEAK_GROUP_THEME),
GSettingsSwitchTweak("org.gnome.desktop.interface", "buttons-have-icons", group_name=TWEAK_GROUP_THEME),
+ DarkThemeSwitcher(group_name=TWEAK_GROUP_THEME),
CursorThemeSwitcher(group_name=TWEAK_GROUP_THEME),
KeyThemeSwitcher(group_name=TWEAK_GROUP_THEME),
IconThemeSwitcher(group_name=TWEAK_GROUP_THEME),
diff --git a/gtweak/widgets.py b/gtweak/widgets.py
index 7982c74..84fc265 100644
--- a/gtweak/widgets.py
+++ b/gtweak/widgets.py
@@ -16,11 +16,13 @@
# along with gnome-tweak-tool. If not, see <http://www.gnu.org/licenses/>.
import logging
+import os.path
-from gi.repository import Gtk, Gdk, Gio, Pango
+from gi.repository import GLib, Gtk, Gdk, Gio, Pango
from gtweak.tweakmodel import Tweak
from gtweak.gsettings import GSettingsSetting, GSettingsFakeSetting, GSettingsMissingError
+from gtweak.gtksettings import GtkSettingsManager
from gtweak.gconf import GConfSetting
def build_label_beside_widget(txt, *widget, **kwargs):
@@ -277,3 +279,25 @@ class ZipFileChooserButton(Gtk.FileChooserButton):
#self.set_width_chars(15)
self.set_local_only(True)
+class DarkThemeSwitcher(Tweak):
+ def __init__(self, **options):
+ Tweak.__init__(self, _("Enable dark theme for all applications"),
+ _("Enable the dark theme hint for all the applications in the session"),
+ **options)
+
+ self._gtksettings = GtkSettingsManager()
+
+ w = Gtk.Switch()
+ w.set_active(self._gtksettings.get_integer("gtk-application-prefer-dark-theme"))
+
+ w.connect("notify::active", self._on_switch_changed)
+ self.widget = build_label_beside_widget(self.name, w)
+
+ def _on_switch_changed(self, switch, param):
+ active = switch.get_active()
+
+ try:
+ self._gtksettings.set_integer("gtk-application-prefer-dark-theme",
+ active)
+ except:
+ self.notify_error(_("Error writing setting"))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]