From ee978640866ac0a25038aa661e125b1d1722f45e Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Tue, 19 Jul 2022 23:26:28 +0300 Subject: [PATCH] [GtkUI] Add a way to change themes Currently, the only way to change the themes is by manually set a value in the command line or set it as env variable. Closes: https://dev.deluge-torrent.org/ticket/3536 Closes: https://github.com/deluge-torrent/deluge/pull/392 --- deluge/ui/gtk3/glade/preferences_dialog.ui | 79 ++++++++++++++++++++-- deluge/ui/gtk3/gtkui.py | 1 + deluge/ui/gtk3/mainwindow.py | 6 ++ deluge/ui/gtk3/preferences.py | 20 +++++- 4 files changed, 101 insertions(+), 5 deletions(-) diff --git a/deluge/ui/gtk3/glade/preferences_dialog.ui b/deluge/ui/gtk3/glade/preferences_dialog.ui index aa1531d75..44bcafe4c 100644 --- a/deluge/ui/gtk3/glade/preferences_dialog.ui +++ b/deluge/ui/gtk3/glade/preferences_dialog.ui @@ -429,6 +429,77 @@ 0 + + + True + False + 0 + none + + + True + False + 3 + 10 + + + True + False + + + Light + True + True + False + The light theme + True + True + + + False + True + 0 + + + + + Dark + True + True + False + The dark theme + True + radio_theme_light + + + False + True + 7 + 1 + + + + + + + + + True + False + Theme + + + + + + + + False + False + 5 + 1 + + True @@ -736,7 +807,7 @@ and daemon (does not apply in Standalone mode). False False 5 - 1 + 2 @@ -964,7 +1035,7 @@ and daemon (does not apply in Standalone mode). False True 5 - 2 + 3 @@ -1024,7 +1095,7 @@ and daemon (does not apply in Standalone mode). False False 5 - 3 + 4 @@ -1101,7 +1172,7 @@ and daemon (does not apply in Standalone mode). False True - 4 + 5 diff --git a/deluge/ui/gtk3/gtkui.py b/deluge/ui/gtk3/gtkui.py index 434d1b82b..0fbb5b773 100644 --- a/deluge/ui/gtk3/gtkui.py +++ b/deluge/ui/gtk3/gtkui.py @@ -84,6 +84,7 @@ except ImportError: DEFAULT_PREFS = { 'standalone': True, + 'dark_theme': False, 'interactive_add': True, 'focus_add_dialog': True, 'enable_system_tray': True, diff --git a/deluge/ui/gtk3/mainwindow.py b/deluge/ui/gtk3/mainwindow.py index e1e3bb342..84956f2cd 100644 --- a/deluge/ui/gtk3/mainwindow.py +++ b/deluge/ui/gtk3/mainwindow.py @@ -72,6 +72,12 @@ class MainWindow(component.Component): self.config = ConfigManager('gtk3ui.conf') self.main_builder = Gtk.Builder() + # Set theme + Gtk.Settings.get_default().set_property( + 'gtk-application-prefer-dark-theme', + self.config['dark_theme'], + ) + # Patch this GtkBuilder to avoid connecting signals from elsewhere # # Think about splitting up mainwindow gtkbuilder file into the necessary parts diff --git a/deluge/ui/gtk3/preferences.py b/deluge/ui/gtk3/preferences.py index a024a5958..cf303d75a 100644 --- a/deluge/ui/gtk3/preferences.py +++ b/deluge/ui/gtk3/preferences.py @@ -13,7 +13,7 @@ from hashlib import sha1 as sha from urllib.parse import urlparse from gi import require_version -from gi.repository import Gtk +from gi.repository import GObject, Gtk from gi.repository.Gdk import Color import deluge.common @@ -171,6 +171,14 @@ class Preferences(component.Component): # Radio buttons to choose between systray and appindicator self.builder.get_object('alignment_tray_type').set_visible(appindicator) + # Initialize a binding for dark theme + Gtk.Settings.get_default().bind_property( + 'gtk-application-prefer-dark-theme', + self.builder.get_object('radio_theme_dark'), + 'active', + GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE, + ) + from .gtkui import DEFAULT_PREFS self.COLOR_DEFAULTS = {} @@ -557,6 +565,9 @@ class Preferences(component.Component): self.builder.get_object('radio_thinclient').set_active( not self.gtkui_config['standalone'] ) + self.builder.get_object('radio_theme_dark').set_active( + self.gtkui_config['dark_theme'] + ) self.builder.get_object('chk_show_rate_in_title').set_active( self.gtkui_config['show_rate_in_title'] ) @@ -741,6 +752,9 @@ class Preferences(component.Component): ).get_active() # Interface tab # + new_gtkui_config['dark_theme'] = self.builder.get_object( + 'radio_theme_dark' + ).get_active() new_gtkui_config['enable_system_tray'] = self.builder.get_object( 'chk_use_tray' ).get_active() @@ -1074,6 +1088,10 @@ class Preferences(component.Component): def on_button_cancel_clicked(self, data): log.debug('on_button_cancel_clicked') + Gtk.Settings.get_default().set_property( + 'gtk-application-prefer-dark-theme', + self.gtkui_config['dark_theme'], + ) self.hide() return True