Skip to content

service

dev_tool.services.notification.service

Notification dataclass

A data class representing a single notification with expiration logic.

This class contains notification details including message, type, format, timing information, and display preferences.

message instance-attribute

notification_type instance-attribute

notification_format instance-attribute

timestamp instance-attribute

duration = 5.0 class-attribute instance-attribute

persistent = False class-attribute instance-attribute

show_prefix = False class-attribute instance-attribute

identifier = None class-attribute instance-attribute

expired property

A property that checks if notification has expired based on timestamp and duration.

Returns:

  • bool

    True if the notification has expired, False otherwise.

remaining_time property

A property that calculates remaining display time for non-persistent notifications.

Returns:

  • float

    The remaining time in seconds, or infinity for persistent notifications.

NotificationService

A thread-safe singleton service for managing application notifications.

This class provides centralized notification management with support for different notification types, formats, and lifecycle management.

The constructor for the NotificationService class.

Initializes the service with an empty notification list and thread safety.

Source code in dev_tool/services/notification/service.py
def __init__(self) -> None:
    """
    The constructor for the NotificationService class.

    Initializes the service with an empty notification list and thread safety.
    """

    if hasattr(self, '_initialized'):
        return

    self._initialized = True
    self._notifications = []
    self._lock = threading.Lock()

__new__

A class method that creates a singleton instance with thread safety.

Returns:

  • Self

    The singleton NotificationService instance.

Source code in dev_tool/services/notification/service.py
def __new__(cls) -> Self:
    """
    A class method that creates a singleton instance with thread safety.

    :return: The singleton NotificationService instance.
    """

    if cls._instance is None:
        with cls._lock:
            if cls._instance is None:
                cls._instance = super().__new__(cls)

    return cls._instance

add_notification

A method that adds a new notification to the active list.

