web-dev-qa-db-ja.com

PyQtを使用したDBusを使用したプログラミング

グローバルメニューをサポートするデスクトップ環境を作成しようとしています。メインタスクを開始する前に、PyQtで概念実証としてQtDBusで動作するdbusコードを取得しようとしています。以下は、d-feetから得たきれいに印刷された出力とメソッドシグネチャです。

GetMenus() -> (Array of [Struct of (Uint32,String,Object Path)] menus)

[(60817412L, u':1.155', '/com/canonical/menu/3A00004'),
 (58725289L, u':1.151', '/com/canonical/menu/38013A9'),
 (58720393L, u':1.151', '/com/canonical/menu/3800089'),
 (62916305L, u':1.159', '/com/canonical/menu/3C006D1'),
 (54526127L, u':1.129', '/com/canonical/menu/34000AF'),
 (58725701L, u':1.151', '/com/canonical/menu/3801545'),
 (25167093L, u':1.22', '/com/canonical/menu/18004F5'),
 (58726237L, u':1.151', '/com/canonical/menu/380175D'),
 (60825279L, u':1.155', '/com/canonical/menu/3A01EBF'),
 (58721371L, u':1.151', '/com/canonical/menu/380045B'),
 (25165828L, u':1.22', '/com/canonical/menu/1800004')]

これは私がPyQtで書いたコードに似たものを期待しています:

from PyQt4.QtGui import QApplication
from PyQt4.QtDBus import QDBus
from PyQt4.QtDBus import QDBusConnection
from PyQt4.QtDBus import QDBusInterface

desktop = QApplication([])
session_bus_connection = QDBusConnection.sessionBus()
service_name = 'com.canonical.AppMenu.Registrar'
service_path = 'com/canonical/AppMenu/Registrar'
interface = 'com.canonical.AppMenu.Registrar'
menu = QDBusInterface(service_name, service_path, interface, QDBusConnection.sessionBus())
reply = menu.call('GetMenus')
print reply.arguments()
desktop.exec_()

これは、上記のコードから実際に得られる出力です。

christopher@xx-pc:~/Documents/Code$ python desktop_dbus.py
process 2613: arguments to dbus_message_new_method_call() were incorrect, assertion "_dbus_check_is_valid_path (path)" failed in file ../../dbus/dbus-message.c line 1204.
This is normally a bug in some application using the D-Bus library.
process 2613: arguments to dbus_message_set_auto_start() were incorrect, assertion "message != NULL" failed in file ../../dbus/dbus-message.c line 2885.
This is normally a bug in some application using the D-Bus library.
process 2613: arguments to dbus_message_iter_init_append() were incorrect, assertion "message != NULL" failed in file ../../dbus/dbus-message.c line 2284.
This is normally a bug in some application using the D-Bus library.
QDBusConnection: error: could not send message to service "com.canonical.AppMenu.Registrar" path "com/canonical/AppMenu/Registrar" interface "org.freedesktop.DBus.Introspectable" member "Introspect": 
[]

メッセージが送信されない理由を誰か教えてもらえますか?

4
Christopher

このコメント による Jjed に基づく回答:

process 2613: arguments to dbus_message_new_method_call() were incorrect
 assertion "_dbus_check_is_valid_path (path)" failed in file ../../dbus/dbus-message.c line 1204.
This is normally a bug in some application using the D-Bus library.

これはあなたのservice_pathである問題を示しています。すべてのDBusパスは/で始まるため、変更する必要があります

service_path = 'com/canonical/AppMenu/Registrar'

service_path = '/com/canonical/AppMenu/Registrar'
2
Zanna