Cannot call klipper methods in dbus with python

匿名 (未验证) 提交于 2019-12-03 08:57:35

问题:

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 <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' 

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

回答1:

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



回答2:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!