[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
+2 -24
View File
@@ -1,25 +1,3 @@
from ignis.widgets import Widget
from .workspaces import workspaces
from .kb_layout import kb_layout
from .clock import clock
from .pinned_apps import pinned_apps
from .tray import tray
from .battery import battery_widget
# from .wallpaper_engine import wallpaper_engine_widget
from .bar import Bar
def bar(monitor: int) -> Widget.Window:
return Widget.Window(
anchor=["left", "top", "right"],
exclusivity="exclusive",
monitor=monitor,
namespace=f"ignis_BAR_{monitor}",
layer="top",
kb_mode="none",
child=Widget.CenterBox(
css_classes=["bar-widget"],
start_widget=Widget.Box(child=[workspaces()]),
center_widget=Widget.Box(child=[pinned_apps()]),
end_widget=Widget.Box(child=[tray(), kb_layout(), battery_widget(), clock(monitor)]),
), # wallpaper_engine_widget(),
css_classes=["unset"],
)
__all__ = ["Bar"]
Binary file not shown.
+25
View File
@@ -0,0 +1,25 @@
from ignis.widgets import Widget
from .widgets import StatusPill, Tray, KeyboardLayout, Battery, Apps, Workspaces
class Bar(Widget.Window):
__gtype_name__ = "Bar"
def __init__(self, monitor: int):
super().__init__(
anchor=["left", "top", "right"],
exclusivity="exclusive",
monitor=monitor,
namespace=f"ignis_BAR_{monitor}",
layer="top",
kb_mode="none",
child=Widget.CenterBox(
css_classes=["bar-widget"],
start_widget=Widget.Box(child=[Workspaces()]),
center_widget=Widget.Box(child=[Apps()]),
end_widget=Widget.Box(
child=[Tray(), KeyboardLayout(), Battery(), StatusPill(monitor)]
),
),
css_classes=["unset"],
)
+31
View File
@@ -0,0 +1,31 @@
from ignis.widgets import Widget
from ignis.services.network import Ethernet, Wifi
class IndicatorIcon(Widget.Icon):
def __init__(self, css_classes: list[str] = [], **kwargs):
super().__init__(
style="margin-right: 0.5rem;", css_classes=["unset"] + css_classes, **kwargs
)
class NetworkIndicatorIcon(IndicatorIcon):
def __init__(
self, device_type: Ethernet | Wifi, other_device_type: Wifi | Ethernet
):
self._device_type = device_type
self._other_device_type = other_device_type
super().__init__(icon_name=device_type.bind("icon-name"))
for binding in (
device_type.bind("devices", self.__check_visibility),
other_device_type.bind("is_connected", self.__check_visibility),
device_type.bind("is_connected", self.__check_visibility),
):
self.visible = binding # type: ignore
def __check_visibility(self, *args) -> bool:
return len(self._device_type.devices) > 0 and (
not self._other_device_type.is_connected or self._device_type.is_connected
)
+8
View File
@@ -0,0 +1,8 @@
from .pill import StatusPill
from .tray import Tray
from .kb_layout import KeyboardLayout
from .battery import Battery
from .apps import Apps
from .workspaces import Workspaces
__all__ = ["StatusPill", "Tray", "KeyboardLayout", "Battery", "Apps", "Workspaces"]
+52
View File
@@ -0,0 +1,52 @@
from ignis.widgets import Widget
from ignis.app import IgnisApp
from ignis.services.applications import ApplicationsService, Application
applications = ApplicationsService.get_default()
app = IgnisApp.get_default()
TERMINAL_FORMAT = "kitty %command%"
class AppItem(Widget.Button):
def __init__(self, app: Application):
menu = Widget.PopoverMenu(
items=[
Widget.MenuItem(label="Launch", on_activate=lambda x: app.launch()),
Widget.Separator(),
]
+ [
Widget.MenuItem(
label=i.name, on_activate=lambda x, action=i: action.launch()
)
for i in app.actions
]
+ [
Widget.Separator(),
Widget.MenuItem(label="Unpin", on_activate=lambda x: app.unpin()),
]
)
super().__init__(
child=Widget.Box(child=[Widget.Icon(image=app.icon, pixel_size=32), menu]),
on_click=lambda x: app.launch(terminal_format=TERMINAL_FORMAT),
on_right_click=lambda x: menu.popup(),
css_classes=["pinned-app", "unset"],
)
class Apps(Widget.Box):
def __init__(self):
super().__init__(
child=applications.bind(
"pinned",
transform=lambda value: [AppItem(app) for app in value]
+ [
Widget.Button(
child=Widget.Icon(image="start-here-symbolic", pixel_size=32),
on_click=lambda x: app.toggle_window("ignis_LAUNCHER"),
css_classes=["pinned-app", "unset"],
)
],
)
)
+37
View File
@@ -0,0 +1,37 @@
from ignis.widgets import Widget
from ignis.services.upower import UPowerService, UPowerDevice
upower = UPowerService.get_default()
class BatteryItem(Widget.Box):
def __init__(self, device: UPowerDevice):
super().__init__(
css_classes=["battery-item"],
setup=lambda self: device.connect("removed", lambda x: self.unparent()),
child=[
Widget.Icon(
icon_name=device.bind("icon_name"), css_classes=["battery-icon"]
),
Widget.Label(
label=device.bind("percent", lambda x: f"{int(x)}%"),
css_classes=["battery-percent"],
),
Widget.Scale(
min=0,
max=100,
value=device.bind("percent"),
sensitive=False,
css_classes=["battery-scale"],
),
],
)
class Battery(Widget.Box):
def __init__(self):
super().__init__(
setup=lambda self: upower.connect(
"battery-added", lambda x, device: self.append(BatteryItem(device))
),
)
+18
View File
@@ -0,0 +1,18 @@
from ignis.widgets import Widget
from ignis.services.hyprland import HyprlandService
hyprland = HyprlandService.get_default()
class KeyboardLayout(Widget.Button):
def __init__(self):
super().__init__(
css_classes=["kb-layout", "unset"],
on_click=lambda x: hyprland.main_keyboard.switch_layout("1"),
visible=hyprland.is_available,
child=Widget.Label(
label=hyprland.main_keyboard.bind(
"active_keymap", transform=lambda value: value[:2].lower()
)
),
)
+111
View File
@@ -0,0 +1,111 @@
import datetime
from ignis.widgets import Widget
from ignis.app import IgnisApp
from ignis.utils import Utils
from ignis.variable import Variable
from ignis.services.network import NetworkService
from ignis.services.notifications import NotificationService
from ignis.services.recorder import RecorderService
from ignis.services.audio import AudioService
from ..indicator_icon import IndicatorIcon, NetworkIndicatorIcon
from ignis.options import options
network = NetworkService.get_default()
notifications = NotificationService.get_default()
recorder = RecorderService.get_default()
audio = AudioService.get_default()
app = IgnisApp.get_default()
current_time = Variable(
value=Utils.Poll(1000, lambda x: datetime.datetime.now().strftime("%H:%M:%S")).bind(
"output"
)
)
class WifiIcon(NetworkIndicatorIcon):
def __init__(self):
super().__init__(device_type=network.wifi, other_device_type=network.ethernet)
class EthernetIcon(NetworkIndicatorIcon):
def __init__(self):
super().__init__(device_type=network.ethernet, other_device_type=network.wifi)
class VpnIcon(IndicatorIcon):
def __init__(self):
super().__init__(
image=network.vpn.bind("icon_name"),
visible=network.vpn.bind("is_connected"),
)
class DNDIcon(IndicatorIcon):
def __init__(self):
super().__init__(
image="notification-disabled-symbolic",
visible=options.notifications.bind("dnd"),
)
class RecorderIcon(IndicatorIcon):
def __init__(self):
super().__init__(
image="media-record-symbolic",
css_classes=["record-indicator"],
setup=lambda self: recorder.connect(
"notify::is-paused", self.__update_css_class
),
visible=recorder.bind("active"),
)
def __update_css_class(self, *args) -> None:
if recorder.is_paused:
self.remove_css_class("active")
else:
self.add_css_class("active")
class VolumeIcon(IndicatorIcon):
def __init__(self):
super().__init__(
image=audio.speaker.bind("icon_name"),
)
class StatusPill(Widget.Button):
def __init__(self, monitor: int):
self._monitor = monitor
self._window: Widget.Window = app.get_window("ignis_CONTROL_CENTER") # type: ignore
super().__init__(
child=Widget.Box(
child=[
RecorderIcon(),
WifiIcon(),
EthernetIcon(),
VpnIcon(),
VolumeIcon(),
DNDIcon(),
Widget.Label(
label=current_time.bind("value"),
),
]
),
css_classes=self._window.bind(
"visible",
lambda value: ["clock", "unset", "active"]
if value
else ["clock", "unset"],
),
on_click=self.__on_click,
)
def __on_click(self, x) -> None:
if self._window.monitor == self._monitor:
self._window.visible = not self._window.visible
else:
self._window.set_monitor(self._monitor)
self._window.visible = True
+42
View File
@@ -0,0 +1,42 @@
import asyncio
from ignis.widgets import Widget
from ignis.services.system_tray import SystemTrayService, SystemTrayItem
system_tray = SystemTrayService.get_default()
class TrayItem(Widget.Button):
__gtype_name__ = "TrayItem"
def __init__(self, item: SystemTrayItem):
if item.menu:
menu = item.menu.copy()
else:
menu = None
super().__init__(
child=Widget.Box(
child=[
Widget.Icon(image=item.bind("icon"), pixel_size=24),
menu,
]
),
tooltip_text=item.bind("tooltip"),
on_click=lambda x: asyncio.create_task(item.activate_async()),
setup=lambda self: item.connect("removed", lambda x: self.unparent()),
on_right_click=lambda x: menu.popup() if menu else None,
css_classes=["tray-item", "unset"],
)
class Tray(Widget.Box):
__gtype_name__ = "Tray"
def __init__(self):
super().__init__(
css_classes=["tray"],
setup=lambda self: system_tray.connect(
"added", lambda x, item: self.append(TrayItem(item))
),
spacing=10,
)
+49
View File
@@ -0,0 +1,49 @@
from ignis.widgets import Widget
from ignis.services.hyprland import HyprlandService, HyprlandWorkspace
hyprland = HyprlandService.get_default()
class WorkspaceButton(Widget.Button):
def __init__(self, workspace: HyprlandWorkspace) -> None:
super().__init__(
css_classes=["workspace", "unset"],
on_click=lambda x: workspace.switch_to(),
halign="start",
valign="center",
)
if workspace.id == hyprland.active_workspace.id:
self.add_css_class("active")
def scroll_workspaces(direction: str) -> None:
current = hyprland.active_workspace.id
if direction == "up":
target = current - 1
hyprland.switch_to_workspace(target)
else:
target = current + 1
if target == 11:
return
hyprland.switch_to_workspace(target)
class Workspaces(Widget.Box):
def __init__(self):
if hyprland.is_available:
child = [
Widget.EventBox(
on_scroll_up=lambda x: scroll_workspaces("up"),
on_scroll_down=lambda x: scroll_workspaces("down"),
css_classes=["workspaces"],
child=hyprland.bind_many(
["workspaces", "active_workspace"],
transform=lambda workspaces, *_: [
WorkspaceButton(i) for i in workspaces
],
),
)
]
else:
child = []
super().__init__(child=child)