コード例 #1
0
ファイル: listnames.py プロジェクト: xiangnidj0910/Examples
def method2():
    sys.stdout.write("Method 2:\n")

    bus = QtDBus.QDBusConnection.sessionBus()
    dbus_iface = QtDBus.QDBusInterface('org.freedesktop.DBus',
                                       '/org/freedesktop/DBus',
                                       'org.freedesktop.DBus', bus)
    names = dbus_iface.call('ListNames').arguments()[0]

    # Mimic the output from the C++ version.
    sys.stdout.write('QVariant(QStringList, ("%s") )\n' % '", "'.join(names))
コード例 #2
0
sip.setapi('QVariant', 2)

import sys
from PyQt4 import QtCore, QtDBus


if __name__ == '__main__':
    app = QtCore.QCoreApplication(sys.argv)

    if not QtDBus.QDBusConnection.sessionBus().isConnected():
        sys.stderr.write("Cannot connect to the D-Bus session bus.\n"
                "To start it, run:\n"
                "\teval `dbus-launch --auto-syntax`\n");
        sys.exit(1)

    iface = QtDBus.QDBusInterface('com.trolltech.QtDBus.PingExample', '/', '',
            QtDBus.QDBusConnection.sessionBus())

    if iface.isValid():
        msg = iface.call('ping', sys.argv[1] if len(sys.argv) > 1 else "")
        reply = QtDBus.QDBusReply(msg)

        if reply.isValid():
            sys.stdout.write("Reply was: %s\n" % reply.value())
            sys.exit()

        sys.stderr.write("Call failed: %s\n" % reply.error().message())
        sys.exit(1)

    sys.stderr.write("%s\n" % QtDBus.QDBusConnection.sessionBus().lastError().message())
    sys.exit(1)