Re: the directory for current theme used by Gtk
- From: Christoph Reiter <reiter christoph gmail com>
- To: Krister <thekswenson gmail com>
- Cc: python-hackers-list <python-hackers-list gnome org>
- Subject: Re: the directory for current theme used by Gtk
- Date: Sat, 9 Dec 2017 10:32:41 +0100
I use the following to get a list of available themes, maybe it's useful:
import os
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gio
def get_themes():
theme_dir = Gtk.rc_get_theme_dir()
theme_dirs = [theme_dir, os.path.join(os.path.expanduser("~"),
".themes")]
themes = set()
for theme_dir in theme_dirs:
try:
subdirs = os.listdir(theme_dir)
except OSError:
continue
for dir_ in subdirs:
gtk_dir = os.path.join(theme_dir, dir_, "gtk-3.0")
if os.path.isdir(gtk_dir):
themes.add(dir_)
try:
resource_themes = Gio.resources_enumerate_children(
"/org/gtk/libgtk/theme", 0)
except GLib.GError:
pass
else:
themes.update([t.rstrip("/") for t in resource_themes])
return themes
[
Date Prev][
Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]