feat(src/window/notification): add action buttons creation and improve UI alignment

This commit is contained in:
sankalp committed 2026-07-14 23:11:19 +05:45
1 parent e4e1d3a291
commit f2517ee9f3
1 file changed
+65 -4
+65 -4
View File
@@ -1,6 +1,6 @@
from collections import defaultdict from collections import defaultdict
from fabric.utils import GdkPixbuf, GLib, logger from fabric.utils import Gdk, GdkPixbuf, GLib, Gtk, logger
from fabric.widgets.box import Box from fabric.widgets.box import Box
from fabric.widgets.button import Button from fabric.widgets.button import Button
from fabric.widgets.centerbox import CenterBox from fabric.widgets.centerbox import CenterBox
@@ -264,19 +264,27 @@ class ExpandableNotificationGroup(Box):
label="Show less", label="Show less",
on_clicked=self.collapse, on_clicked=self.collapse,
h_align="end", h_align="end",
v_align="center",
).build(
lambda btn: btn.get_style_context().add_class("mac-header-pill")
), ),
Button( Button(
name="notification-close-summery", name="notification-close-summery",
h_expand=False, h_expand=False,
v_expand=False, v_expand=False,
h_align="end",
v_align="center",
on_clicked=self.close_all, on_clicked=self.close_all,
image=CustomImage( child=CustomImage(
icon_name="close-symbolic", icon_name="close-symbolic",
name="notification-close-header", name="notification-close-header",
icon_size=18, icon_size=12,
h_align="end", h_align="center",
v_align="center",
), ),
visible=True, visible=True,
).build(
lambda btn: btn.get_style_context().add_class("mac-header-circle")
), ),
], ],
) )
@@ -582,6 +590,59 @@ class NotificationCenterWidget(NotificationWidget):
], ],
) )
def create_action_buttons(self, notification):
# Create an options button to hold the context menu
options_button = Button(
name="notification-options-button",
label="Options ⌄",
h_align="end",
v_align="center",
)
options_button.get_style_context().add_class("mac-options-button")
# Build context menu
menu = Gtk.Menu()
menu.get_style_context().add_class("mac-context-menu")
if notification.actions:
for action in notification.actions:
item = Gtk.MenuItem(label=action.label)
# Connect action invocation
def on_activate(_widget, a=action):
self._should_cleanup_cache = True
a.invoke()
a.parent.close("dismissed-by-user")
item.connect("activate", on_activate)
menu.append(item)
menu.append(Gtk.SeparatorMenuItem())
close_item = Gtk.MenuItem(label="Close")
close_item.connect("activate", self._on_close_clicked)
menu.append(close_item)
menu.show_all()
def show_menu(btn):
# Show the menu under the button
menu.popup_at_widget(
btn, Gdk.Gravity.SOUTH_EAST, Gdk.Gravity.NORTH_EAST, None
)
options_button.connect("clicked", show_menu)
# Add to a box that takes up the bottom space
action_box = Box(
h_expand=True,
children=[
Box(h_expand=True), # Push to right
options_button,
],
)
return action_box
def _on_close_clicked(self, *args): def _on_close_clicked(self, *args):
try: try:
# Use instance cache metadata instead of notification attribute # Use instance cache metadata instead of notification attribute