Commit 878b4c0d by Jascha Geerds Committed by Jeremy Bicha

appearance: Search for themes and icons in system data dirs

parent c39ae9fd
......@@ -13,7 +13,7 @@ from gi.repository import Gtk
from gi.repository import GLib
import gtweak
from gtweak.utils import walk_directories, make_combo_list_with_default, extract_zip_file
from gtweak.utils import walk_directories, make_combo_list_with_default, extract_zip_file, get_resource_dirs
from gtweak.tweakmodel import Tweak
from gtweak.gshellwrapper import GnomeShellFactory
from gtweak.gsettings import GSettingsSetting
......@@ -41,11 +41,8 @@ class GtkThemeSwitcher(GSettingsComboTweak):
if gtk_ver % 2: # Want even number
gtk_ver += 1
dirs = ( os.path.join(gtweak.DATA_DIR, "themes"),
os.path.join(GLib.get_user_data_dir(), "themes"),
os.path.join(os.path.expanduser("~"), ".themes"))
valid = ['Adwaita', 'HighContrast', 'HighContrastInverse']
valid += walk_directories(dirs, lambda d:
valid += walk_directories(get_resource_dirs("themes"), lambda d:
os.path.exists(os.path.join(d, "gtk-3.0", "gtk.css")) or \
os.path.exists(os.path.join(d, "gtk-3.{}".format(gtk_ver))))
return set(valid)
......@@ -76,10 +73,7 @@ class IconThemeSwitcher(GSettingsComboTweak):
**options)
def _get_valid_icon_themes(self):
dirs = ( os.path.join(gtweak.DATA_DIR, "icons"),
os.path.join(GLib.get_user_data_dir(), "icons"),
os.path.join(os.path.expanduser("~"), ".icons"))
valid = walk_directories(dirs, lambda d:
valid = walk_directories(get_resource_dirs("icons"), lambda d:
os.path.isdir(d) and \
os.path.exists(os.path.join(d, "index.theme")))
return set(valid)
......@@ -94,10 +88,7 @@ class CursorThemeSwitcher(GSettingsComboTweak):
**options)
def _get_valid_cursor_themes(self):
dirs = ( os.path.join(gtweak.DATA_DIR, "icons"),
os.path.join(GLib.get_user_data_dir(), "icons"),
os.path.join(os.path.expanduser("~"), ".icons"))
valid = walk_directories(dirs, lambda d:
valid = walk_directories(get_resource_dirs("icons"), lambda d:
os.path.isdir(d) and \
os.path.exists(os.path.join(d, "cursors")))
return set(valid)
......
......@@ -8,6 +8,7 @@ import tempfile
import shutil
import subprocess
import glob
import itertools
import gtweak
from gtweak.gsettings import GSettingsSetting
......@@ -104,6 +105,22 @@ def execute_subprocess(cmd_then_args, block=True):
stdout, stderr = p.communicate()
return stdout, stderr, p.returncode
def get_resource_dirs(resource):
"""Returns a list of all known resource dirs for a given resource.
:param str resource:
Name of the resource (e.g. "themes")
:return:
A list of resource dirs
"""
dirs = [os.path.join(dir, resource)
for dir in itertools.chain(GLib.get_system_data_dirs(),
(gtweak.DATA_DIR,
GLib.get_user_data_dir()))]
dirs += [os.path.join(os.path.expanduser("~"), ".{}".format(resource))]
return [dir for dir in dirs if os.path.isdir(dir)]
@singleton
class AutostartManager:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment