8000 bin/meld: Add support for a dark theme, following the GtkSetting · ITCSsDeveloper/meld@f84e165 · GitHub
Skip to content

Commit f84e165

Browse files
committed
bin/meld: Add support for a dark theme, following the GtkSetting
This commit just loads the dark CSS if it's present; there still isn't any there. Since we're doing this, we also handle CSS files not being found and complain appropriately.
1 parent ff4024e commit f84e165

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

bin/meld

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,23 @@ def check_requirements():
174174

175175
def setup_resources():
176176
from gi.repository import GObject
177+
from gi.repository import GLib
177178
from gi.repository import Gtk
178179
from gi.repository import Gdk
179180

180181
GObject.threads_init()
181182
icon_dir = os.path.join(meld.conf.DATADIR, "icons")
182183
Gtk.IconTheme.get_default().append_search_path(icon_dir)
183-
css_file = os.path.join(meld.conf.DATADIR, "meld.css")
184+
185+
gtk_settings = Gtk.Settings.get_default()
186+
dark_theme = gtk_settings.get_property('gtk-application-prefer-dark-theme')
187+
css_name = "meld-dark" if dark_theme else "meld"
188+
css_file = os.path.join(meld.conf.DATADIR, css_name + ".css")
184189
provider = Gtk.CssProvider()
185-
provider.load_from_path(css_file)
190+
try:
191+
provider.load_from_path(css_file)
192+
except GLib.GError as err:
193+
print(_("Couldn't load Meld-specific CSS (%s)\n%s") % (css_file, err))
186194
Gtk.StyleContext.add_provider_for_screen(
187195
Gdk.Screen.get_default(), provider,
188196
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

0 commit comments

Comments
 (0)