From f5d0e22dc73efa59a8ca1cb37303ed8f86ef5985 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 13 Jan 2010 15:25:15 +0100 Subject: [PATCH] qt.base.preferences.Preferences now subclasses qtlib.preferences.Preferences. --- qt/base/preferences.py | 53 ++++-------------------------------------- 1 file changed, 5 insertions(+), 48 deletions(-) diff --git a/qt/base/preferences.py b/qt/base/preferences.py index 1118806c..d73da401 100644 --- a/qt/base/preferences.py +++ b/qt/base/preferences.py @@ -6,60 +6,21 @@ # which should be included with this package. The terms are also available at # http://www.hardcoded.net/licenses/hs_license -from PyQt4.QtCore import QSettings, QVariant +from qtlib.preferences import Preferences as PreferencesBase -from hsutil.misc import tryint - -def variant_to_py(v): - value = None - ok = False - t = v.type() - if t == QVariant.String: - value = unicode(v.toString()) - ok = True # anyway - # might be bool or int, try them - if v == 'true': - value = True - elif value == 'false': - value = False - else: - value = tryint(value, value) - elif t == QVariant.Int: - value, ok = v.toInt() - elif t == QVariant.Bool: - value, ok = v.toBool(), True - elif t in (QVariant.List, QVariant.StringList): - value, ok = map(variant_to_py, v.toList()), True - if not ok: - raise TypeError(u"Can't convert {0} of type {1}".format(repr(v), v.type())) - return value - -def py_to_variant(v): - if isinstance(v, (list, tuple)): - return QVariant(map(py_to_variant, v)) - return QVariant(v) - -class Preferences(object): +class Preferences(PreferencesBase): # (width, is_visible) COLUMNS_DEFAULT_ATTRS = [] def __init__(self): - self.reset() + PreferencesBase.__init__(self) self.reset_columns() def _load_specific(self, settings, get): # load prefs specific to the dg edition pass - def load(self): - self.reset() - settings = QSettings() - def get(name, default): - if settings.contains(name): - return variant_to_py(settings.value(name)) - else: - return default - + def _load_values(self, settings, get): self.filter_hardness = get('FilterHardness', self.filter_hardness) self.mix_file_kind = get('MixFileKind', self.mix_file_kind) self.use_regexp = get('UseRegexp', self.use_regexp) @@ -97,11 +58,7 @@ class Preferences(object): # save prefs specific to the dg edition pass - def save(self): - settings = QSettings() - def set_(name, value): - settings.setValue(name, py_to_variant(value)) - + def _save_values(self, settings, set_): set_('FilterHardness', self.filter_hardness) set_('MixFileKind', self.mix_file_kind) set_('UseRegexp', self.use_regexp)