summaryrefslogtreecommitdiff
path: root/src/caelestia/utils/scheme.py
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-06-17 12:49:16 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-06-17 12:49:16 +1000
commit2c94c42cbd269b9b7fae3ad4d33e31e493e739b4 (patch)
tree3593981fecd1847bd0bfe423a0f7942483ba9055 /src/caelestia/utils/scheme.py
parentcompletions: update for prev commit (diff)
downloadcaelestia-cli-2c94c42cbd269b9b7fae3ad4d33e31e493e739b4.tar.gz
caelestia-cli-2c94c42cbd269b9b7fae3ad4d33e31e493e739b4.tar.bz2
caelestia-cli-2c94c42cbd269b9b7fae3ad4d33e31e493e739b4.zip
scheme: add notify opt
For sending a notification on error
Diffstat (limited to 'src/caelestia/utils/scheme.py')
-rw-r--r--src/caelestia/utils/scheme.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/caelestia/utils/scheme.py b/src/caelestia/utils/scheme.py
index 0d6cfb5..c169543 100644
--- a/src/caelestia/utils/scheme.py
+++ b/src/caelestia/utils/scheme.py
@@ -3,6 +3,7 @@ import random
from pathlib import Path
from caelestia.utils.material import get_colours_for_image
+from caelestia.utils.notify import notify
from caelestia.utils.paths import atomic_dump, scheme_data_dir, scheme_path
@@ -12,6 +13,7 @@ class Scheme:
_mode: str
_variant: str
_colours: dict[str, str]
+ notify: bool
def __init__(self, json: dict[str, any] | None) -> None:
if json is None:
@@ -26,6 +28,7 @@ class Scheme:
self._mode = json["mode"]
self._variant = json["variant"]
self._colours = json["colours"]
+ self.notify = False
@property
def name(self) -> str:
@@ -37,6 +40,11 @@ class Scheme:
return
if name not in get_scheme_names():
+ if self.notify:
+ notify(
+ "Unable to set scheme",
+ f'"{name}" is not a valid scheme.\nValid schemes are: {get_scheme_names()}',
+ )
raise ValueError(f"Invalid scheme name: {name}")
self._name = name
@@ -55,6 +63,12 @@ class Scheme:
return
if flavour not in get_scheme_flavours():
+ if self.notify:
+ notify(
+ "Unable to set scheme flavour",
+ f'"{flavour}" is not a valid flavour of scheme "{self.name}".\n'
+ f"Valid flavours are: {get_scheme_flavours()}",
+ )
raise ValueError(f'Invalid scheme flavour: "{flavour}". Valid flavours: {get_scheme_flavours()}')
self._flavour = flavour
@@ -71,6 +85,12 @@ class Scheme:
return
if mode not in get_scheme_modes():
+ if self.notify:
+ notify(
+ "Unable to set scheme mode",
+ f'"{mode}" is not a valid mode of scheme "{self.name} {self.flavour}".\n'
+ f"Valid modes are: {get_scheme_modes()}",
+ )
raise ValueError(f'Invalid scheme mode: "{mode}". Valid modes: {get_scheme_modes()}')
self._mode = mode