SF.net SVN: fclient: [576] trunk/fclient/src/fclient/lib/qt4ex/settingsbase .py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-11 16:33:46
|
Revision: 576
http://fclient.svn.sourceforge.net/fclient/?rev=576&view=rev
Author: jUrner
Date: 2008-07-11 09:33:56 -0700 (Fri, 11 Jul 2008)
Log Message:
-----------
deprecate settingsbase
Modified Paths:
--------------
trunk/fclient/src/fclient/lib/qt4ex/settingsbase.py
Modified: trunk/fclient/src/fclient/lib/qt4ex/settingsbase.py
===================================================================
--- trunk/fclient/src/fclient/lib/qt4ex/settingsbase.py 2008-07-11 16:33:36 UTC (rev 575)
+++ trunk/fclient/src/fclient/lib/qt4ex/settingsbase.py 2008-07-11 16:33:56 UTC (rev 576)
@@ -1,7 +1,10 @@
"""Base class for settings to take awasy a bit of the hassle of working with QSettings
"""
-
+import warnings
+warnings.warn('deprecated module. use <settings> instead', DeprecationWarning)
+
+
from PyQt4 import QtCore, QtGui
__version__ = '0.0.2'
@@ -22,25 +25,24 @@
('MySettingsName2', ['ConvertValue', None])
)
- with the first member being the name of the setting, and the secon member
+ with the first member being the name of the setting, and the second member
being a list[type, default-value]. The type is used to convert the settings value
- to a desired type. It can be either a QVariant method (in wich case the type
- conversion is handled automatically) or a user supplied method name to
- call to do the type conversion.
+ to a desired type. It can be either a QVariant method (the type conversion is handled
+ automatically) or a user supplied method name to call to do the type conversion.
If it is a user supplied method name, a method "toMethodName" will be called
upon reading settings to convert a QVariant into the desired type and return its value,
- and a method "fromMethodName" will be called to convert the value of the setting into
+ and a method "fromMethodName" will be called to convert the value of the setting into
something that can be fed to a QVariant to store as setting while dumping settings.
- Note that the "from" method may return None. In this case the return value is ignored,
- else the return value will be stored in the instances settings.
+ Note that the "from" method may return None. In this case the return value is ignored.
+ any other return value will be stored in the instances settings.
- Also note that the variant passed to the "to" method be None, so ckeck for it.
+ Also note that the variant passed to the "to" method may be None, so ckeck for it.
The order in wich settings appear is always preserved.
- Type can be None aswell, in wich case the setting will never get read or dumped to disk
+ Type can be None aswell. if so, the setting will never get read or dumped to or read from disk
Sample:
@@ -105,7 +107,7 @@
def __setitem__(self, settingsName, value):
- """Sets the value of a setting"""
+ """Sets the value of a setting and marks it as dirty if the value has changed"""
if value != self.settingsDict[settingsName][1]:
self.setDirty(settingsName, True)
self.settingsDict[settingsName][1] = value
@@ -132,6 +134,34 @@
settings.endGroup()
+ def dumpNow(self, parent, settings, **values):
+ """Sets and emidiately dumps settings to the specified settings object
+ @arg parent: parent window
+ @arg settings: QSettings
+ @arg values: settingsName --> value pairs to dump
+ """
+ settings.beginGroup(self.KEY_SETTINGS)
+
+ for name, value in values.items():
+ settingsType, value, isDirty = self.settingsDict[name]
+ if settingsType is None:
+ continue
+
+ if not hasattr(QtCore.QVariant, settingsType):
+ value = getattr(self, 'from' + settingsType)(parent, settings, name, value)
+ if value == None:
+ continue
+
+
+
+ settings.setValue(name, QtCore.QVariant(value) )
+
+ settings.endGroup()
+
+
+
+
+
def isDirty(self, settingsName):
"""Checks if a setting is dirty"""
return self.settingsDict[settingsName][2]
@@ -189,7 +219,12 @@
def setDirty(self, settingsName, flag):
- """Marks a setting as dirty"""
+ """Marks a setting as dirty
+ @param settingsName: name of the setting to mark
+ @flag: (bool)
+
+ @note: use this flag for whatever purpose you want
+ """
self.settingsDict[settingsName][2] = flag
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|