Skip to content

Commit

Permalink
Refactor gtk available_themes property
Browse files Browse the repository at this point in the history
  • Loading branch information
l0drex committed Apr 18, 2024
1 parent 2b409fe commit 04f7d81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
19 changes: 18 additions & 1 deletion yin_yang/plugins/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from abc import ABC, abstractmethod
from configparser import ConfigParser
from pathlib import Path
from typing import Optional
from typing import Optional, List

from PySide6.QtDBus import QDBusConnection, QDBusMessage
from PySide6.QtGui import QColor, QRgba64
Expand Down Expand Up @@ -365,3 +365,20 @@ def flatpak_user(app_id: str) -> Path:

def snap_path(app: str) -> Path:
return Path(f'/var/lib/snapd/snap/{app}/current')

def themes_from_theme_directories(type: str) -> List[Path]:
theme_directories = [
Path('/usr/share/themes'),
Path('/usr/local/share/themes'),
Path.home() / '.themes',
Path.home() / '.local/share/themes',
]

themes = []
for directory in theme_directories:
if not directory.is_dir():
continue

themes.extend(d.name for d in directory.iterdir() if d.is_dir() and (d / type).is_dir())

return themes
15 changes: 2 additions & 13 deletions yin_yang/plugins/gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@

from PySide6.QtDBus import QDBusMessage

from ._plugin import PluginDesktopDependent, PluginCommandline, DBusPlugin
from ._plugin import PluginDesktopDependent, PluginCommandline, DBusPlugin, themes_from_theme_directories
from .system import test_gnome_availability
from ..meta import Desktop

logger = logging.getLogger(__name__)


theme_directories = ['/usr/share/themes', f'{Path.home()}/.themes']


class Gtk(PluginDesktopDependent):
name = 'GTK'

Expand All @@ -40,15 +37,7 @@ def __init__(self, desktop: Desktop):

@property
def available_themes(self) -> dict:
themes = []

for directory in theme_directories:
if not path.isdir(directory):
continue

with scandir(directory) as entries:
themes.extend(d.name for d in entries if d.is_dir() and path.isdir(d.path + '/gtk-3.0'))

themes = themes_from_theme_directories('gtk-3.0')
return {t: t for t in themes}


Expand Down

0 comments on commit 04f7d81

Please sign in to comment.