Skip to content

Notifications

class NotificationCloseReason (value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

A reason for which a notification was closed

member EXPIRED 1

member DISMISSED_BY_USER 2

member CLOSED_BY_APPLICATION 3

member UNKNOWN 4

class NotificationImagePixmap (raw_variant: Variant)

Bases: object

A class for storing image data associated with a notification

classmethod deserialize (data: tuple[int, int, int, bool, int, int, str]) NotificationImagePixmap

Load image data from a serialized data tuple (using the serialize method) and return the newly created Pixmap object

  • Parameters: data (tuple *[*int , int , int , bool , int , int , str ]) — the tuple which is holding the image’s data
  • Returns: the newly loaded image pixmap
  • Return type: NotificationImagePixmap

def as_pixbuf () Pixbuf

Load a Pixbuf variant of this pixmap

  • Returns: the newly created pixbuf in which it has the contents of this pixmap
  • Return type: GdkPixbuf.Pixbuf

def serialize () tuple[int, int, int, bool, int, int, str]

Serialize this pixmap image into a tuple for ease of carrying and saving

  • Returns: the serialized pixmap image data
  • Return type: tuple[int, int, int, bool, int, int, str]

class NotificationAction (identifier: str, label: str, parent: Notification)

Bases: object

A notification action that can be invoked

attribute identifier str

attribute label str

attribute parent Notification

def invoke ()

Invoke this action

class NotificationSerializedData

Bases: TypedDict

attribute id int

attribute summary str

attribute body str

attribute timeout int

attribute urgency int

attribute actions list[tuple[str, str]]

class Notification (id: int, raw_variant: Variant, **kwargs)

Bases: Service

The notification class holds all the data of a specific notification (such as actions, images and sender’s info)

Default service constructor (base constructor)

  • Parameters: **kwargs

    mapped to signal connections (e.g. on_clicked=lambda *_: … connects the given function to the signal “clicked”, notify_my_property=my_func connects the given function to the signal “notify::my-property”)

signal closed (self, reason: object) NoneType

signal action_invoked (self, action: str) NoneType

property app_name str

The display name of the application sent this notification

  • Returns: sender’s display name
  • Return type: str

property app_icon str

An optional application icon name

  • Returns: sender’s named icon (or None)
  • Return type: str

property summary str

property body str

A multi-line body of text given by the sender (might contain markup)

  • Returns: this notification’s body text
  • Return type: str

property id int

The uniuqe identifier of this notification

  • Returns: this notification’s id
  • Return type: int

property replaces_id int

An optional ID of an existing notification that this notification is intended to replace

  • Returns: the id of the targetted notification (or None)
  • Return type: int

property timeout int

Expiration timeout (in milliseconds) since the display of the notification at which the notification should automatically get closed

  • Returns: timeout in milliseconds, -1 means whatever the user decides, 0 means the notification is supposed to never get closed
  • Return type: int

property urgency int

Urgency level of this notification

  • Returns: the urgency level as an integer, 0 for low, 1 for normal, 2 for critical
  • Return type: int

property actions list[NotificationAction]

A list of all the action this notification has

  • Returns: a list of notification actions
  • Return type: list[NotificationAction]

property image_pixmap NotificationImagePixmap

Raw image data supplied by the sender (if any)

  • Returns: raw image data stored in a pixmap object
  • Return type: NotificationImagePixmap

property image_file str

The image file path provided by the sender for this notification (if any)

  • Returns: the image file path
  • Return type: str

property image_pixbuf Pixbuf

A Pixbuf loaded from either image-pixmap or the image-file property

  • Returns: the newly loaded image pixbuf
  • Return type: GdkPixbuf.Pixbuf

classmethod deserialize (data: NotificationSerializedData, **kwargs) Notification

Deserialize a given serialized notification data into a newly created notification object

  • Parameters: data (NotificationSerializedData) — the serialized data to consume and covert to an object
  • Returns: the newly created notification objet
  • Return type: Notification

def serialize () NotificationSerializedData

Serialize this notification into a dictionary that can easily get converted into JSON

  • Returns: the serialized notification data (dict)
  • Return type: NotificationSerializedData

def invoke_action (action: str)

Invoke an action via its name

def close (reason: Literal['expired', 'dismissed-by-user', 'closed-by-application', 'unknown'] | NotificationCloseReason = NotificationCloseReason.DISMISSED_BY_USER)

Close this notification and notify the sender with a reason

  • Parameters: reason (Literal [ “expired” , “dismissed-by-user” , “closed-by-application” , “unknown” ] | NotificationCloseReason , optional) — the reason behind the close of this notification, defaults to NotificationCloseReason.DISMISSED_BY_USER

class Notifications (**kwargs)

Bases: Service

A server for watching in-coming notifications from running applications, in order for it to work, other notification daemons must be NOT running on the system

Default service constructor (base constructor)

  • Parameters: **kwargs

    mapped to signal connections (e.g. on_clicked=lambda *_: … connects the given function to the signal “clicked”, notify_my_property=my_func connects the given function to the signal “notify::my-property”)

signal changed (self) NoneType

signal notification_added (self, notification_id: int) NoneType

signal notification_removed (self, notification_id: int) NoneType

signal notification_closed (self, notification_id: int, reason: object) NoneType

property notifications dict[int, Notification]

A list of all the notifications received by this server

  • Returns: the list of notifications
  • Return type: dict[int, Notification]

def new_notification_id () int

Get the next notification id and increase the internal counter

  • Returns: the next id
  • Return type: int

def get_notification_from_id (notification_id: int) Notification | None

Lookup a notification via its identifier

  • Parameters: notification_id (int) — the notification’s id (gotten from the notification-added signal)
  • Returns: the desired notification object (if found)
  • Return type: Notification | None

def invoke_notification_action (notification_id: int, action: str)

Invoke a named action on a notification

  • Parameters:
    • notification_id (int) — the notification id of in which the action should be triggered
    • action (str) — the name of the action

def remove_notification (notification_id: int)

Remove a notification (without closing it) from the server

  • Parameters: notification_id (int) — the id of the notification

def close_notification (notification_id: int, reason: NotificationCloseReason = NotificationCloseReason.DISMISSED_BY_USER)

Close a notification and remove it from the server

  • Parameters:
    • notification_id (int) — the id of the notification
    • reason (NotificationCloseReason , optional) — the reason behind this notification begin closed, defaults to NotificationCloseReason.DISMISSED_BY_USER

def serialize () list[NotificationSerializedData]

Similar to Notification.serialize but it serializes all the notifications in the server instead

  • Returns: a list with all the serialized notifications in this server
  • Return type: list[NotificationSerializedData]

def deserialize (data: list[NotificationSerializedData])

Load a list of serialized notifications data

  • Parameters: data (list *[*NotificationSerializedData ]) — the list with serialized notifications