1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2024-11-04 15:29:02 +00:00

qt.base.preferences.Preferences now subclasses qtlib.preferences.Preferences.

This commit is contained in:
Virgil Dupras 2010-01-13 15:25:15 +01:00
parent dc5ba01f1e
commit f5d0e22dc7

View File

@ -6,60 +6,21 @@
# which should be included with this package. The terms are also available at # which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/hs_license # 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 class Preferences(PreferencesBase):
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):
# (width, is_visible) # (width, is_visible)
COLUMNS_DEFAULT_ATTRS = [] COLUMNS_DEFAULT_ATTRS = []
def __init__(self): def __init__(self):
self.reset() PreferencesBase.__init__(self)
self.reset_columns() self.reset_columns()
def _load_specific(self, settings, get): def _load_specific(self, settings, get):
# load prefs specific to the dg edition # load prefs specific to the dg edition
pass pass
def load(self): def _load_values(self, settings, get):
self.reset()
settings = QSettings()
def get(name, default):
if settings.contains(name):
return variant_to_py(settings.value(name))
else:
return default
self.filter_hardness = get('FilterHardness', self.filter_hardness) self.filter_hardness = get('FilterHardness', self.filter_hardness)
self.mix_file_kind = get('MixFileKind', self.mix_file_kind) self.mix_file_kind = get('MixFileKind', self.mix_file_kind)
self.use_regexp = get('UseRegexp', self.use_regexp) self.use_regexp = get('UseRegexp', self.use_regexp)
@ -97,11 +58,7 @@ class Preferences(object):
# save prefs specific to the dg edition # save prefs specific to the dg edition
pass pass
def save(self): def _save_values(self, settings, set_):
settings = QSettings()
def set_(name, value):
settings.setValue(name, py_to_variant(value))
set_('FilterHardness', self.filter_hardness) set_('FilterHardness', self.filter_hardness)
set_('MixFileKind', self.mix_file_kind) set_('MixFileKind', self.mix_file_kind)
set_('UseRegexp', self.use_regexp) set_('UseRegexp', self.use_regexp)