Skip to content

Instantly share code, notes, and snippets.

Last active April 5, 2021 13:07
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
QtDBus demo with PyQt5
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PyQt5 import QtCore, QtDBus, QtWidgets
def notify(header, msg):
item = "org.freedesktop.Notifications"
path = "/org/freedesktop/Notifications"
interface = "org.freedesktop.Notifications"
app_name = "dbus_demo"
v = QtCore.QVariant(12321) # random int to identify all notifications
if v.convert(QtCore.QVariant.UInt):
id_replace = v
icon = ""
title = header
text = msg
actions_list = QtDBus.QDBusArgument([], QtCore.QMetaType.QStringList)
hint = []
time = 100 # milliseconds for display timeout
bus = QtDBus.QDBusConnection.sessionBus()
if not bus.isConnected():
print("Not connected to dbus!")
notify = QtDBus.QDBusInterface(item, path, interface, bus)
if notify.isValid():
x =, "Notify", app_name,
id_replace, icon, title, text,
actions_list, hint, time)
if x.errorName():
print("Failed to send notification!")
print("Invalid dbus interface")
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()
notify("hello header", "some message!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment