diff options
| author | Hugo Parente Lima <hugo.lima@openbossa.org> | 2010-04-30 16:08:23 -0300 |
|---|---|---|
| committer | Renato Filho <renato.filho@openbossa.org> | 2010-05-03 17:32:03 -0300 |
| commit | 59d0798159149be4bf9fd209b468a5b09d37d80a (patch) | |
| tree | 891f6064d927aadde617b26ff9f4963a3b2d64c7 /doc/codesnippets/examples/dbus/example-client.py | |
| parent | e7f6729d5b23931ba8a3ea30d80b15110cb4aa8f (diff) | |
Add dbus example do docs.
Reviewer: Bruno Araújo <bruno.araujo@openbossa.org>
Reviewer: Renato Araújo <renato.araujo@openbossa.org>
Diffstat (limited to 'doc/codesnippets/examples/dbus/example-client.py')
| -rwxr-xr-x | doc/codesnippets/examples/dbus/example-client.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/doc/codesnippets/examples/dbus/example-client.py b/doc/codesnippets/examples/dbus/example-client.py new file mode 100755 index 000000000..605d4b452 --- /dev/null +++ b/doc/codesnippets/examples/dbus/example-client.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# DBUS Client using PySide integration + +import sys +from traceback import print_exc + +# import python dbus module +import dbus +# import python dbus GLib mainloop support +import dbus.mainloop.glib +# import QtCore +from PySide.QtCore import * + +# signal handler +def button_clicked(): + print "button clicked" + +# main function +if __name__ == '__main__': + + # Enable glib main loop support + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + # Get the session bus + bus = dbus.SessionBus() + + try: + # Get the remote object + remote_object = bus.get_object("com.example.SampleService", + "/DBusWidget") + # Get the remote interface for the remote object + iface = dbus.Interface(remote_object, "com.example.SampleWidget") + except dbus.DBusException: + print_exc() + sys.exit(1) + + # Start the application + app = QCoreApplication([]) + + # Call some methods of the remote interface + iface.show() + iface.setText("Emit signal") + # connect the DBus signal clicked to the function button_clicked + iface.connect_to_signal("clicked", button_clicked) + iface.connect_to_signal("lastWindowClosed", app.quit) + + # enter in the main loop + app.exec_() |
