我尝试为发送新通知时立即替换的亮度控件设置通知。我设法创建了一个测试,以便在同一个python进程/脚本中运行,但如果运行新进程,则不会替换通知。
#!/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))
我无法看到我做错了什么,特别是看到它在同一个过程中都有效。它几乎就像dbus实际上并不是跨进程进行通信,但是进程有自己的私有连接吗?
如果它很重要,我会使用:
这都是在linux linux上的i3下。