Parameters:

  • message (str) –

    The notification message text.

  • notification_type (NotificationType, default: INFO ) –

    The type of notification for styling.

  • notification_format (NotificationFormat, default: BANNER ) –

    The display format for the notification.

  • duration (float, default: 5.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • show_prefix (bool, default: False ) –

    Whether to show the notification type prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def add_notification(
    self,
    message: str,
    notification_type: NotificationType = NotificationType.INFO,
    notification_format: NotificationFormat = NotificationFormat.BANNER,
    duration: float = 5.0,
    persistent: bool = False,
    show_prefix: bool = False,
    identifier: str | None = None
) -> None:
    """
    A method that adds a new notification to the active list.

    :param message: The notification message text.
    :param notification_type: The type of notification for styling.
    :param notification_format: The display format for the notification.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param show_prefix: Whether to show the notification type prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    notification = Notification(
        message=message,
        notification_type=notification_type,
        notification_format=notification_format,
        timestamp=time.time(),
        duration=duration,
        persistent=persistent,
        show_prefix=show_prefix,
        identifier=identifier
    )

    with self._lock:
        self._notifications.append(notification)

clear

A method that removes all notifications from the active list.

Source code in dev_tool/services/notification/service.py
def clear(self) -> None:
    """A method that removes all notifications from the active list."""

    with self._lock:
        self._notifications.clear()

dismiss

A method that removes a specific notification from the active list.

Parameters:

  • notification (Notification) –

    The notification object to remove.

Source code in dev_tool/services/notification/service.py
def dismiss(self, notification: Notification) -> None:
    """
    A method that removes a specific notification from the active list.

    :param notification: The notification object to remove.
    """

    with self._lock:
        if notification in self._notifications:
            self._notifications.remove(notification)

dismiss_by_identifier

A method that removes notifications with a specific identifier.

Parameters:

  • identifier (str) –

    The identifier to match for removal.

Source code in dev_tool/services/notification/service.py
def dismiss_by_identifier(self, identifier: str) -> None:
    """
    A method that removes notifications with a specific identifier.

    :param identifier: The identifier to match for removal.
    """

    with self._lock:
        self._notifications = [
            n for n in self._notifications
            if n.identifier != identifier
        ]

error

A method that adds an error notification with red styling.

Parameters:

  • message (str) –

    The error message text.

  • duration (float, default: 10.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • banner (bool, default: False ) –

    Whether to use banner format instead of text format.

  • show_prefix (bool, default: False ) –

    Whether to show the error prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def error(self, message: str, duration: float = 10.0, persistent: bool = False, banner: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds an error notification with red styling.

    :param message: The error message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param banner: Whether to use banner format instead of text format.
    :param show_prefix: Whether to show the error prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    format_type = NotificationFormat.BANNER if banner else NotificationFormat.TEXT
    self.add_notification(message, NotificationType.ERROR, format_type, duration, persistent, show_prefix, identifier)

error_banner

A method that adds an error notification with banner format.

Parameters:

  • message (str) –

    The error message text.

  • duration (float, default: 10.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • show_prefix (bool, default: False ) –

    Whether to show the error prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def error_banner(self, message: str, duration: float = 10.0, persistent: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds an error notification with banner format.

    :param message: The error message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param show_prefix: Whether to show the error prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    self.add_notification(message, NotificationType.ERROR, NotificationFormat.BANNER, duration, persistent, show_prefix, identifier)

error_text

A method that adds an error notification with text format.

Parameters:

  • message (str) –

    The error message text.

  • duration (float, default: 10.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • show_prefix (bool, default: False ) –

    Whether to show the error prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def error_text(self, message: str, duration: float = 10.0, persistent: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds an error notification with text format.

    :param message: The error message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param show_prefix: Whether to show the error prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    self.add_notification(message, NotificationType.ERROR, NotificationFormat.TEXT, duration, persistent, show_prefix, identifier)

flush

A method that clears all active notifications.

Source code in dev_tool/services/notification/service.py
def flush(self) -> None:
    """A method that clears all active notifications."""

    with self._lock:
        self._notifications.clear()

get_active

A method that gets active notifications and cleans up expired ones.

Returns:

Source code in dev_tool/services/notification/service.py
def get_active(self) -> list[Notification]:
    """
    A method that gets active notifications and cleans up expired ones.

    :return: A list of active notification objects.
    """

    with self._lock:
        active = [
            notification
            for notification in self._notifications
            if not notification.expired
        ]

        self._notifications = active
        return active.copy()

info

A method that adds an info notification with blue styling.

Parameters:

  • message (str) –

    The info message text.

  • duration (float, default: 5.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • banner (bool, default: False ) –

    Whether to use banner format instead of text format.

  • show_prefix (bool, default: False ) –

    Whether to show the info prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def info(self, message: str, duration: float = 5.0, persistent: bool = False, banner: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds an info notification with blue styling.

    :param message: The info message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param banner: Whether to use banner format instead of text format.
    :param show_prefix: Whether to show the info prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    format_type = NotificationFormat.BANNER if banner else NotificationFormat.TEXT
    self.add_notification(message, NotificationType.INFO, format_type, duration, persistent, show_prefix, identifier)

info_banner

A method that adds an info notification with banner format.

Parameters:

  • message (str) –

    The info message text.

  • duration (float, default: 5.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • show_prefix (bool, default: False ) –

    Whether to show the info prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def info_banner(self, message: str, duration: float = 5.0, persistent: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds an info notification with banner format.

    :param message: The info message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param show_prefix: Whether to show the info prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    self.add_notification(message, NotificationType.INFO, NotificationFormat.BANNER, duration, persistent, show_prefix, identifier)

info_text

A method that adds an info notification with text format.

Parameters:

  • message (str) –

    The info message text.

  • duration (float, default: 5.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • show_prefix (bool, default: False ) –

    Whether to show the info prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def info_text(self, message: str, duration: float = 5.0, persistent: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds an info notification with text format.

    :param message: The info message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param show_prefix: Whether to show the info prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    self.add_notification(message, NotificationType.INFO, NotificationFormat.TEXT, duration, persistent, show_prefix, identifier)

normal

A method that adds a normal notification with plain styling.

Parameters:

  • message (str) –

    The notification message text.

  • duration (float, default: 5.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • banner (bool, default: False ) –

    Whether to use banner format instead of text format.

  • show_prefix (bool, default: False ) –

    Whether to show the normal prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def normal(self, message: str, duration: float = 5.0, persistent: bool = False, banner: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds a normal notification with plain styling.

    :param message: The notification message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param banner: Whether to use banner format instead of text format.
    :param show_prefix: Whether to show the normal prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    format_type = NotificationFormat.BANNER if banner else NotificationFormat.TEXT
    self.add_notification(message, NotificationType.NORMAL, format_type, duration, persistent, show_prefix, identifier)

normal_banner

A method that adds a normal notification with banner format.

Parameters:

  • message (str) –

    The notification message text.

  • duration (float, default: 5.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • show_prefix (bool, default: False ) –

    Whether to show the normal prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def normal_banner(self, message: str, duration: float = 5.0, persistent: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds a normal notification with banner format.

    :param message: The notification message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param show_prefix: Whether to show the normal prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    self.add_notification(message, NotificationType.NORMAL, NotificationFormat.BANNER, duration, persistent, show_prefix, identifier)

normal_text

A method that adds a normal notification with text format.

Parameters:

  • message (str) –

    The notification message text.

  • duration (float, default: 5.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • show_prefix (bool, default: False ) –

    Whether to show the normal prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def normal_text(self, message: str, duration: float = 5.0, persistent: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds a normal notification with text format.

    :param message: The notification message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param show_prefix: Whether to show the normal prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    self.add_notification(message, NotificationType.NORMAL, NotificationFormat.TEXT, duration, persistent, show_prefix, identifier)

success

A method that adds a success notification with green styling.

Parameters:

  • message (str) –

    The success message text.

  • duration (float, default: 3.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • banner (bool, default: False ) –

    Whether to use banner format instead of text format.

  • show_prefix (bool, default: False ) –

    Whether to show the success prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def success(self, message: str, duration: float = 3.0, persistent: bool = False, banner: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds a success notification with green styling.

    :param message: The success message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param banner: Whether to use banner format instead of text format.
    :param show_prefix: Whether to show the success prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    format_type = NotificationFormat.BANNER if banner else NotificationFormat.TEXT
    self.add_notification(message, NotificationType.SUCCESS, format_type, duration, persistent, show_prefix, identifier)

success_banner

A method that adds a success notification with banner format.

Parameters:

  • message (str) –

    The success message text.

  • duration (float, default: 3.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • show_prefix (bool, default: False ) –

    Whether to show the success prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def success_banner(self, message: str, duration: float = 3.0, persistent: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds a success notification with banner format.

    :param message: The success message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param show_prefix: Whether to show the success prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    self.add_notification(message, NotificationType.SUCCESS, NotificationFormat.BANNER, duration, persistent, show_prefix, identifier)

success_text

A method that adds a success notification with text format.

Parameters:

  • message (str) –

    The success message text.

  • duration (float, default: 3.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • show_prefix (bool, default: False ) –

    Whether to show the success prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def success_text(self, message: str, duration: float = 3.0, persistent: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds a success notification with text format.

    :param message: The success message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param show_prefix: Whether to show the success prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    self.add_notification(message, NotificationType.SUCCESS, NotificationFormat.TEXT, duration, persistent, show_prefix, identifier)

warning

A method that adds a warning notification with yellow styling.

Parameters:

  • message (str) –

    The warning message text.

  • duration (float, default: 7.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • banner (bool, default: False ) –

    Whether to use banner format instead of text format.

  • show_prefix (bool, default: False ) –

    Whether to show the warning prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def warning(self, message: str, duration: float = 7.0, persistent: bool = False, banner: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds a warning notification with yellow styling.

    :param message: The warning message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param banner: Whether to use banner format instead of text format.
    :param show_prefix: Whether to show the warning prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    format_type = NotificationFormat.BANNER if banner else NotificationFormat.TEXT
    self.add_notification(message, NotificationType.WARNING, format_type, duration, persistent, show_prefix, identifier)

warning_banner

A method that adds a warning notification with banner format.

Parameters:

  • message (str) –

    The warning message text.

  • duration (float, default: 7.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • show_prefix (bool, default: False ) –

    Whether to show the warning prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def warning_banner(self, message: str, duration: float = 7.0, persistent: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds a warning notification with banner format.

    :param message: The warning message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param show_prefix: Whether to show the warning prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    self.add_notification(message, NotificationType.WARNING, NotificationFormat.BANNER, duration, persistent, show_prefix, identifier)

warning_text

A method that adds a warning notification with text format.

Parameters:

  • message (str) –

    The warning message text.

  • duration (float, default: 7.0 ) –

    The display duration in seconds.

  • persistent (bool, default: False ) –

    Whether the notification should persist until dismissed.

  • show_prefix (bool, default: False ) –

    Whether to show the warning prefix.

  • identifier (str | None, default: None ) –

    Optional identifier for targeted dismissal.

Source code in dev_tool/services/notification/service.py
def warning_text(self, message: str, duration: float = 7.0, persistent: bool = False, show_prefix: bool = False, identifier: str | None = None) -> None:
    """
    A method that adds a warning notification with text format.

    :param message: The warning message text.
    :param duration: The display duration in seconds.
    :param persistent: Whether the notification should persist until dismissed.
    :param show_prefix: Whether to show the warning prefix.
    :param identifier: Optional identifier for targeted dismissal.
    """

    self.add_notification(message, NotificationType.WARNING, NotificationFormat.TEXT, duration, persistent, show_prefix, identifier)