Cannot call klipper methods in dbus with python
I try to call methods from klipper bus with python. But I could not make it. Here is what i try:
>>> 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 <Prox开发者_JAVA技巧yObject 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'
As you can see it sets both proxy and interface. But I cannot call methods via this interface.
What can I do? What am i doing wrong?
Edit Solved:
Well when i look to "qdbusviewer" I saw the exact path of klipper. So changing
>> proxy = bus.get_object("org.kde.klipper","/org/kde/klipper")
this line with this:
>>> proxy = bus.get_object("org.kde.klipper","/klipper")
Solves the problem.
I hope this post help someone
After some try, I found the the mistake:
>>> proxy = bus.get_object("org.kde.klipper","/org/kde/klipper")
must be:
>>> proxy = bus.get_object("org.kde.klipper","/klipper")
this solved the problem
Looks quite scarry. It might be simpler to call qdbus
through bash
:
import os
system("qdbus org.kde.klipper /klipper getClipboardHistoryItem 0")
0 is for current selection, 1 is for following one - and so on.
精彩评论