00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 import dbus
00032
00033
00034 class SettingsProxyDBusService(dbus.service.Object):
00035
00036 """DBus service of a 'Settings' instance."""
00037
00038 def __init__(self, object_path):
00039 super(SettingsProxyDBusService, self).__init__(object_path)
00040 self._settings_proxy = None
00041 self._group = None
00042
00043 def set_settings(self, settings):
00044 if settings is not None:
00045 self._settings_proxy = settings._settings_proxy
00046 self._group = settings._group
00047 else:
00048 self._settings_proxy = None
00049 self._group = None
00050
00051 @dbus.service.method('org.ros.qt_gui.Settings', in_signature='s', out_signature='av')
00052 def all_keys(self, group):
00053 return self._settings_proxy.all_keys(self._group + '/' + group)
00054
00055 @dbus.service.method('org.ros.qt_gui.Settings', in_signature='s', out_signature='as')
00056 def child_groups(self, group):
00057 return self._settings_proxy.child_groups(self._group + '/' + group)
00058
00059 @dbus.service.method('org.ros.qt_gui.Settings', in_signature='s', out_signature='as')
00060 def child_keys(self, group):
00061 return self._settings_proxy.child_keys(self._group + '/' + group)
00062
00063 @dbus.service.method('org.ros.qt_gui.Settings', in_signature='ss', out_signature='b')
00064 def contains(self, group, key):
00065 return self._settings_proxy.contains(self._group + '/' + group, key)
00066
00067 @dbus.service.method('org.ros.qt_gui.Settings', in_signature='ss', out_signature='')
00068 def remove(self, group, key):
00069 self._settings_proxy.remove(self._group + '/' + group, key)
00070
00071 @dbus.service.method('org.ros.qt_gui.Settings', in_signature='ssv', out_signature='')
00072 def set_value(self, group, key, value):
00073 value = self._sanitize_value(value)
00074 self._settings_proxy.set_value(self._group + '/' + group, key, value)
00075
00076 @dbus.service.method('org.ros.qt_gui.Settings', in_signature='ssv', out_signature='v')
00077 def value(self, group, key, default_value=None):
00078 return self._settings_proxy.value(self._group + '/' + group, key, default_value)
00079
00080 def _sanitize_value(self, value):
00081
00082 if isinstance(value, dbus.Boolean):
00083 value = bool(value)
00084 elif isinstance(value, (dbus.Byte, dbus.Int16, dbus.Int32, dbus.Int64, dbus.UInt16, dbus.UInt32, dbus.UInt64)):
00085 value = int(value)
00086 elif isinstance(value, dbus.Double):
00087 value = float(value)
00088 elif isinstance(value, dbus.String):
00089 value = str(value)
00090 elif isinstance(value, dbus.UTF8String):
00091 value = unicode(value)
00092 return value