Enhancement in notification_center

This commit is contained in:
tr1x_em committed 2025-08-09 20:46:52 +05:30
1 parent dcad41e9f8
commit 217e0f6936
2 files changed
+82 -27

No files matched your search

+74 -24
View File
@@ -28,10 +28,17 @@ class ExpandableNotificationGroup(Box):
self.app_name = app_name self.app_name = app_name
self.notifications = notifications self.notifications = notifications
self.is_expanded = False self.is_expanded = False # Always start collapsed
# Create collapsed state (shows only latest notification) # Create collapsed state first (shows only latest notification)
self.create_collapsed_state() self.create_collapsed_state()
# Create expanded state (hidden initially)
self.create_expanded_state()
# Ensure we start in collapsed state
self.collapsed_eventbox.set_visible(True)
self.expanded_box.set_visible(False)
def create_collapsed_state(self): def create_collapsed_state(self):
from widgets.custom_image import CustomImage from widgets.custom_image import CustomImage
@@ -97,7 +104,8 @@ class ExpandableNotificationGroup(Box):
image=CustomImage( image=CustomImage(
icon_name="close-symbolic", icon_size=18 icon_name="close-symbolic", icon_size=18
), ),
visible=True, # Initially hidden visible=True,
on_clicked=lambda *_: self._close_single_notification_and_stop_propagation(latest_notification),
), ),
Box(v_expand=True), Box(v_expand=True),
], ],
@@ -173,7 +181,16 @@ class ExpandableNotificationGroup(Box):
), ),
Box( Box(
name="notification-count", name="notification-count",
orientation="v",
children=[ children=[
Button(
name="notification-close",
image=CustomImage(
icon_name="close-symbolic", icon_size=18
),
visible=True,
on_clicked=lambda *_: self._close_single_notification_and_stop_propagation(latest_notification),
),
Label( Label(
name="notification-count-label", name="notification-count-label",
label=f"{len(self.notifications)}", label=f"{len(self.notifications)}",
@@ -188,8 +205,7 @@ class ExpandableNotificationGroup(Box):
self.add(self.collapsed_eventbox) self.add(self.collapsed_eventbox)
# Create expanded state (hidden initially) # Note: expanded state creation moved to __init__
self.create_expanded_state()
def create_expanded_state(self): def create_expanded_state(self):
self.expanded_box = Box( self.expanded_box = Box(
@@ -269,19 +285,27 @@ class ExpandableNotificationGroup(Box):
return get_fallback_notification_icon((35, 35)) return get_fallback_notification_icon((35, 35))
def on_clicked(self, widget, event): def on_clicked(self, widget, event):
logger.debug(f"Notification group clicked: {self.app_name}, button: {event.button}")
if event.button == 1: # Left click if event.button == 1: # Left click
self.expand() if len(self.notifications) > 1: # Only expand if there are multiple notifications
self.expand()
else:
logger.debug("Single notification group - no expansion needed")
return True return True
def expand(self, *args): def expand(self, *args):
"""Expand to show all notifications in this group"""
self.is_expanded = True self.is_expanded = True
self.collapsed_eventbox.set_visible(False) self.collapsed_eventbox.set_visible(False)
self.expanded_box.set_visible(True) self.expanded_box.set_visible(True)
logger.debug(f"Expanded notification group: {self.app_name}")
def collapse(self, *args): def collapse(self, *args):
"""Collapse to show only the summary notification"""
self.is_expanded = False self.is_expanded = False
self.collapsed_eventbox.set_visible(True) self.collapsed_eventbox.set_visible(True)
self.expanded_box.set_visible(False) self.expanded_box.set_visible(False)
logger.debug(f"Collapsed notification group: {self.app_name}")
def close_all(self, *args): def close_all(self, *args):
# Close all notifications in this group # Close all notifications in this group
@@ -298,6 +322,25 @@ class ExpandableNotificationGroup(Box):
logger.error( logger.error(
f"Error removing notification {notification.cache_id}: {e}" f"Error removing notification {notification.cache_id}: {e}"
) )
def _close_single_notification(self, notification):
"""Close a single notification from this group"""
try:
cleanup_notification_specific_caches(
app_icon_source=getattr(notification, "app_icon_source", None),
notification_image_cache_key=getattr(
notification, "notification_image_cache_key", None
),
)
notification_service.remove_cached_notification(notification.cache_id)
logger.debug(f"Closed single notification: {notification.cache_id}")
except Exception as e:
logger.error(f"Error removing single notification {notification.cache_id}: {e}")
def _close_single_notification_and_stop_propagation(self, notification):
"""Close notification and prevent click from expanding the group"""
self._close_single_notification(notification)
return True # Stop event propagation
class NotificationCenterWidget(NotificationWidget): class NotificationCenterWidget(NotificationWidget):
@@ -454,10 +497,10 @@ class NotificationCenter(Window):
name="noti-center-box", name="noti-center-box",
) )
self.scrolled = ScrolledWindow(h_expand=False, v_expand=False) self.scrolled = ScrolledWindow(h_expand=True, v_expand=True)
self.notifications_box = Box( self.notifications_box = Box(
v_expand=False, v_expand=True,
h_expand=False, h_expand=True,
style="margin: 1px 0px 1px 1px;", style="margin: 1px 0px 1px 1px;",
orientation="v", orientation="v",
spacing=5, spacing=5,
@@ -465,17 +508,17 @@ class NotificationCenter(Window):
self.scrolled.add(self.notifications_box) self.scrolled.add(self.notifications_box)
main_box.add(self.scrolled) main_box.add(self.scrolled)
# # No notifications label # No notifications label
# self.not_found_label = Label( self.not_found_label = Label(
# label="No notifications", label="No notifications",
# h_align="center", h_align="center",
# v_align="center", v_align="center",
# h_expand=True, h_expand=True,
# v_expand=True, v_expand=True,
# style="color: #888888; font-style: italic; margin: 20px;", style="color: #888888; font-style: italic; margin: 20px;",
# visible=(notification_service.count == 0), visible=(notification_service.count == 0),
# ) )
# main_box.add(self.not_found_label) main_box.add(self.not_found_label)
self.clear_all_button = Button( self.clear_all_button = Button(
name="noti-clear-button", name="noti-clear-button",
@@ -488,7 +531,13 @@ class NotificationCenter(Window):
) )
main_box.add(self.button_centre_box) main_box.add(self.button_centre_box)
self.children = main_box self.revealer = Revealer(
child=main_box,
transition="slide-down",
transition_duration=600,
child_revealed=False,
)
self.children = self.revealer
# Load existing notifications and group them # Load existing notifications and group them
self._rebuild_notification_groups() self._rebuild_notification_groups()
@@ -639,8 +688,9 @@ class NotificationCenter(Window):
self.mousecapture = mousecapture self.mousecapture = mousecapture
def _set_mousecapture(self, visible): def _set_mousecapture(self, visible):
# No need to refresh on visibility change since we use signals self.revealer.child_revealed = visible
pass # # No need to refresh on visibility change since we use signals
# pass
def _on_destroy(self, *_): def _on_destroy(self, *_):
try: try:
+8 -3
View File
@@ -149,7 +149,7 @@
} }
#notification-show-less:hover { #notification-show-less:hover {
background-color: alpha(#fff, 0.1); background-color: alpha(#999, 0.7);
color: rgba(255, 255, 255, 0.9); color: rgba(255, 255, 255, 0.9);
} }
@@ -277,6 +277,9 @@
margin-bottom: 10px; margin-bottom: 10px;
} }
#notification-close-header {
margin-right: 10px;
}
#notification-close, #notification-close,
#notification-close-header { #notification-close-header {
background-color: alpha(#444, 0.8); background-color: alpha(#444, 0.8);
@@ -284,10 +287,12 @@
min-height: 23px; min-height: 23px;
border-radius: 50%; border-radius: 50%;
} }
#notification-close:hover, #notification-close:hover {
#notification-close-summery:hover #notification-close-header {
background-color: alpha(#666, 0.8); background-color: alpha(#666, 0.8);
min-width: 23px; min-width: 23px;
min-height: 23px; min-height: 23px;
border-radius: 50%; border-radius: 50%;
} }
#notification-close-summery:hover .notification-close-header button {
background-color: transparent;
}