desktop
desktop
¶
Desktop notifier backed by dbus-fast and the freedesktop Notifications spec.
BUS_NAME = 'org.freedesktop.Notifications'
module-attribute
¶
OBJECT_PATH = '/org/freedesktop/Notifications'
module-attribute
¶
INTERFACE_NAME = 'org.freedesktop.Notifications'
module-attribute
¶
CloseReason
¶
Bases: IntEnum
Reason a notification was closed, per the freedesktop spec.
EXPIRED = 1
class-attribute
instance-attribute
¶
The notification expired (timed out).
DISMISSED = 2
class-attribute
instance-attribute
¶
The notification was dismissed by the user.
CLOSED = 3
class-attribute
instance-attribute
¶
The notification was closed via CloseNotification.
UNDEFINED = 4
class-attribute
instance-attribute
¶
The notification server did not provide a reason.
DbusNotifier(app_name='terok')
¶
Send desktop notifications over the D-Bus session bus.
The connection is established lazily on the first notify call.
Action callbacks are dispatched from the ActionInvoked signal;
stale callbacks are cleaned up automatically on NotificationClosed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Application name sent with every notification. |
'terok'
|
Initialise with the given application name.
Source code in src/terok_clearance/notifications/desktop.py
connect()
async
¶
Idempotently open the session-bus connection and subscribe to signals.
Safe to call concurrently and repeatedly: the lock serialises racing callers so exactly one MessageBus is ever created for this notifier.
Source code in src/terok_clearance/notifications/desktop.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
notify(summary, body='', *, actions=(), timeout_ms=-1, hints=None, replaces_id=0, app_icon='', container_id='', container_name='', project='', task_id='', task_name='')
async
¶
Send a desktop notification.
Freedesktop notifications render summary + body + actions only,
so the structured identity kwargs (container_id and the
terok task triple) are dropped on the floor here — callers are
expected to have folded the user-facing identity into body
already. The kwargs stay in the signature for
Notifier conformance so callers
don't have to branch on notifier kind.
Source code in src/terok_clearance/notifications/desktop.py
on_action(notification_id, callback)
async
¶
Register a callback for when the user clicks an action button.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification_id
|
int
|
ID returned by |
required |
callback
|
Callable[[str], None]
|
Called with the |
required |
Source code in src/terok_clearance/notifications/desktop.py
close(notification_id)
async
¶
Close an active notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification_id
|
int
|
ID returned by |
required |
Source code in src/terok_clearance/notifications/desktop.py
disconnect()
async
¶
Tear down the session-bus connection.