wijjit.core.notification_manager.NotificationManager
- class wijjit.core.notification_manager.NotificationManager(overlay_manager, terminal_width, terminal_height, position='top-right', spacing=1, margin=2, max_stack=5)[source]
Manager for notification stack and lifecycle.
This class manages multiple active notifications, handling their positioning in a stack, auto-dismissal based on timeouts, and integration with the overlay manager.
- Parameters:
overlay_manager (
OverlayManager) – Overlay manager instance for displaying notificationsterminal_width (
int) – Current terminal widthterminal_height (
int) – Current terminal heightposition (
str, optional) – Stack position: “top-right”, “top-left”, “bottom-right”, “bottom-left” (default: “top-right”)spacing (
int, optional) – Vertical spacing between stacked notifications (default: 1)margin (
int, optional) – Margin from screen edges (default: 2)max_stack (
intorNone, optional) – Maximum number of concurrent notifications. When limit is reached, oldest notifications are automatically dismissed. None = unlimited (default: 5)
- Variables:
overlay_manager (
OverlayManager) – Overlay manager referenceterminal_width (
int) – Terminal widthterminal_height (
int) – Terminal heightposition (
str) – Stack positionspacing (
int) – Spacing between notificationsmargin (
int) – Edge marginnotifications (
list) – List of active notifications (oldest first)_lock (
threading.Lock) – Thread lock for protecting notification list access
Notes
All notification list access is protected by a threading.Lock to ensure thread safety when notifications are added, removed, or checked from multiple threads or async tasks.
- __init__(overlay_manager, terminal_width, terminal_height, position='top-right', spacing=1, margin=2, max_stack=5)[source]
Methods
__init__(overlay_manager, terminal_width, ...)add(element[, duration, on_close])Add a notification to the stack.
Check for expired notifications and remove them (synchronous).
Check for expired notifications and remove them (asynchronous).
clear()Remove all notifications.
Dismiss the oldest notification.
Dismiss the topmost (most recent) notification.
is_empty()Check if there are any active notifications (thread-safe).
remove(notification_id)Remove a notification from the stack.
Update positions of all notifications in the stack.
update_terminal_size(width, height)Update terminal size and reposition notifications.
- add(element, duration=3.0, on_close=None)[source]
Add a notification to the stack.
If max_stack is set and the stack is full, the oldest notification will be automatically dismissed before adding the new one.
- Parameters:
- Returns:
Notification ID for manual dismissal
- Return type:
- check_expired()[source]
Check for expired notifications and remove them (synchronous).
- Returns:
True if any notifications were removed, False otherwise
- Return type:
- async check_expired_async()[source]
Check for expired notifications and remove them (asynchronous).
This async version allows the event loop to process other tasks while checking and removing expired notifications.
- Returns:
True if any notifications were removed, False otherwise
- Return type:
- update_positions()[source]
Update positions of all notifications in the stack.
This should be called after adding/removing notifications or when terminal size changes.
- Return type:
None
- dismiss_oldest()[source]
Dismiss the oldest notification.
- Returns:
True if a notification was dismissed, False if none exist
- Return type: