maestral.notify.notify

This module handles desktop notifications and supports multiple backends, depending on the platform.

Module Contents

Classes

NotificationLevel

Enumeration of notification levels

Notification

A desktop notification

DesktopNotifier

Cross-platform desktop notification emitter

MaestralDesktopNotifier

Desktop notification emitter for Maestral

MaestralDesktopNotificationHandler

A logging handler to send desktop notifications.

class maestral.notify.notify.DesktopNotifier(app_name: str, app_id: str)[source]

Cross-platform desktop notification emitter

Uses different backends depending on the platform version and available services. The Dbus backend requires a running asyncio loop. The Cocoa implementations will dispatch notifications without an event loop but require a running CFRunLoop in the main thread to react to user interactions with the notification. Packages such as rubicon.objc can be used to integrate asyncio with a CFRunLoop.

Parameters
  • app_name – Name of app which sends notifications.

  • app_id – Bundle identifier of the app. This is typically a reverse domain name such as ‘com.google.app’.

send(self, title: str, message: str, urgency: NotificationLevel = NotificationLevel.Normal, icon: Optional[str] = None, action: Optional[Callable] = None, buttons: Optional[Dict[str, Optional[Callable]]] = None)None[source]

Sends a desktop notification. Some arguments may be ignored, depending on the backend.

Parameters
  • title – Notification title.

  • message – Notification message.

  • urgency – Notification level: low, normal or critical. This is ignored by some implementations.

  • icon – Path to an icon to use for the notification, typically the app icon. This is ignored by some implementations, e.g., on macOS where the icon of the app bundle is always used.

  • action – Handler to call when the notification is clicked. This is ignored by some implementations.

  • buttons – A dictionary with button names and callbacks to show in the notification. This is ignored by some implementations.

class maestral.notify.notify.MaestralDesktopNotifier(config_name: str)[source]

Desktop notification emitter for Maestral

Desktop notifier with snooze functionality and variable notification levels.

Variables
  • NONE (int) – Notification level for no desktop notifications.

  • ERROR (int) – Notification level for errors.

  • SYNCISSUE (int) – Notification level for sync issues.

  • FILECHANGE (int) – Notification level for file changes.

NONE = 100[source]
ERROR = 40[source]
SYNCISSUE = 30[source]
FILECHANGE = 15[source]
classmethod level_number_to_name(cls, number: int)str[source]

Converts a Maestral notification level number to name.

classmethod level_name_to_number(cls, name: str)int[source]

Converts a Maestral notification level name to number.

property notify_level(self)int[source]

Custom notification level. Notifications with a lower level will be discarded.

property snoozed(self)float[source]

Time in minutes to snooze notifications. Applied to FILECHANGE level only.

notify(self, title: str, message: str, level: int = FILECHANGE, on_click: Optional[Callable] = None, buttons: Optional[Dict[str, Optional[Callable]]] = None)None[source]

Sends a desktop notification.

Parameters
  • title – Notification title.

  • message – Notification message.

  • level – Notification level of the message.

  • on_click – A callback to execute when the notification is clicked. The provided callable must not take any arguments.

  • buttons – A dictionary with button names and callbacks for the notification.

class maestral.notify.notify.MaestralDesktopNotificationHandler[source]

Bases: logging.Handler

A logging handler to send desktop notifications.

emit(self, record: logging.LogRecord)None[source]

Emits a logging message as a desktop notification.

Parameters

record – Log record.