Go to the documentation of this file.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 from python_qt_binding.QtCore import QMutex, QMutexLocker, QObject
00032
00033
00034 class SettingsProxy(QObject):
00035
00036 """Wrapper of a QSettings instance simplifying access of grouped data."""
00037
00038 def __init__(self, qsettings):
00039 super(SettingsProxy, self).__init__()
00040 self.setObjectName('SettingsProxy')
00041
00042 self._qsettings = qsettings
00043 self._mutex = QMutex(QMutex.Recursive)
00044
00045 def all_keys(self, group):
00046 locker = QMutexLocker(self._mutex)
00047 self._qsettings.beginGroup(group)
00048 keys = self._qsettings.allKeys()
00049 self._qsettings.endGroup()
00050 return keys
00051
00052
00053
00054
00055
00056 def child_groups(self, group):
00057 locker = QMutexLocker(self._mutex)
00058 self._qsettings.beginGroup(group)
00059 groups = self._qsettings.childGroups()
00060 self._qsettings.endGroup()
00061 return groups
00062
00063 def child_keys(self, group):
00064 locker = QMutexLocker(self._mutex)
00065 self._qsettings.beginGroup(group)
00066 keys = self._qsettings.childKeys()
00067 self._qsettings.endGroup()
00068 return keys
00069
00070 def contains(self, group, key):
00071 locker = QMutexLocker(self._mutex)
00072 self._qsettings.beginGroup(group)
00073 key_exists = self._qsettings.contains(key)
00074 self._qsettings.endGroup()
00075 return key_exists
00076
00077
00078
00079 def remove(self, group, key):
00080 locker = QMutexLocker(self._mutex)
00081 self._qsettings.beginGroup(group)
00082 self._qsettings.remove(key)
00083 self._qsettings.endGroup()
00084
00085
00086
00087 def set_value(self, group, key, value):
00088 locker = QMutexLocker(self._mutex)
00089 self._qsettings.beginGroup(group)
00090 self._qsettings.setValue(key, value)
00091 self._qsettings.endGroup()
00092
00093 def value(self, group, key, default_value=None):
00094 locker = QMutexLocker(self._mutex)
00095 self._qsettings.beginGroup(group)
00096 v = self._qsettings.value(key, default_value)
00097 self._qsettings.endGroup()
00098 return v