✨ feat: add fabric widgets and core framework

This commit is contained in:
sankalp committed 2025-07-30 09:30:42 +05:45
1 parent acec6bdda7
commit 6684033219
102 files changed
+12735 -24

No files matched your search

+158
View File
@@ -0,0 +1,158 @@
import psutil
from fabric import Application, Fabricator
from fabric.widgets.box import Box
from fabric.widgets.image import Image
from fabric.widgets.eventbox import EventBox
from fabric.widgets.datetime import DateTime
from fabric.widgets.centerbox import CenterBox
from fabric.system_tray.widgets import SystemTray
from fabric.widgets.circularprogressbar import CircularProgressBar
from fabric.widgets.wayland import WaylandWindow as Window
from fabric.hyprland.widgets import (
HyprlandLanguage,
HyprlandActiveWindow,
HyprlandWorkspaces,
WorkspaceButton,
)
from fabric.utils import FormattedString, get_relative_path, bulk_replace
AUDIO_WIDGET = True
if AUDIO_WIDGET is True:
try:
from fabric.audio.service import Audio
except Exception as e:
AUDIO_WIDGET = False
print(e)
class VolumeWidget(Box):
def __init__(self, **kwargs):
self.progress_bar = CircularProgressBar(
name="volume-progress-bar",
pie=True,
child=Image(icon_name="audio-speakers-symbolic", icon_size=12),
size=24,
)
self.audio = Audio(notify_speaker=self.on_speaker_changed)
super().__init__(
children=EventBox(
events="scroll", child=self.progress_bar, on_scroll_event=self.on_scroll
),
**kwargs,
)
def on_scroll(self, _, event):
match event.direction:
case 0:
self.audio.speaker.volume += 8
case 1:
self.audio.speaker.volume -= 8
return
def on_speaker_changed(self):
if not self.audio.speaker:
return
self.progress_bar.value = self.audio.speaker.volume / 100
return self.audio.speaker.bind(
"volume", "value", self.progress_bar, lambda _, v: v / 100
)
class StatusBar(Window):
def __init__(
self,
):
super().__init__(
name="bar",
layer="top",
anchor="left top right",
margin="10px 10px -2px 10px",
exclusivity="auto",
visible=False,
)
self.system_status = Box(
name="system-status",
spacing=4,
orientation="h",
children=[
# a progress bar (ram) has a child of a progress bar (cpu) that which has a child (the icon)
CircularProgressBar(
name="ram-progress-bar",
pie=True,
child=CircularProgressBar(
name="cpu-progress-bar",
pie=True,
child=Image(icon_name="cpu-symbolic", icon_size=12),
size=24,
).build(
lambda progres: Fabricator(
interval=1000,
poll_from=lambda f: psutil.cpu_percent() / 100,
on_changed=lambda _, value: progres.set_value(value),
)
),
size=24,
).build(
lambda progres: Fabricator(
interval=1000,
poll_from=lambda f: psutil.virtual_memory().percent / 100,
on_changed=lambda _, value: progres.set_value(value),
)
)
]
# create a volume widget if enabled
+ ([VolumeWidget()] if AUDIO_WIDGET else []),
)
self.children = CenterBox(
name="bar-inner",
start_children=Box(
name="start-container",
children=HyprlandWorkspaces(
name="workspaces",
spacing=4,
buttons_factory=lambda ws_id: WorkspaceButton(id=ws_id, label=None),
),
),
center_children=Box(
name="center-container",
children=HyprlandActiveWindow(name="hyprland-window"),
),
end_children=Box(
name="end-container",
spacing=4,
orientation="h",
children=[
self.system_status,
SystemTray(name="system-tray", spacing=4),
DateTime(name="date-time"),
HyprlandLanguage(
name="hyprland-window",
formatter=FormattedString(
"{replace_lang(language)}",
replace_lang=lambda lang: bulk_replace(
lang,
(r".*Eng.*", r".*Ar.*"),
("ENG", "ARA"),
regex=True,
),
),
),
],
),
)
return self.show_all()
if __name__ == "__main__":
bar = StatusBar()
app = Application("bar", bar)
app.set_stylesheet_from_file(get_relative_path("./style.css"))
app.run()
+165
View File
@@ -0,0 +1,165 @@
/* we can use web-css variables, fabric compiles those to gtk-css.
global variables can be defined in the :vars selector... */
:vars {
--background: #150d16;
--foreground: #f5dbc4;
--color0: #150d16;
--color1: #72448D;
--color2: #9C5995;
--color3: #D5719F;
--color4: #9A62F3;
--color5: #E075DF;
--color6: #F98F9F;
--color7: #f5dbc4;
--color8: #ab9989;
--color9: #72448D;
--color10: #9C5995;
--color11: #D5719F;
--color12: #9A62F3;
--color13: #E075DF;
--color14: #F98F9F;
--color15: #f5dbc4;
--window-bg: alpha(var(--background), 0.6);
--module-bg: alpha(var(--background), 0.4);
--border-color: var(--color11);
--ws-active: var(--color9);
--ws-inactive: var(--color3);
--ws-empty: var(--color8);
--ws-hover: var(--color1);
--ws-urgent: var(--color12);
}
* {
/* unset so we can style everything from the ground up. */
all: unset;
/* text color */
color: var(--foreground);
font-size: 16px;
font-family: "Jost*", sans-serif;
/* pill shape */
border-radius: 100px;
}
#bar-inner {
padding: 4px;
border: solid 2px;
border-color: var(--border-color);
background-color: var(--window-bg);
min-height: 28px;
}
#workspaces {
padding: 6px;
min-width: 0px;
background-color: var(--module-bg);
}
#workspaces>button {
padding: 0px 8px;
transition: padding 0.05s steps(8);
background-color: var(--ws-inactive);
}
#workspaces>button>label {
font-size: 0px;
}
#workspaces>button:hover {
background-color: var(--ws-hover);
}
#workspaces>button.urgent {
background-color: var(--ws-urgent);
}
#workspaces>button.active {
padding: 0px 32px;
background-color: var(--ws-active);
}
#workspaces>button.empty {
background-color: var(--ws-empty);
}
#system-status {
padding: 2px;
background-color: var(--module-bg);
}
#cpu-progress-bar,
#ram-progress-bar,
#volume-progress-bar {
color: transparent;
background-color: transparent
}
#cpu-progress-bar {
border: solid 0px alpha(var(--color9), 0.8);
}
#ram-progress-bar,
#volume-progress-bar {
border: solid 0px var(--border-color);
}
#date-time,
#hyprland-language,
#hyprland-window {
background-color: var(--module-bg);
padding: 0px 8px;
}
menu>menuitem>label,
#date-time>label,
#hyprland-language>label,
#hyprland-window>label {
font-weight: 900;
}
/* system tray */
#system-tray {
padding: 2px 4px;
background-color: var(--module-bg);
}
/* menu and menu items (written for the system tray) */
menu {
border: solid 2px;
border-radius: 10px;
border-color: var(--border-color);
background-color: var(--window-bg);
}
menu>menuitem {
border-radius: 0px;
background-color: var(--module-bg);
padding: 6px;
margin-left: 2px;
margin-right: 2px;
}
menu>menuitem:first-child {
margin-top: 1px;
border-radius: 8px 8px 0px 0px;
}
menu>menuitem:last-child {
margin-bottom: 1px;
border-radius: 0px 0px 8px 8px;
}
menu>menuitem:hover {
background-color: var(--border-color);
}
tooltip {
border: solid 2px;
border-color: var(--border-color);
background-color: var(--window-bg);
}
tooltip>* {
padding: 2px 4px
}