From f8f1816aa3318b0e3fc096514144138b4b0d093e Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Wed, 20 Nov 2024 16:00:23 +0545 Subject: [PATCH] update --- config/fabric/modules/bar/bar.py | 7 +- config/fabric/modules/bar/widgets/__init__.py | 4 +- config/fabric/modules/bar/widgets/battery.py | 2 +- .../fabric/modules/bar/widgets/bluetooth.py | 2 +- config/fabric/modules/bar/widgets/glace.py | 97 ++++++++++++ .../modules/bar/widgets/idle_indicator.py | 5 +- config/fabric/modules/bar/widgets/info.py | 3 +- .../fabric/modules/bar/widgets/microphone.py | 2 +- config/fabric/modules/bar/widgets/network.py | 3 +- .../fabric/modules/bar/widgets/powermenu.py | 149 ------------------ .../modules/bar/widgets/powerprofile.py | 2 +- config/fabric/modules/bar/widgets/taskbar.py | 2 +- config/fabric/modules/bar/widgets/volume.py | 2 +- config/fabric/modules/bar/widgets/weather.py | 32 ++++ 14 files changed, 148 insertions(+), 164 deletions(-) create mode 100644 config/fabric/modules/bar/widgets/glace.py delete mode 100644 config/fabric/modules/bar/widgets/powermenu.py create mode 100644 config/fabric/modules/bar/widgets/weather.py diff --git a/config/fabric/modules/bar/bar.py b/config/fabric/modules/bar/bar.py index f0c792d0..5185b721 100644 --- a/config/fabric/modules/bar/bar.py +++ b/config/fabric/modules/bar/bar.py @@ -16,6 +16,7 @@ from modules.bar.widgets import ( PowerProfile, TaskBar, VolumeIndicator, + Weather, workspace, ) @@ -42,9 +43,10 @@ class Bar(Window): ), ), ) + self.date_time = DateTime(formatters=["%-I:%M 󰧞 %a %d %b"], name="datetime") self.system_tray = SystemTray(name="tray", spacing=4, icon_size=18) - self.taskbar = TaskBar(icon_size=18) + self.taskbar = TaskBar() self.volume = VolumeIndicator() self.network = Network() self.bluetooth = Bluetooth() @@ -54,6 +56,7 @@ class Bar(Window): self.workspaces = Button(child=workspace, name="workspaces") self.info = HardwareUsage() self.idle = IdleIndicator() + self.weather = Weather("Kohalpur") self.applets = Box( name="applets", spacing=4, @@ -67,6 +70,7 @@ class Bar(Window): self.idle, ], ) + self.children = CenterBox( name="bar", start_children=Box( @@ -76,6 +80,7 @@ class Bar(Window): children=[ self.workspaces, self.info, + self.weather, ], ), center_children=Box( diff --git a/config/fabric/modules/bar/widgets/__init__.py b/config/fabric/modules/bar/widgets/__init__.py index bbb8bed1..d6901760 100644 --- a/config/fabric/modules/bar/widgets/__init__.py +++ b/config/fabric/modules/bar/widgets/__init__.py @@ -1,12 +1,13 @@ from .battery import BatteryLabel from .bluetooth import Bluetooth +from .glace import TaskBar from .idle_indicator import IdleIndicator from .info import HardwareUsage from .microphone import MicrophoneIndicator from .network import Network from .powerprofile import PowerProfile -from .taskbar import TaskBar from .volume import VolumeIndicator +from .weather import Weather from .workspace import workspace __all__ = [ @@ -20,4 +21,5 @@ __all__ = [ "TaskBar", "VolumeIndicator", "workspace", + "Weather", ] diff --git a/config/fabric/modules/bar/widgets/battery.py b/config/fabric/modules/bar/widgets/battery.py index dcf261fe..fa4a3b87 100644 --- a/config/fabric/modules/bar/widgets/battery.py +++ b/config/fabric/modules/bar/widgets/battery.py @@ -3,7 +3,7 @@ import psutil from fabric.utils import invoke_repeater from fabric.widgets.box import Box from fabric.widgets.label import Label -from services import MaterialIcon +from snippets import MaterialIcon class BatteryLabel(Box): diff --git a/config/fabric/modules/bar/widgets/bluetooth.py b/config/fabric/modules/bar/widgets/bluetooth.py index 139a0dcb..6d83d054 100644 --- a/config/fabric/modules/bar/widgets/bluetooth.py +++ b/config/fabric/modules/bar/widgets/bluetooth.py @@ -1,6 +1,6 @@ from fabric.bluetooth import BluetoothClient from fabric.widgets.box import Box -from services import MaterialIcon # Import your MaterialIcon function +from snippets import MaterialIcon # Import your MaterialIcon function class Bluetooth(Box): diff --git a/config/fabric/modules/bar/widgets/glace.py b/config/fabric/modules/bar/widgets/glace.py new file mode 100644 index 00000000..518fdde6 --- /dev/null +++ b/config/fabric/modules/bar/widgets/glace.py @@ -0,0 +1,97 @@ +import gi +from fabric.widgets.box import Box +from fabric.widgets.button import Button +from fabric.widgets.image import Image +from fabric.widgets.wayland import WaylandWindow as Window +from snippets import IconResolver + +gi.require_version("Glace", "0.1") +gi.require_version("Gtk", "3.0") +from gi.repository import Glace, Gtk + + +class TaskBar(Box): + def __init__(self): + self.client_buttons = {} + super().__init__(spacing=10, name="taskbar") + self.icon_resolver = IconResolver() + self._manager = Glace.Manager() + self._manager.connect("client-added", self.on_client_added) + self._manager.connect( + "client-removed", self.on_client_removed + ) # Listen for client removal + + def on_client_added(self, _, client: Glace.Client): + client_image = Image() + client_button = Button( + image=client_image, + on_button_press_event=lambda *_: client.activate(), + ) + self.client_buttons[client.get_id()] = client_button + + client.connect( + "notify::app-id", + lambda *_: client_image.set_from_pixbuf( + self.icon_resolver.get_icon_pixbuf(client.get_app_id(), 24) + ), + ) + + client.connect( + "notify::activated", + lambda *_: ( + client_button.add_style_class("activated") + if client.get_activated() + else client_button.remove_style_class("activated") + ), + ) + tooltip_image = Image(style="padding-bottom: 50px;") + + popover = Window(type="popup", anchor="bottom", child=tooltip_image) + + client_button.connect( + "enter-notify-event", self.on_enter, client, tooltip_image, popover + ) + client_button.connect("leave-notify-event", self.on_leave, popover) + + # client.bind_property("title", client_button, "tooltip-text", 0) + client.connect("close", lambda *_: self.remove(client_button)) + self.add(client_button) + + # After adding a new client, ensure the taskbar is visible + self._update_visibility() + + def on_client_removed(self, _, client: Glace.Client): + # Remove the button associated with the client + client_button = self.client_buttons.pop(client.get_id(), None) + if client_button: + self.remove(client_button) + + # After removing a client, ensure the taskbar visibility is updated + self._update_visibility() + + def on_enter(self, button: Button, event, client, tooltip_image, popover): + x = event.x_root + + def capture_callback(pbuf, user_data): + tooltip_image.set_from_pixbuf( + pbuf.scale_simple(pbuf.get_width() * 0.15, pbuf.get_height() * 0.15, 2) + ) + tooltip_image.set_style(f"padding-bottom: 10px;") + popover.show() if button.is_hovered() else None + + self._manager.capture_client( + client=client, + overlay_cursor=False, + callback=capture_callback, + user_data=None, + ) + + def on_leave(self, button, event, popover: Gtk.Popover): + popover.hide() + + def _update_visibility(self): + # Check if there are any client buttons; if not, hide the taskbar + if len(self.client_buttons) == 0: + self.set_visible(False) + else: + self.set_visible(True) diff --git a/config/fabric/modules/bar/widgets/idle_indicator.py b/config/fabric/modules/bar/widgets/idle_indicator.py index 5ce7655a..7a747fbd 100644 --- a/config/fabric/modules/bar/widgets/idle_indicator.py +++ b/config/fabric/modules/bar/widgets/idle_indicator.py @@ -1,8 +1,7 @@ -from gi.repository import GLib - from fabric.utils import exec_shell_command from fabric.widgets.box import Box -from services import MaterialIcon +from gi.repository import GLib +from snippets import MaterialIcon class IdleIndicator(Box): diff --git a/config/fabric/modules/bar/widgets/info.py b/config/fabric/modules/bar/widgets/info.py index 4505d10d..7c0ad615 100644 --- a/config/fabric/modules/bar/widgets/info.py +++ b/config/fabric/modules/bar/widgets/info.py @@ -1,12 +1,11 @@ import psutil - from fabric.utils import invoke_repeater from fabric.widgets.box import Box from fabric.widgets.button import Button from fabric.widgets.circularprogressbar import CircularProgressBar from fabric.widgets.label import Label from fabric.widgets.overlay import Overlay -from services import MaterialIcon +from snippets import MaterialIcon class HardwareUsage(Button): diff --git a/config/fabric/modules/bar/widgets/microphone.py b/config/fabric/modules/bar/widgets/microphone.py index bae91c5a..d84a6dad 100644 --- a/config/fabric/modules/bar/widgets/microphone.py +++ b/config/fabric/modules/bar/widgets/microphone.py @@ -1,6 +1,6 @@ from fabric.audio.service import Audio from fabric.widgets.box import Box -from services import MaterialIcon +from snippets import MaterialIcon class MicrophoneIndicator(Box): diff --git a/config/fabric/modules/bar/widgets/network.py b/config/fabric/modules/bar/widgets/network.py index 8a66cf84..8a39d1c7 100644 --- a/config/fabric/modules/bar/widgets/network.py +++ b/config/fabric/modules/bar/widgets/network.py @@ -1,10 +1,9 @@ import subprocess import psutil - from fabric.utils import invoke_repeater from fabric.widgets.box import Box -from services import MaterialIcon +from snippets import MaterialIcon class Network(Box): diff --git a/config/fabric/modules/bar/widgets/powermenu.py b/config/fabric/modules/bar/widgets/powermenu.py deleted file mode 100644 index e00d8776..00000000 --- a/config/fabric/modules/bar/widgets/powermenu.py +++ /dev/null @@ -1,149 +0,0 @@ -from fabric.utils import bulk_connect, exec_shell_command_async -from fabric.widgets.box import Box -from fabric.widgets.button import Button -from fabric.widgets.eventbox import EventBox -from fabric.widgets.label import Label -from fabric.widgets.revealer import Revealer - - -class PowerMenu(EventBox): - def __init__(self): - super().__init__(name="power-event") - - icons_map = { - "power-lock": "", - "power-suspend": "", - "power-logout": "", - "power-reboot": "", - "power-shutdown": "", - } - - self.buttons = { - name: Button(name=name, child=Label(label=f"{icon}")) - for name, icon in icons_map.items() - } - - self.power_box = Box( - name="power-box", - orientation="h", - children=[ - self.buttons[name] - for name in [ - "power-lock", - "power-suspend", - "power-logout", - "power-reboot", - ] - ], - ) - - self.accept_button = Button(name="accept", child=Label(label="✔")) - self.cancel_button = Button(name="cancel", child=Label(label="✘")) - - self.revealer_buttons_box = Box( - name="confirm-box", - orientation="h", - children=[self.accept_button, self.cancel_button], - ) - - self.revealer = Revealer( - name="power-revealer", - transition_type="slide-right", - transition_duration=300, - child=self.power_box, - reveal_child=False, - ) - - self.shutdown_box = Box( - name="shutdown-box", - orientation="h", - children=[self.buttons["power-shutdown"]], - ) - - self.super_box = Box( - name="super-box", - orientation="h", - children=[self.revealer, self.shutdown_box], - ) - - self.confirm_revealer = Revealer( - name="confirm-revealer", - transition_type="slide-right", - transition_duration=300, - child=self.revealer_buttons_box, - reveal_child=False, - ) - - self.full_power = Box( - name="full-power", - orientation="h", - children=[self.super_box, self.confirm_revealer], - ) - - self.add(self.full_power) - self.buttons["self"] = self - self.current_command = None - self.confirmation_active = False - - for btn in self.buttons.values(): - bulk_connect( - btn, - { - "button-press-event": self.on_button_press, - "enter-notify-event": self.on_button_hover, - "leave-notify-event": self.on_button_unhover, - }, - ) - - self.accept_button.connect("button-press-event", self.on_accept_press) - self.cancel_button.connect("button-press-event", self.on_cancel_press) - - def on_button_hover(self, button, event): - if button == self and not self.confirmation_active: - self.revealer.set_reveal_child(True) - - def on_button_unhover(self, button, event): - if button == self and not self.confirmation_active: - self.revealer.set_reveal_child(False) - - def on_button_press(self, button, event): - commands = { - self.buttons["power-lock"]: "hyprlock", - self.buttons[ - "power-suspend" - ]: "hyprctl dispatch exec hyprlock && systemctl suspend", - self.buttons["power-logout"]: "hyprctl dispatch exit", - self.buttons["power-reboot"]: "systemctl reboot", - self.buttons["power-shutdown"]: "systemctl poweroff", - } - if button in commands: - if button != self.buttons["power-lock"]: - self.current_command = commands[button] - self.revealer.set_reveal_child(False) - self.confirm_revealer.set_reveal_child(True) - self.shutdown_box.hide() - self.confirmation_active = True - - else: - exec_shell_command_async(commands[button], lambda *_: None) - return True - - def on_accept_press(self, button, event): - if self.current_command: - exec_shell_command_async(self.current_command, lambda *_: None) - self.current_command = None - self.confirm_revealer.set_reveal_child(False) - self.revealer.set_reveal_child(True) - self.shutdown_box.show() - self.confirmation_active = False - - return True - - def on_cancel_press(self, button, event): - self.current_command = None - self.confirm_revealer.set_reveal_child(False) - self.revealer.set_reveal_child(True) - self.shutdown_box.show() - self.confirmation_active = False - - return True diff --git a/config/fabric/modules/bar/widgets/powerprofile.py b/config/fabric/modules/bar/widgets/powerprofile.py index 14b36b10..39aa982f 100644 --- a/config/fabric/modules/bar/widgets/powerprofile.py +++ b/config/fabric/modules/bar/widgets/powerprofile.py @@ -1,6 +1,6 @@ from fabric.utils import exec_shell_command, invoke_repeater from fabric.widgets.box import Box -from services import MaterialIcon +from snippets import MaterialIcon PROFILE_ICONS = { "power-saver": "data_saver_on", diff --git a/config/fabric/modules/bar/widgets/taskbar.py b/config/fabric/modules/bar/widgets/taskbar.py index bbda01b1..67291067 100644 --- a/config/fabric/modules/bar/widgets/taskbar.py +++ b/config/fabric/modules/bar/widgets/taskbar.py @@ -68,7 +68,7 @@ class TaskBar(Box): button = Button(image=icon, tooltip_text=client["title"]) if client["address"] == active_window_address: button.set_style( - "background-color: @surfaceVariant; border-radius:101px;" + "background-color: @surfaceVariant; border-radius:100px;" ) button.connect( "button-press-event", self.on_icon_click, client["address"] diff --git a/config/fabric/modules/bar/widgets/volume.py b/config/fabric/modules/bar/widgets/volume.py index b410c3fb..90610c28 100644 --- a/config/fabric/modules/bar/widgets/volume.py +++ b/config/fabric/modules/bar/widgets/volume.py @@ -2,7 +2,7 @@ from fabric.audio.service import Audio from fabric.utils import exec_shell_command, invoke_repeater from fabric.widgets.box import Box from fabric.widgets.button import Button -from services import MaterialIcon +from snippets import MaterialIcon VOLUME_ICONS = { "muted": "volume_off", diff --git a/config/fabric/modules/bar/widgets/weather.py b/config/fabric/modules/bar/widgets/weather.py new file mode 100644 index 00000000..8720c6c0 --- /dev/null +++ b/config/fabric/modules/bar/widgets/weather.py @@ -0,0 +1,32 @@ +from services import WeatherInfo + +from fabric.utils import invoke_repeater +from fabric.widgets.box import Box +from fabric.widgets.label import Label + + +class Weather(Box): + def __init__( + self, + city: str, + interval: int = 60000, + enable_tooltip=True, + ): + super().__init__(name="tray") + self.enable_tooltip = enable_tooltip + self.city = city + + self.weather_service = WeatherInfo() + + self.weather_label = Label(label="weather") + self.children = self.weather_label + + invoke_repeater(interval, self.update_label, initial_call=True) + + def update_label(self): + res = self.weather_service.simple_weather_info(city=self.city) + self.weather_label.set_label(f"{res["icon"]} {res["temperature"]}") + + if self.enable_tooltip: + self.set_tooltip_text(f"{res["city"]}, {res["condition"]}".strip("'")) + return True