Add dark theme switch in preferences

This commit is contained in:
Philipp Hörist 2018-09-23 14:57:10 +02:00
parent 26b8125446
commit 0e0bb9e190
3 changed files with 40 additions and 6 deletions

View File

@ -1508,9 +1508,6 @@ $T will be replaced by auto-not-available timeout</property>
<property name="margin_bottom">18</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkFrame" id="frame3">
<property name="visible">True</property>
@ -1616,6 +1613,28 @@ $T will be replaced by auto-not-available timeout</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="enable_dark_theme">
<property name="label" translatable="yes">Enable dark theme</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_enable_dark_theme_toggled" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
@ -1640,9 +1659,6 @@ $T will be replaced by auto-not-available timeout</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="position">4</property>

View File

@ -24,6 +24,8 @@ from gajim.common import helpers
from gajim.common import configpaths
from gajim.common import config as c_config
from gajim.common import idle
from gajim.gtk.util import get_dark_theme
from gajim.gtk.util import set_dark_theme
from gajim.gtk.util import get_builder
from gajim.gtk import AspellDictError
from gajim.gtk.themes import Themes
@ -207,6 +209,9 @@ class Preferences(Gtk.ApplicationWindow):
st = app.config.get('use_transports_iconsets')
self.xml.get_object('transports_iconsets_checkbutton').set_active(st)
# Dark theme
self.xml.get_object('enable_dark_theme').set_active(get_dark_theme())
### Personal Events tab ###
# outgoing send chat state notifications
st = app.config.get('outgoing_chat_state_notifications')
@ -655,6 +660,9 @@ class Preferences(Gtk.ApplicationWindow):
self.on_checkbutton_toggled(widget, 'use_transports_iconsets')
gtkgui_helpers.reload_jabber_state_images()
def on_enable_dark_theme_toggled(self, widget):
set_dark_theme(widget.get_active())
def on_outgoing_chat_states_combobox_changed(self, widget):
active = widget.get_active()
old_value = app.config.get('outgoing_chat_state_notifications')

View File

@ -230,3 +230,13 @@ def convert_rgb_to_hex(rgb_string):
green = int(rgb.green * 255)
blue = int(rgb.blue * 255)
return '#%02x%02x%02x' % (red, green, blue)
def set_dark_theme(enable: bool) -> None:
settings = Gtk.Settings.get_default()
settings.set_property('gtk-application-prefer-dark-theme', enable)
def get_dark_theme() -> bool:
settings = Gtk.Settings.get_default()
return settings.get_property('gtk-application-prefer-dark-theme')