[SCRIPT] Updated

This commit is contained in:
t
2025-03-31 20:14:11 +02:00
parent 810f54cb65
commit 314a27eb42
472 changed files with 11721 additions and 921 deletions
+5
View File
@@ -0,0 +1,5 @@
from .toggle_box import ToggleBox
from .notification import NotificationWidget
from .volume_slider import MaterialVolumeSlider
__all__ = ["ToggleBox", "NotificationWidget", "MaterialVolumeSlider"]
@@ -0,0 +1,138 @@
import asyncio
from ignis.widgets import Widget
from ignis.services.notifications import Notification
from ignis.utils import Utils
class ScreenshotLayout(Widget.Box):
def __init__(self, notification: Notification) -> None:
super().__init__(
vertical=True,
hexpand=True,
child=[
Widget.Box(
child=[
Widget.Picture(
image=notification.icon,
content_fit="cover",
width=1920 // 7,
height=1080 // 7,
style="border-radius: 1rem; background-color: black;",
),
Widget.Button(
child=Widget.Icon(
image="window-close-symbolic", pixel_size=20
),
halign="end",
valign="start",
hexpand=True,
css_classes=["notification-close"],
on_click=lambda x: notification.close(),
),
],
),
Widget.Label(
label="Screenshot saved",
css_classes=["notification-screenshot-label"],
),
Widget.Box(
homogeneous=True,
style="margin-top: 0.75rem;",
spacing=10,
child=[
Widget.Button(
child=Widget.Label(label="Open"),
css_classes=["notification-action"],
on_click=lambda x: asyncio.create_task(
Utils.exec_sh_async(f"xdg-open {notification.icon}")
),
),
Widget.Button(
child=Widget.Label(label="Close"),
css_classes=["notification-action"],
on_click=lambda x: notification.close(),
),
],
),
],
)
class NormalLayout(Widget.Box):
def __init__(self, notification: Notification) -> None:
super().__init__(
vertical=True,
hexpand=True,
child=[
Widget.Box(
child=[
Widget.Icon(
image=notification.icon
if notification.icon
else "dialog-information-symbolic",
pixel_size=48,
halign="start",
valign="start",
),
Widget.Box(
vertical=True,
style="margin-left: 0.75rem;",
child=[
Widget.Label(
ellipsize="end",
label=notification.summary,
halign="start",
visible=notification.summary != "",
css_classes=["notification-summary"],
),
Widget.Label(
label=notification.body,
ellipsize="end",
halign="start",
css_classes=["notification-body"],
visible=notification.body != "",
),
],
),
Widget.Button(
child=Widget.Icon(
image="window-close-symbolic", pixel_size=20
),
halign="end",
valign="start",
hexpand=True,
css_classes=["notification-close"],
on_click=lambda x: notification.close(),
),
],
),
Widget.Box(
child=[
Widget.Button(
child=Widget.Label(label=action.label),
on_click=lambda x, action=action: action.invoke(),
css_classes=["notification-action"],
)
for action in notification.actions
],
homogeneous=True,
style="margin-top: 0.75rem;" if notification.actions else "",
spacing=10,
),
],
)
class NotificationWidget(Widget.Box):
def __init__(self, notification: Notification) -> None:
layout: NormalLayout | ScreenshotLayout
if notification.app_name == "grimblast":
layout = ScreenshotLayout(notification)
else:
layout = NormalLayout(notification)
super().__init__(
css_classes=["notification"],
child=[layout],
)
@@ -0,0 +1,25 @@
from ignis.widgets import Widget
from typing import Callable
class ToggleBox(Widget.Box):
def __init__(
self,
label: str,
active: bool,
on_change: Callable,
css_classes: list[str] = [],
**kwargs,
):
super().__init__(
child=[
Widget.Label(label=label),
Widget.Switch(
halign="end",
hexpand=True,
active=active,
on_change=on_change,
),
],
css_classes=["toggle-box"] + css_classes,
)
@@ -0,0 +1,18 @@
from ignis.widgets import Widget
from ignis.services.audio import AudioService, Stream
audio = AudioService.get_default()
class MaterialVolumeSlider(Widget.Scale):
def __init__(self, stream: Stream, **kwargs):
super().__init__(
value=stream.bind_many(
["volume", "is_muted"],
lambda volume, is_muted: 0 if is_muted or volume is None else volume,
),
css_classes=["material-slider"],
hexpand=True,
step=5,
**kwargs,
)