Commit ece8c945 authored by Cosimo Cecchi's avatar Cosimo Cecchi Committed by John Stowers

Add a switch to globally enable the dark theme preference

https://bugzilla.gnome.org/show_bug.cgi?id=677803
parent b5fdc926
# 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
......@@ -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),
......
......@@ -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"))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment