Skip to content

notification

dev_tool.event.handler.notification

NotificationEventHandler

A handler class for notification events.

This class processes notification events and delegates them to the notification service for display.

The constructor for the NotificationEventHandler class.

Parameters:

Source code in dev_tool/event/handler/notification.py
def __init__(self, notification_service: NotificationService) -> None:
    """
    The constructor for the NotificationEventHandler class.

    :param notification_service: The notification service instance.
    """

    self.notification_service = notification_service

notification_service = notification_service instance-attribute

handle

A method that handles notification events.

Parameters:

  • event (Event) –

    The event object to handle.

Source code in dev_tool/event/handler/notification.py
def handle(self, event: Event) -> None:
    """
    A method that handles notification events.

    :param event: The event object to handle.
    """

    message = str(event.data.get('message', ''))
    duration_value = event.data.get('duration', 5.0)
    persistent_value = event.data.get('persistent', False)
    identifier_value = event.data.get('identifier')
    stacktrace_value = event.data.get('stacktrace')

    duration = float(duration_value) if duration_value is not None else 5.0
    persistent = bool(persistent_value)
    identifier = str(identifier_value) if identifier_value is not None else None
    stacktrace = str(stacktrace_value) if stacktrace_value is not None else None

    match event.type:
        case AppEventType.NOTIFICATION_ERROR:
            self.notification_service.error_text(message)
        case AppEventType.NOTIFICATION_ERROR_BANNER:
            self.notification_service.error_banner(
                message,
                duration=duration,
                persistent=persistent,
                identifier=identifier,
                stacktrace=stacktrace
            )
        case AppEventType.NOTIFICATION_INFO:
            self.notification_service.info(message)
        case AppEventType.NOTIFICATION_INFO_BANNER:
            self.notification_service.info_banner(
                message,
                duration=duration,
                persistent=persistent,
                identifier=identifier
            )
        case AppEventType.NOTIFICATION_NORMAL:
            self.notification_service.normal_text(message)
        case AppEventType.NOTIFICATION_SUCCESS:
            self.notification_service.success_text(message)
        case AppEventType.NOTIFICATION_SUCCESS_BANNER:
            self.notification_service.success_banner(
                message,
                duration=duration,
                persistent=persistent,
                identifier=identifier
            )
        case AppEventType.NOTIFICATION_WARNING:
            self.notification_service.warning_text(message)

get_event_type staticmethod

A method that returns the event types this handler processes.

Returns:

Source code in dev_tool/event/handler/notification.py
@staticmethod
def get_event_type() -> list[AppEventType]:
    """
    A method that returns the event types this handler processes.

    :return: A list of event types.
    """

    return [
        AppEventType.NOTIFICATION_ERROR,
        AppEventType.NOTIFICATION_ERROR_BANNER,
        AppEventType.NOTIFICATION_INFO,
        AppEventType.NOTIFICATION_INFO_BANNER,
        AppEventType.NOTIFICATION_NORMAL,
        AppEventType.NOTIFICATION_SUCCESS,
        AppEventType.NOTIFICATION_SUCCESS_BANNER,
        AppEventType.NOTIFICATION_WARNING,
    ]