[SCRIPT] Updated
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
|
||||
import asyncio
|
||||
from gi.repository import GLib # type: ignore
|
||||
from jinja2 import Template
|
||||
from PIL import Image
|
||||
from materialyoucolor.quantize import QuantizeCelebi
|
||||
@@ -12,10 +13,8 @@ from materialyoucolor.score.score import Score
|
||||
from ignis.utils import Utils
|
||||
from ignis.app import IgnisApp
|
||||
from ignis.base_service import BaseService
|
||||
from ignis.services.wallpaper import CACHE_WALLPAPER_PATH
|
||||
from gi.repository import GObject # type: ignore
|
||||
from ignis.services.wallpaper import WallpaperService
|
||||
from ignis.services.options import OptionsService
|
||||
from ignis.options import options
|
||||
from user_options import user_options
|
||||
|
||||
from .constants import MATERIAL_CACHE_DIR, TEMPLATES, SAMPLE_WALL
|
||||
from .util import rgba_to_hex, calculate_optimal_size
|
||||
@@ -27,39 +26,19 @@ class MaterialService(BaseService):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self._wallpaper = WallpaperService.get_default()
|
||||
|
||||
options = OptionsService.get_default()
|
||||
opt_group = options.create_group(name="material", exists_ok=True)
|
||||
self._dark_mode_opt = opt_group.create_option(
|
||||
name="dark_mode", default=True, exists_ok=True
|
||||
)
|
||||
self._colors_opt = opt_group.create_option(
|
||||
name="colors", default={}, exists_ok=True
|
||||
)
|
||||
|
||||
if not os.path.exists(CACHE_WALLPAPER_PATH):
|
||||
if not options.wallpaper.wallpaper_path:
|
||||
self.__on_colors_not_found()
|
||||
if self.colors == {}:
|
||||
if user_options.material.colors == {}:
|
||||
self.__on_colors_not_found()
|
||||
|
||||
@GObject.Property
|
||||
def dark_mode(self) -> bool:
|
||||
return self._dark_mode_opt.value
|
||||
|
||||
@dark_mode.setter
|
||||
def dark_mode(self, value: bool) -> None:
|
||||
self._dark_mode_opt.value = value
|
||||
self.generate_colors(CACHE_WALLPAPER_PATH)
|
||||
|
||||
@GObject.Property
|
||||
def colors(self) -> dict:
|
||||
return self._colors_opt.value
|
||||
user_options.material.connect_option(
|
||||
"dark_mode", lambda: self.generate_colors(options.wallpaper.wallpaper_path)
|
||||
)
|
||||
|
||||
def __on_colors_not_found(self) -> None:
|
||||
self._wallpaper.set_wallpaper(SAMPLE_WALL)
|
||||
options.wallpaper.set_wallpaper_path(SAMPLE_WALL)
|
||||
self.generate_colors(SAMPLE_WALL)
|
||||
Utils.exec_sh_async("hyprctl reload")
|
||||
asyncio.create_task(Utils.exec_sh_async("hyprctl reload"))
|
||||
|
||||
def get_colors_from_img(self, path: str, dark_mode: bool) -> dict[str, str]:
|
||||
image = Image.open(path)
|
||||
@@ -88,17 +67,17 @@ class MaterialService(BaseService):
|
||||
return material_colors
|
||||
|
||||
def generate_colors(self, path: str) -> None:
|
||||
colors = self.get_colors_from_img(path, self.dark_mode)
|
||||
colors = self.get_colors_from_img(path, user_options.material.dark_mode)
|
||||
dark_colors = self.get_colors_from_img(path, True)
|
||||
self._colors_opt.value = colors
|
||||
user_options.material.colors = colors
|
||||
self.__render_templates(colors, dark_colors)
|
||||
self.__setup(path)
|
||||
asyncio.create_task(self.__setup(path))
|
||||
|
||||
def __render_templates(self, colors: dict, dark_colors: dict) -> None:
|
||||
for template in os.listdir(TEMPLATES):
|
||||
self.render_template(
|
||||
colors=colors,
|
||||
dark_mode=self.dark_mode,
|
||||
dark_mode=user_options.material.dark_mode,
|
||||
input_file=f"{TEMPLATES}/{template}",
|
||||
output_file=f"{MATERIAL_CACHE_DIR}/{template}",
|
||||
)
|
||||
@@ -119,7 +98,7 @@ class MaterialService(BaseService):
|
||||
dark_mode: bool | None = None,
|
||||
) -> None:
|
||||
if dark_mode is None:
|
||||
colors["dark_mode"] = str(self.dark_mode).lower()
|
||||
colors["dark_mode"] = str(user_options.material.dark_mode).lower()
|
||||
else:
|
||||
colors["dark_mode"] = str(dark_mode).lower()
|
||||
with open(input_file) as file:
|
||||
@@ -128,17 +107,20 @@ class MaterialService(BaseService):
|
||||
with open(output_file, "w") as file:
|
||||
file.write(template_rendered)
|
||||
|
||||
def __reload_gtk_theme(self) -> None:
|
||||
async def __reload_gtk_theme(self) -> None:
|
||||
THEME_CMD = "gsettings set org.gnome.desktop.interface gtk-theme {}"
|
||||
COLOR_SCHEME_CMD = "gsettings set org.gnome.desktop.interface color-scheme {}"
|
||||
Utils.exec_sh_async(THEME_CMD.format("Adwaita"))
|
||||
Utils.exec_sh_async(THEME_CMD.format("Material"))
|
||||
Utils.exec_sh_async(COLOR_SCHEME_CMD.format("default"))
|
||||
Utils.exec_sh_async(COLOR_SCHEME_CMD.format("prefer-dark"))
|
||||
Utils.exec_sh_async(COLOR_SCHEME_CMD.format("default"))
|
||||
await Utils.exec_sh_async(THEME_CMD.format("Adwaita"))
|
||||
await Utils.exec_sh_async(THEME_CMD.format("Material"))
|
||||
await Utils.exec_sh_async(COLOR_SCHEME_CMD.format("default"))
|
||||
await Utils.exec_sh_async(COLOR_SCHEME_CMD.format("prefer-dark"))
|
||||
await Utils.exec_sh_async(COLOR_SCHEME_CMD.format("default"))
|
||||
|
||||
def __setup(self, image_path: str) -> None:
|
||||
Utils.exec_sh_async("pkill -SIGUSR1 kitty")
|
||||
self._wallpaper.set_wallpaper(image_path)
|
||||
async def __setup(self, image_path: str) -> None:
|
||||
try:
|
||||
await Utils.exec_sh_async("pkill -SIGUSR1 kitty")
|
||||
except GLib.Error:
|
||||
...
|
||||
options.wallpaper.set_wallpaper_path(image_path)
|
||||
app.reload_css()
|
||||
self.__reload_gtk_theme()
|
||||
await self.__reload_gtk_theme()
|
||||
|
||||
@@ -1,27 +1,23 @@
|
||||
foreground {{ onSurface }}
|
||||
background {{ surface }}
|
||||
cursor {{ onSurface }}
|
||||
|
||||
color0 {{ surface }}
|
||||
color8 {{ surface }}
|
||||
foreground {{ onBackground }}
|
||||
background {{ background }}
|
||||
cursor {{ primaryFixed }}
|
||||
|
||||
# Base 8 Colors (0-7)
|
||||
color0 {{ surfaceContainerLowest }}
|
||||
color1 {{ error }}
|
||||
color9 {{ error }}
|
||||
|
||||
color2 {{ inversePrimary }}
|
||||
color10 {{ inversePrimary }}
|
||||
|
||||
color3 {{ error }}
|
||||
color11 {{ error }}
|
||||
|
||||
color2 {{ primary }}
|
||||
color3 {{ tertiary }}
|
||||
color4 {{ primaryContainer }}
|
||||
color12 {{ primaryContainer }}
|
||||
|
||||
color5 {{ onSecondaryContainer }}
|
||||
color13 {{ onSecondaryContainer }}
|
||||
|
||||
color6 {{ primary }}
|
||||
color14 {{ primary }}
|
||||
|
||||
color5 {{ secondaryFixedDim }}
|
||||
color6 {{ tertiaryFixed }}
|
||||
color7 {{ onSurface }}
|
||||
color15 {{ onSurface }}
|
||||
|
||||
# Bright (Bold) Variants (8–15)
|
||||
color8 {{ outlineVariant }}
|
||||
color9 {{ errorContainer }}
|
||||
color10 {{ primaryContainer }}
|
||||
color11 {{ tertiaryContainer }}
|
||||
color12 {{ secondaryContainer }}
|
||||
color13 {{ onSecondaryFixedVariant }}
|
||||
color14 {{ onTertiaryFixedVariant }}
|
||||
color15 {{ onSurfaceVariant }}
|
||||
|
||||
Reference in New Issue
Block a user