From 40274dcab2036d36a1fbf7c3701484c0fdb2bcad Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Thu, 12 Dec 2024 16:26:10 +0545 Subject: [PATCH] fix --- .../fabric/modules/launcher/widgets/noti.py | 96 ------ config/fabric/snippets/icon.py | 4 +- config/fabric/snippets/popup.py | 313 ------------------ 3 files changed, 2 insertions(+), 411 deletions(-) delete mode 100644 config/fabric/modules/launcher/widgets/noti.py delete mode 100644 config/fabric/snippets/popup.py diff --git a/config/fabric/modules/launcher/widgets/noti.py b/config/fabric/modules/launcher/widgets/noti.py deleted file mode 100644 index dd5900a8..00000000 --- a/config/fabric/modules/launcher/widgets/noti.py +++ /dev/null @@ -1,96 +0,0 @@ -from fabric.widgets.box import Box -from fabric.widgets.button import Button -from fabric.widgets.image import Image -from fabric.widgets.label import Label -from snippets import MaterialIcon - - -class NotificationManager: - def __init__(self, launcher): - self.launcher = launcher - self.notifications = [] - - self.notification_button = self.create_notification_button() - self.update_notification_button_style() - - def create_notification_button(self): - button = Button( - child=MaterialIcon("notifications"), - h_align="center", - v_align="center", - on_clicked=self.show_notification_menu, - ) - return button - - def add_notification(self, title, message, icon_name="notifications"): - """Add a new notification.""" - notification = { - "title": title, - "message": message, - "icon_name": icon_name, - } - self.notifications.append(notification) - self.update_notification_button_style() - - def remove_notification(self, index): - """Remove a notification by index.""" - if 0 <= index < len(self.notifications): - del self.notifications[index] - self.update_notification_button_style() - - def clear_notifications(self): - """Clear all notifications.""" - self.notifications.clear() - self.update_notification_button_style() - - def update_notification_button_style(self): - """Update the notification button style based on the notification count.""" - count = len(self.notifications) - if count > 0: - style = "background-color: @surfaceVariant; border-radius: 50%;" - self.notification_button.set_style(style) - self.notification_button.set_label(str(count)) - else: - style = "background-color: transparent;" - self.notification_button.set_style(style) - self.notification_button.set_label("") - - def show_notification_menu(self, *_): - """Display the notification menu.""" - viewport = self.launcher.viewport - viewport.children = [] - notifications_box = Box(orientation="v", spacing=5) - - for index, notification in enumerate(self.notifications): - notification_button = self.create_notification_button_item( - notification, index - ) - notifications_box.add(notification_button) - - viewport.add(notifications_box) - - def create_notification_button_item(self, notification, index): - """Create a button for an individual notification.""" - return Button( - child=Box( - orientation="h", - spacing=10, - children=[ - Image(icon_name=notification["icon_name"], size=32), - Box( - orientation="v", - spacing=2, - children=[ - Label(label=notification["title"], bold=True), - Label(label=notification["message"]), - ], - ), - ], - ), - on_clicked=lambda _, idx=index: self.remove_notification(idx), - name="notification-item", - ) - - def get_notification_button(self): - """Get the notification button for the UI.""" - return self.notification_button diff --git a/config/fabric/snippets/icon.py b/config/fabric/snippets/icon.py index 7bf8e7ac..99027003 100644 --- a/config/fabric/snippets/icon.py +++ b/config/fabric/snippets/icon.py @@ -1,9 +1,9 @@ from fabric.widgets.label import Label -def MaterialIcon(icon_name: str, size: str = "24px", props: dict = None): +def MaterialIcon(icon_name: str, size: str = "24px", props=None): label_props = { - "label": icon_name, # Directly use the provided icon name + "label": str(icon_name), # Directly use the provided icon name "name": "material_icon", "style": f"font-size: {size}; ", # Set font family for Material Icons "h_align": "center", # Align horizontally diff --git a/config/fabric/snippets/popup.py b/config/fabric/snippets/popup.py deleted file mode 100644 index cfcc3e7a..00000000 --- a/config/fabric/snippets/popup.py +++ /dev/null @@ -1,313 +0,0 @@ -from typing import Literal - -from fabric.widgets.box import Box -from fabric.widgets.eventbox import EventBox -from fabric.widgets.revealer import Revealer -from fabric.widgets.wayland import WaylandWindow -from fabric.widgets.widget import Widget -from gi.repository import GLib - - -class Padding(EventBox): - def __init__(self, name: str | None = None, style: str = "", **kwargs): - super().__init__( - name=name, - h_expand=True, - v_expand=True, - child=Box(style=style, h_expand=True, v_expand=True), - events=["button-press"], - **kwargs, - ) - self.set_can_focus(False) - - -class PopupRevealer(Box): - def __init__( - self, - popup_window: WaylandWindow, - decorations: str = "padding: 1px;", - name: str | None = None, - child: Widget | None = None, - transition_type: Literal[ - "none", - "crossfade", - "slide-right", - "slide-left", - "slide-up", - "slide-down", - ] = "slide-down", - transition_duration: int = 400, - ): - self.revealer: Revealer = Revealer( - name=name, - child=child, - transition_type=transition_type, - transition_duration=transition_duration, - notify_child_revealed=lambda revealer, _: ( - [ - revealer.hide(), - popup_window.set_visible(False), - ] - if not revealer.fully_revealed - else None - ), - notify_reveal_child=lambda revealer, _: ( - [ - popup_window.set_visible(True), - ] - if revealer.child_revealed - else None - ), - ) - super().__init__( - style=decorations, - children=self.revealer, - ) - - -def make_layout(anchor: str, name: str, popup: PopupRevealer, **kwargs) -> Box: - match anchor: - case "center-left": - return Box( - children=[ - Box( - orientation="vertical", - children=[ - Padding(name=name, **kwargs), - popup, - Padding(name=name, **kwargs), - ], - ), - Padding(name=name, **kwargs), - ] - ) - - case "center": - return Box( - children=[ - Padding(name=name, **kwargs), - Box( - orientation="vertical", - children=[ - Padding(name=name, **kwargs), - popup, - Padding(name=name, **kwargs), - ], - ), - Padding(name=name, **kwargs), - ] - ) - case "center-right": - return Box( - children=[ - Padding(name=name, **kwargs), - Box( - orientation="vertical", - children=[ - Padding(name=name, **kwargs), - popup, - Padding(name=name, **kwargs), - ], - ), - ] - ) - case "top": - return Box( - children=[ - Padding(name=name, **kwargs), - Box( - orientation="vertical", - children=[popup, Padding(name=name, **kwargs)], - ), - Padding(name=name, **kwargs), - ] - ) - case "top-right": - return Box( - children=[ - Padding(name=name, **kwargs), - Box( - h_expand=False, - orientation="vertical", - children=[popup, Padding(name=name, **kwargs)], - ), - ] - ) - case "top-center": - return Box( - children=[ - Padding(name=name, **kwargs), - Box( - h_expand=False, - orientation="vertical", - children=[popup, Padding(name=name, **kwargs)], - ), - Padding(name=name, **kwargs), - ] - ) - case "top-left": - return Box( - children=[ - Box( - h_expand=False, - orientation="vertical", - children=[popup, Padding(name=name, **kwargs)], - ), - Padding(name=name, **kwargs), - ] - ) - case "bottom-left": - return Box( - children=[ - Box( - h_expand=False, - orientation="vertical", - children=[Padding(name=name, **kwargs), popup], - ), - Padding(name=name, **kwargs), - ] - ) - case "bottom-center": - return Box( - children=[ - Padding(name=name, **kwargs), - Box( - h_expand=False, - orientation="vertical", - children=[Padding(name=name, **kwargs), popup], - ), - Padding(name=name, **kwargs), - ] - ) - case "bottom-right": - return Box( - children=[ - Padding(name=name, **kwargs), - Box( - h_expand=True, - orientation="vertical", - children=[Padding(name=name, **kwargs), popup], - ), - ] - ) - case _: - return None - - -class PopupWindow(WaylandWindow): - def __init__( - self, - name: str = "popup-window", - decorations: str = "padding: 1px;", - child: Widget | None = None, - transition_type: ( - Literal[ - "none", - "crossfade", - "slide-right", - "slide-left", - "slide-up", - "slide-down", - ] - | None - ) = None, - transition_duration: int = 100, - popup_visible: bool = False, - anchor: Literal[ - "center-left", - "center", - "center-right", - "top", - "top-right", - "top-center", - "top-left", - "bottom-left", - "bottom-center", - "bottom-right", - ] = "top-right", - enable_inhibitor: bool = False, - keyboard_mode: Literal["none", "exclusive", "on-demand"] = "on-demand", - timeout: int = 1000, - **kwargs, - ): - self.timeout = timeout - self.currtimeout = 0 - self.popup_running = False - - self.popup_visible = popup_visible - - self.enable_inhibitor = enable_inhibitor - - self.monitor_number: int | None = None - - self.reveal_child = PopupRevealer( - name=name, - popup_window=self, - child=child, - transition_type=transition_type, - transition_duration=transition_duration, - decorations=decorations, - ) - - super().__init__( - layer="top", - keyboard_mode=keyboard_mode, - visible=False, - exclusivity="normal", - anchor="top bottom right left", - child=make_layout( - anchor=anchor, - name=name, - popup=self.reveal_child, - on_button_press_event=self.on_inhibit_click, - ), - on_key_release_event=self.on_key_release, - ) - - def on_key_release(self, _, event_key): - if event_key.get_keycode()[1] == 9: - self.popup_visible = False - self.reveal_child.revealer.set_reveal_child(self.popup_visible) - - def on_inhibit_click(self, *_): - self.popup_visible = False - self.reveal_child.revealer.set_reveal_child(self.popup_visible) - - def toggle_popup(self, monitor: bool = False): - if monitor: - curr_monitor = self.hyprland_monitor.get_current_gdk_monitor_id() - self.monitor = curr_monitor - if self.monitor_number != curr_monitor and self.popup_visible: - self.monitor_number = curr_monitor - return - - self.monitor_number = curr_monitor - - if not self.popup_visible: - self.reveal_child.revealer.show() - - self.popup_visible = not self.popup_visible - self.reveal_child.revealer.set_reveal_child(self.popup_visible) - - def popup_timeout(self): - - if not self.popup_visible: - self.reveal_child.revealer.show() - if self.popup_running: - self.currtimeout = 0 - return - self.popup_visible = True - self.reveal_child.revealer.set_reveal_child(self.popup_visible) - self.popup_running = True - - def popup_func(): - if self.currtimeout >= self.timeout: - self.popup_visible = False - self.reveal_child.revealer.set_reveal_child(self.popup_visible) - self.currtimeout = 0 - self.popup_running = False - return False - self.currtimeout += 500 - return True - - GLib.timeout_add(500, popup_func)