I'm trying to set up notifications for brightness controls that are replaced immediately when a new notification is sent. I've managed to create a test to get this working within the same python process/script but if a new process is run the notification is not replaced.
#!/usr/bin/env python
import dbus
import sys
import os
import time
item = 'org.freedesktop.Notifications'
path = '/org/freedesktop/Notifications'
interface = 'org.freedesktop.Notifications'
app_name = 'dbus test'
title = 'dbus test'
timeout = 5000 # Use seconds x 1000
notify_id_file = '/tmp/dbus-id-{}'.format(os.getenv('USER'))
try:
with open(notify_id_file, 'r') as f:
notify_id = dbus.UInt32(f.read())
except:
notify_id = dbus.UInt32(0)
icon = '/home/shane/.icons/Surfn/32/notifications/notification-display-brightness-full.svg'
hint = {'type': 'int', 'name': 'value', 'value': int(sys.argv[1])}
bus = dbus.SessionBus(private=False)
notif = bus.get_object(item, path)
notify = dbus.Interface(notif, interface)
notify_id = notify.Notify(app_name, notify_id, icon, title, '', '', hint, timeout)
with open(notify_id_file, 'w') as f:
f.write(str(notify_id))
# Emulating second call, works from within same process, not from another
time.sleep(1)
bus = dbus.SessionBus(private=False)
notif = bus.get_object(item, path)
notify = dbus.Interface(notif, interface)
with open(notify_id_file, 'r') as f:
notify_id = dbus.UInt32(f.read())
hint = {'type': 'int', 'name': 'value', 'value': int(sys.argv[1]) + 20}
notify_id = notify.Notify(app_name, notify_id, icon, title, '', '', hint, timeout)
with open(notify_id_file, 'w') as f:
f.write(str(notify_id))
I can't see what I'm doing wrong, especially seeing as it all works within the same process. It's almost like dbus isn't actually communicating across processes but the process has its own private connection or something?
Just in case it's important, I'm using:
- python 3.6.4
- dbus 1.12.4
- python-dbus 1.2.6
- notify-osd 0.9.35 (using the customizable leolik branch)
and this is all under i3 on arch linux.