diff options
author | DjLegolas <djlegolas@protonmail.com> | 2022-07-19 22:26:28 +0200 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2024-02-19 18:49:04 +0100 |
commit | ee978640866ac0a25038aa661e125b1d1722f45e (patch) | |
tree | bfcb8acc18aa98d4ba86f4571054fa4f007d7f8b | |
parent | [WebUI] Add a way to change themes (diff) | |
download | deluge-ee978640866ac0a25038aa661e125b1d1722f45e.tar.xz deluge-ee978640866ac0a25038aa661e125b1d1722f45e.zip |
[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
-rw-r--r-- | deluge/ui/gtk3/glade/preferences_dialog.ui | 79 | ||||
-rw-r--r-- | deluge/ui/gtk3/gtkui.py | 1 | ||||
-rw-r--r-- | deluge/ui/gtk3/mainwindow.py | 6 | ||||
-rw-r--r-- | 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 @@ -430,6 +430,77 @@ </packing> </child> <child> + <object class="GtkFrame" id="frame_theme"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <child> + <object class="GtkAlignment" id="alignment_theme"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="top_padding">3</property> + <property name="left_padding">10</property> + <child> + <object class="GtkBox" id="hbox_theme"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkRadioButton" id="radio_theme_light"> + <property name="label" translatable="yes">Light</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="tooltip_text" translatable="yes">The light theme</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="radio_theme_dark"> + <property name="label" translatable="yes">Dark</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="tooltip_text" translatable="yes">The dark theme</property> + <property name="draw_indicator">True</property> + <property name="group">radio_theme_light</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="padding">7</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> + </child> + <child type="label"> + <object class="GtkLabel" id="label_theme"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Theme</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="padding">5</property> + <property name="position">1</property> + </packing> + </child> + <child> <object class="GtkFrame" id="frame29"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -736,7 +807,7 @@ and daemon (does not apply in Standalone mode).</property> <property name="expand">False</property> <property name="fill">False</property> <property name="padding">5</property> - <property name="position">1</property> + <property name="position">2</property> </packing> </child> <child> @@ -964,7 +1035,7 @@ and daemon (does not apply in Standalone mode).</property> <property name="expand">False</property> <property name="fill">True</property> <property name="padding">5</property> - <property name="position">2</property> + <property name="position">3</property> </packing> </child> <child> @@ -1024,7 +1095,7 @@ and daemon (does not apply in Standalone mode).</property> <property name="expand">False</property> <property name="fill">False</property> <property name="padding">5</property> - <property name="position">3</property> + <property name="position">4</property> </packing> </child> <child> @@ -1101,7 +1172,7 @@ and daemon (does not apply in Standalone mode).</property> <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">4</property> + <property name="position">5</property> </packing> </child> </object> 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 |