我尝试用python从klipper总线调用方法。但我做不到。这是我尝试的:
>>> import dbus
>>> bus = dbus.SessionBus()
>>> proxy = bus.get_object("org.kde.klipper","/org/kde/klipper")
>>> print proxy
<ProxyObject wrapping <dbus._dbus.SessionBus (session) at 0x7fc249da3bf0> :1.67 /org/kde/klipper at 0x7fc249dc16d0>
>>> iface = dbus.Interface(proxy,"org.kde.klipper.klipper")
>>> print iface
<Interface <ProxyObject wrapping <dbus._dbus.SessionBus (session) at 0x7fc249da3bf0> :1.67 /org/kde/klipper at 0x7fc249dc16d0> implementing 'org.kde.klipper.klipper' at 0x7fc249dc1790>
>>> print iface.getClipboardContents()
ERROR:dbus.proxies:Introspect error on :1.67:/org/kde/klipper: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownObject: No such object path '/org/kde/klipper'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/dbus/proxies.py", line 68, in __call__
return self._proxy_method(*args, **keywords)
File "/usr/lib/python2.6/site-packages/dbus/proxies.py", line 140, in __call__
**keywords)
File "/usr/lib/python2.6/site-packages/dbus/connection.py", line 622, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownObject: No such object path '/org/kde/klipper'
正如您所看到的,它设置了代理和接口。但我不能通过这个界面调用方法。
我该怎么办?我做错了什么?
编辑已解决:
当我看到“qdbusviewer”时,我看到了klipper的确切路径。 如此改变
>> proxy = bus.get_object("org.kde.klipper","/org/kde/klipper")
这一行:
>>> proxy = bus.get_object("org.kde.klipper","/klipper")
解决问题。
我希望这篇文章可以帮助某人
答案 0 :(得分:1)
经过一番尝试,我发现了错误:
>>> proxy = bus.get_object("org.kde.klipper","/org/kde/klipper")
一定是:
>>> proxy = bus.get_object("org.kde.klipper","/klipper")
这解决了问题
答案 1 :(得分:0)
看起来很伤心。通过qdbus
致电bash
可能更简单:
import os
system("qdbus org.kde.klipper /klipper getClipboardHistoryItem 0")
0表示当前选择,1表示后续选择 - 依此类推。