From e41a17bf4c53c25b7aca373abbba7108bb49f370 Mon Sep 17 00:00:00 2001 From: 00xJ4CK <144516471+00xJ4CK@users.noreply.github.com> Date: Sat, 21 Dec 2024 08:00:13 +0545 Subject: [PATCH] add calendar widget and fixes some error --- config/fabric/assets/config.json | 5 ++ config/fabric/main.py | 6 +-- config/fabric/modules/launcher/launcher.py | 16 +++---- .../modules/launcher/widgets/__init__.py | 1 + .../modules/launcher/widgets/calendar.py | 25 ++++++++++ .../modules/launcher/widgets/power_menu.py | 2 +- ...notifications.py => notification_popup.py} | 0 config/fabric/snippets/__init__.py | 1 + config/fabric/snippets/calendar.py | 48 +++++++++++++++++++ config/fabric/styles/launcher.css | 40 ++++++++++++++++ 10 files changed, 132 insertions(+), 12 deletions(-) create mode 100644 config/fabric/modules/launcher/widgets/calendar.py rename config/fabric/modules/{notifications.py => notification_popup.py} (100%) create mode 100644 config/fabric/snippets/calendar.py diff --git a/config/fabric/assets/config.json b/config/fabric/assets/config.json index 56f99727..9b339cff 100644 --- a/config/fabric/assets/config.json +++ b/config/fabric/assets/config.json @@ -34,6 +34,11 @@ "command": ":p", "description": "Shutdown and go sleepy time", "handler": "show_powermenu" + }, + { + "command": ":cl", + "description": "Show the calendar", + "handler": "show_calendar" } ] } diff --git a/config/fabric/main.py b/config/fabric/main.py index 2cd4f4d6..0e3199eb 100644 --- a/config/fabric/main.py +++ b/config/fabric/main.py @@ -1,13 +1,13 @@ import os import setproctitle -from fabric import Application -from fabric.utils import get_relative_path, monitor_file from loguru import logger +from fabric import Application +from fabric.utils import get_relative_path, monitor_file from modules.bar.bar import Bar from modules.launcher.launcher import Launcher -from modules.notifications import NotificationPopup +from modules.notification_popup import NotificationPopup from modules.osd import OSDContainer from services import ScreenRecorder diff --git a/config/fabric/modules/launcher/launcher.py b/config/fabric/modules/launcher/launcher.py index 9d66db49..1cae00c3 100644 --- a/config/fabric/modules/launcher/launcher.py +++ b/config/fabric/modules/launcher/launcher.py @@ -1,7 +1,5 @@ -from fabric import Application from fabric.utils import ( get_desktop_applications, - get_relative_path, idle_add, invoke_repeater, remove_handler, @@ -13,8 +11,10 @@ from fabric.widgets.label import Label from fabric.widgets.revealer import Revealer from fabric.widgets.scrolledwindow import ScrolledWindow from fabric.widgets.wayland import WaylandWindow as Window + from modules.launcher.widgets import ( BluetoothMenu, + Calendar, ClipboardManager, EmojiManager, PowerMenu, @@ -63,6 +63,7 @@ class Launcher(Window): self.power_menu = PowerMenu(self) self.bluetooth_menu = BluetoothMenu(self) self.network_menu = WifiMenu(self) + self.calendar_menu = Calendar(self) def setup_ui(self): self.default_button = Button( @@ -272,9 +273,8 @@ class Launcher(Window): self.update_dynamic_button(dynamic_buttons) self.scrolled_revealer.reveal() - -# if __name__ == "__main__": -# launcher = Launcher() -# app = Application("launcher", launcher) -# app.set_stylesheet_from_file(get_relative_path("./styles/main.css")) -# app.run() + def show_calendar(self, *_): + self.calendar_menu.show_calendar_menu(self.viewport) + dynamic_buttons = self.calendar_menu.get_calendar_buttons() + self.update_dynamic_button(dynamic_buttons) + self.scrolled_revealer.reveal() diff --git a/config/fabric/modules/launcher/widgets/__init__.py b/config/fabric/modules/launcher/widgets/__init__.py index 59567757..c99174db 100644 --- a/config/fabric/modules/launcher/widgets/__init__.py +++ b/config/fabric/modules/launcher/widgets/__init__.py @@ -1,5 +1,6 @@ from .app import * from .bluetooth import * +from .calendar import * from .clipboard import * from .emoji import * from .power_menu import * diff --git a/config/fabric/modules/launcher/widgets/calendar.py b/config/fabric/modules/launcher/widgets/calendar.py new file mode 100644 index 00000000..6ffcb155 --- /dev/null +++ b/config/fabric/modules/launcher/widgets/calendar.py @@ -0,0 +1,25 @@ +from fabric.widgets.box import Box +from fabric.widgets.button import Button +from snippets import GtkCalendar, MaterialIcon + + +class Calendar: + def __init__(self, launcher): + self.launcher = launcher + self.today_button = Button( + child=MaterialIcon("event_available"), + v_align="center", + ) + + def show_calendar_menu(self, viewport): + viewport.children = [] + + calendar_container = Box( + name="calendar", + children=GtkCalendar(h_expand=True), + ) + + viewport.add(calendar_container) + + def get_calendar_buttons(self): + return self.today_button diff --git a/config/fabric/modules/launcher/widgets/power_menu.py b/config/fabric/modules/launcher/widgets/power_menu.py index f24eb5c8..97f052a8 100644 --- a/config/fabric/modules/launcher/widgets/power_menu.py +++ b/config/fabric/modules/launcher/widgets/power_menu.py @@ -74,7 +74,7 @@ class PowerMenu: orientation="h", spacing=10, children=[ - MaterialIcon(option["icon"], size="28px"), + MaterialIcon(option["icon"], size=28), Label(label=option["label"], h_align="start"), ], ), diff --git a/config/fabric/modules/notifications.py b/config/fabric/modules/notification_popup.py similarity index 100% rename from config/fabric/modules/notifications.py rename to config/fabric/modules/notification_popup.py diff --git a/config/fabric/snippets/__init__.py b/config/fabric/snippets/__init__.py index add4b114..0cd2d48b 100644 --- a/config/fabric/snippets/__init__.py +++ b/config/fabric/snippets/__init__.py @@ -1,4 +1,5 @@ from .animator import * +from .calendar import * from .custom_image import * from .functions import * from .icon import * diff --git a/config/fabric/snippets/calendar.py b/config/fabric/snippets/calendar.py new file mode 100644 index 00000000..cff34150 --- /dev/null +++ b/config/fabric/snippets/calendar.py @@ -0,0 +1,48 @@ +from collections.abc import Iterable +from typing import Literal + +import gi +from fabric.widgets.widget import Widget +from gi.repository import Gtk + +gi.require_version("Gtk", "3.0") + + +class GtkCalendar(Gtk.Calendar, Widget): + """A switch widget.""" + + def __init__( + self, + name: str | None = None, + h_align: ( + Literal["fill", "start", "end", "center", "baseline"] | Gtk.Align | None + ) = None, + v_align: ( + Literal["fill", "start", "end", "center", "baseline"] | Gtk.Align | None + ) = None, + h_expand: bool = False, + v_expand: bool = False, + tooltip_text: str | None = None, + tooltip_markup: str | None = None, + visible: bool = True, + all_visible: bool = False, + style: str | None = None, + style_classes: Iterable[str] | str | None = None, + **kwargs, + ): + Gtk.Calendar.__init__(self) # type: ignore + Widget.__init__( + self, + name, + visible, + all_visible, + style, + style_classes, + tooltip_text, + tooltip_markup, + h_align, + v_align, + h_expand, + v_expand, + **kwargs, + ) diff --git a/config/fabric/styles/launcher.css b/config/fabric/styles/launcher.css index 683996d9..0ad7cb01 100644 --- a/config/fabric/styles/launcher.css +++ b/config/fabric/styles/launcher.css @@ -144,3 +144,43 @@ background-color: @surfaceVariant; border-radius: 100px; } + +#calendar calendar { + all: unset; + font-size: 18px; + padding: 5px; +} + +#calendar calendar.button { + all: unset; + transition: 200ms; + border-radius: 10px; + background-color: transparent; + background-image: none; + box-shadow: none; +} + +#calendar calendar:selected { + box-shadow: + inset 0 -7px 0 0 @primary, + inset 0 0 0 1px @surfaceVariant; + border-radius: 6px; +} + +#calendar calendar.header { + background-color: transparent; + border: none; +} + +#calendar calendar.highlight { + background-color: transparent; + color: @onSurface; +} + +#calendar calendar:hover { + color: @errorContainer; +} + +#calendar calendar:indeterminate { + color: mix(@onSurfaceVariant, transparent, 0.3); +}