settings_proxy.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 from python_qt_binding.QtCore import QMutex, QMutexLocker, QObject
32 
33 
34 class SettingsProxy(QObject):
35  """Wrapper of a QSettings instance simplifying access of grouped data."""
36 
37  def __init__(self, qsettings):
38  super(SettingsProxy, self).__init__()
39  self.setObjectName('SettingsProxy')
40 
41  self._qsettings = qsettings
42  self._mutex = QMutex(QMutex.Recursive)
43 
44  def all_keys(self, group):
45  locker = QMutexLocker(self._mutex) # noqa: F841
46  self._qsettings.beginGroup(group)
47  keys = self._qsettings.allKeys()
48  self._qsettings.endGroup()
49  return keys
50 
51 # def begin_read_array(self, group):
52 
53 # def begin_write_array(self, group):
54 
55  def child_groups(self, group):
56  locker = QMutexLocker(self._mutex) # noqa: F841
57  self._qsettings.beginGroup(group)
58  groups = self._qsettings.childGroups()
59  self._qsettings.endGroup()
60  return groups
61 
62  def child_keys(self, group):
63  locker = QMutexLocker(self._mutex) # noqa: F841
64  self._qsettings.beginGroup(group)
65  keys = self._qsettings.childKeys()
66  self._qsettings.endGroup()
67  return keys
68 
69  def contains(self, group, key):
70  locker = QMutexLocker(self._mutex) # noqa: F841
71  self._qsettings.beginGroup(group)
72  key_exists = self._qsettings.contains(key)
73  self._qsettings.endGroup()
74  return key_exists
75 
76 # def end_array(self):
77 
78  def remove(self, group, key):
79  locker = QMutexLocker(self._mutex) # noqa: F841
80  self._qsettings.beginGroup(group)
81  self._qsettings.remove(key)
82  self._qsettings.endGroup()
83 
84 # def set_array_index(self, i):
85 
86  def set_value(self, group, key, value):
87  locker = QMutexLocker(self._mutex) # noqa: F841
88  self._qsettings.beginGroup(group)
89  self._qsettings.setValue(key, value)
90  self._qsettings.endGroup()
91 
92  def value(self, group, key, default_value=None):
93  locker = QMutexLocker(self._mutex) # noqa: F841
94  self._qsettings.beginGroup(group)
95  v = self._qsettings.value(key, default_value)
96  self._qsettings.endGroup()
97  return v
def set_value(self, group, key, value)
def value(self, group, key, default_value=None)


qt_gui
Author(s): Dirk Thomas
autogenerated on Thu Jun 6 2019 19:54:27