From 56462039eb0696059a25f2f224a263eaa153250c Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Fri, 31 Oct 2014 14:35:53 -0700 Subject: [PATCH 1/2] Fix GConf examples --- dbus/service.py | 2 +- examples/Makefile.am | 7 ++++-- examples/example-async-client.py | 0 examples/example-client.py | 0 examples/example-service.py | 0 examples/example-signal-emitter.py | 0 examples/example-signal-recipient.py | 0 examples/gconf-proxy-client.py | 5 +---- examples/gconf-proxy-service2.py | 43 ++++++++++++++++++------------------ examples/list-system-services.py | 0 10 files changed, 29 insertions(+), 28 deletions(-) mode change 100644 => 100755 examples/example-async-client.py mode change 100644 => 100755 examples/example-client.py mode change 100644 => 100755 examples/example-service.py mode change 100644 => 100755 examples/example-signal-emitter.py mode change 100644 => 100755 examples/example-signal-recipient.py mode change 100644 => 100755 examples/gconf-proxy-client.py mode change 100644 => 100755 examples/gconf-proxy-service2.py mode change 100644 => 100755 examples/list-system-services.py diff --git a/dbus/service.py b/dbus/service.py index b1fc21d..2953229 100644 --- a/dbus/service.py +++ b/dbus/service.py @@ -23,7 +23,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -__all__ = ('BusName', 'Object', 'method', 'signal') +__all__ = ('BusName', 'Object', 'FallbackObject', 'method', 'signal') __docformat__ = 'restructuredtext' import sys diff --git a/examples/Makefile.am b/examples/Makefile.am index 316b4bb..df241a6 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -4,5 +4,8 @@ EXTRA_DIST = \ example-service.py \ example-signal-emitter.py \ example-signal-recipient.py \ - list-system-services.py -# miss out the gconf examples for now - they don't work + gconf-proxy-client.py \ + gconf-proxy-service2.py \ + list-system-services.py \ + unix-fd-client.py \ + unix-fd-service.py diff --git a/examples/example-async-client.py b/examples/example-async-client.py old mode 100644 new mode 100755 diff --git a/examples/example-client.py b/examples/example-client.py old mode 100644 new mode 100755 diff --git a/examples/example-service.py b/examples/example-service.py old mode 100644 new mode 100755 diff --git a/examples/example-signal-emitter.py b/examples/example-signal-emitter.py old mode 100644 new mode 100755 diff --git a/examples/example-signal-recipient.py b/examples/example-signal-recipient.py old mode 100644 new mode 100755 diff --git a/examples/gconf-proxy-client.py b/examples/gconf-proxy-client.py old mode 100644 new mode 100755 index e485796..2e440f4 --- a/examples/gconf-proxy-client.py +++ b/examples/gconf-proxy-client.py @@ -1,7 +1,5 @@ #!/usr/bin/env python -print "WARNING: this hasn't been updated to current API yet, and might not work" - # Copyright (C) 2004-2006 Red Hat Inc. # Copyright (C) 2005-2007 Collabora Ltd. # @@ -30,8 +28,7 @@ import dbus gconf_key = "/desktop/gnome/file_views/icon_theme" bus = dbus.SessionBus() -gconf_service = bus.get_service("org.gnome.GConf") -gconf_key_object = gconf_service.get_object("/org/gnome/GConf" + gconf_key, "org.gnome.GConf") +gconf_key_object = dbus.Interface(bus.get_object("org.gnome.GConf.Example", "/org/gnome/GConf" + gconf_key), "org.gnome.GConf") value = gconf_key_object.getString() diff --git a/examples/gconf-proxy-service2.py b/examples/gconf-proxy-service2.py old mode 100644 new mode 100755 index f805b77..7ce132b --- a/examples/gconf-proxy-service2.py +++ b/examples/gconf-proxy-service2.py @@ -1,6 +1,4 @@ #!/usr/bin/env python -print "WARNING: this hasn't been updated to current API yet, and might not work" -#FIXME: doesn't work with the new bindings # Copyright (C) 2004-2006 Red Hat Inc. # Copyright (C) 2005-2007 Collabora Ltd. @@ -26,36 +24,39 @@ print "WARNING: this hasn't been updated to current API yet, and might not work" # DEALINGS IN THE SOFTWARE. import dbus +import dbus.mainloop.glib +import dbus.service import gobject import gconf -class GConfService(dbus.Service): +dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) +# there is a real service called "org.gnome.GConf"; don't collide with it. +name = dbus.service.BusName("org.gnome.GConf.Example", dbus.SessionBus()) + +class GConfObject(dbus.service.FallbackObject): def __init__(self): - dbus.Service.__init__(self, "org.gnome.GConf", dbus.SessionBus()) + dbus.service.FallbackObject.__init__(self, dbus.SessionBus(), '/org/gnome/GConf') + self.client = gconf.client_get_default() - gconf_object_tree = self.GConfObjectTree(self) - - class GConfObjectTree(dbus.ObjectTree): - def __init__(self, service): - dbus.ObjectTree.__init__(self, "/org/gnome/GConf", service) + @dbus.service.method("org.gnome.GConf", in_signature='', out_signature='s', rel_path_keyword='object_path') + def getString(self, object_path): + return self.client.get_string(object_path) - self.client = gconf.client_get_default() + @dbus.service.method("org.gnome.GConf", in_signature='s', out_signature='', rel_path_keyword='object_path') + def setString(self, value, object_path): + self.client.set_string(object_path, value) - def object_method_called(self, message, object_path, method_name, argument_list): - print ("Method %s called on GConf key %s" % (method_name, object_path)) + @dbus.service.method("org.gnome.GConf", in_signature='', out_signature='i', rel_path_keyword='object_path') + def getInt(self, object_path): + return self.client.get_int(object_path) - if "getString" == method_name: - return self.client.get_string(object_path) - elif "setString" == method_name: - self.client.set_int(object_path, argument_list[0]) - elif "getInt" == method_name: - return self.client.get_int(object_path) - elif "setInt" == method_name: - self.client.set_int(object_path, argument_list[0]) + @dbus.service.method("org.gnome.GConf", in_signature='i', out_signature='', rel_path_keyword='object_path') + def setInt(self, value, object_path): + self.client.set_int(object_path, value) -gconf_service = GConfService() +gconf_service = GConfObject() print ("GConf Proxy service started.") print ("Run 'gconf-proxy-client.py' to fetch a GConf key through the proxy...") diff --git a/examples/list-system-services.py b/examples/list-system-services.py old mode 100644 new mode 100755 -- 2.1.1