settings_proxy_dbus_service.py
Go to the documentation of this file.
1 # Copyright (c) 2011, Dirk Thomas, Dorian Scholz, TU Darmstadt
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following
12 # disclaimer in the documentation and/or other materials provided
13 # with the distribution.
14 # * Neither the name of the TU Darmstadt nor the names of its
15 # contributors may be used to endorse or promote products derived
16 # from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 
31 import dbus
32 
33 
34 class SettingsProxyDBusService(dbus.service.Object):
35  """DBus service of a 'Settings' instance."""
36 
37  def __init__(self, object_path):
38  super(SettingsProxyDBusService, self).__init__(object_path)
39  self._settings_proxy = None
40  self._group = None
41 
42  def set_settings(self, settings):
43  if settings is not None:
44  self._settings_proxy = settings._settings_proxy
45  self._group = settings._group
46  else:
47  self._settings_proxy = None
48  self._group = None
49 
50  @dbus.service.method('org.ros.qt_gui.Settings', in_signature='s', out_signature='av')
51  def all_keys(self, group):
52  return self._settings_proxy.all_keys(self._group + '/' + group)
53 
54  @dbus.service.method('org.ros.qt_gui.Settings', in_signature='s', out_signature='as')
55  def child_groups(self, group):
56  return self._settings_proxy.child_groups(self._group + '/' + group)
57 
58  @dbus.service.method('org.ros.qt_gui.Settings', in_signature='s', out_signature='as')
59  def child_keys(self, group):
60  return self._settings_proxy.child_keys(self._group + '/' + group)
61 
62  @dbus.service.method('org.ros.qt_gui.Settings', in_signature='ss', out_signature='b')
63  def contains(self, group, key):
64  return self._settings_proxy.contains(self._group + '/' + group, key)
65 
66  @dbus.service.method('org.ros.qt_gui.Settings', in_signature='ss', out_signature='')
67  def remove(self, group, key):
68  self._settings_proxy.remove(self._group + '/' + group, key)
69 
70  @dbus.service.method('org.ros.qt_gui.Settings', in_signature='ssv', out_signature='')
71  def set_value(self, group, key, value):
72  value = self._sanitize_value(value)
73  self._settings_proxy.set_value(self._group + '/' + group, key, value)
74 
75  @dbus.service.method('org.ros.qt_gui.Settings', in_signature='ssv', out_signature='v')
76  def value(self, group, key, default_value=None):
77  return self._settings_proxy.value(self._group + '/' + group, key, default_value)
78 
79  def _sanitize_value(self, value):
80  # transform DBus types to Python types to work with Pickle
81  if isinstance(value, dbus.Boolean):
82  value = bool(value)
83  elif isinstance(value,
84  (dbus.Byte, dbus.Int16, dbus.Int32, dbus.Int64,
85  dbus.UInt16, dbus.UInt32, dbus.UInt64)):
86  value = int(value)
87  elif isinstance(value, dbus.Double):
88  value = float(value)
89  elif isinstance(value, dbus.String):
90  value = str(value)
91  elif isinstance(value, dbus.UTF8String):
92  try:
93  value = unicode(value)
94  except NameError:
95  value = str(value)
96  return value
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService.set_value
def set_value(self, group, key, value)
Definition: settings_proxy_dbus_service.py:71
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService.value
def value(self, group, key, default_value=None)
Definition: settings_proxy_dbus_service.py:76
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService.contains
def contains(self, group, key)
Definition: settings_proxy_dbus_service.py:63
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService
Definition: settings_proxy_dbus_service.py:34
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService.all_keys
def all_keys(self, group)
Definition: settings_proxy_dbus_service.py:51
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService._settings_proxy
_settings_proxy
Definition: settings_proxy_dbus_service.py:39
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService._group
_group
Definition: settings_proxy_dbus_service.py:40
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService.child_keys
def child_keys(self, group)
Definition: settings_proxy_dbus_service.py:59
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService.remove
def remove(self, group, key)
Definition: settings_proxy_dbus_service.py:67
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService.__init__
def __init__(self, object_path)
Definition: settings_proxy_dbus_service.py:37
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService.set_settings
def set_settings(self, settings)
Definition: settings_proxy_dbus_service.py:42
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService.child_groups
def child_groups(self, group)
Definition: settings_proxy_dbus_service.py:55
qt_gui.settings_proxy_dbus_service.SettingsProxyDBusService._sanitize_value
def _sanitize_value(self, value)
Definition: settings_proxy_dbus_service.py:79


qt_gui
Author(s): Dirk Thomas
autogenerated on Sat Jun 25 2022 02:15:05