SF.net SVN: fclient:[803] trunk/fclient/src/fclient/impl/lib/qt4ex/lib/ settings.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-28 19:24:52
|
Revision: 803
http://fclient.svn.sourceforge.net/fclient/?rev=803&view=rev
Author: jUrner
Date: 2008-07-28 19:25:01 +0000 (Mon, 28 Jul 2008)
Log Message:
-----------
allow adding checkboxes to settings controller
Modified Paths:
--------------
trunk/fclient/src/fclient/impl/lib/qt4ex/lib/settings.py
Modified: trunk/fclient/src/fclient/impl/lib/qt4ex/lib/settings.py
===================================================================
--- trunk/fclient/src/fclient/impl/lib/qt4ex/lib/settings.py 2008-07-28 12:28:30 UTC (rev 802)
+++ trunk/fclient/src/fclient/impl/lib/qt4ex/lib/settings.py 2008-07-28 19:25:01 UTC (rev 803)
@@ -395,6 +395,10 @@
#**********************************************************************************
#
#**********************************************************************************
+#TODO:
+#
+# x. maybe weakref this thingy
+#***********************************************************************************
class SettingsControler(QtCore.QObject):
"""associates widgets to settings and automatically adjusts settings according to widget signals
@@ -424,6 +428,12 @@
#########################
## methods
#########################
+ def addCheckBox(self, checkBox, settingName):
+ """adds a (two state for a boolean setting) checkbox to the controler"""
+ self.objects[checkBox] = settingName
+ checkBox.setCheckState(QtCore.Qt.Checked if self.settings.value(settingName) else QtCore.Qt.Unchecked)
+ self.connect(checkBox, QtCore.SIGNAL('stateChanged(int)'), self.onCheckBoxStateChanged)
+
def addLineEdit(self, lineEdit, settingName):
"""adds a QLineEdit as controler for the specified setting"""
self.objects[lineEdit] = settingName
@@ -444,6 +454,9 @@
value = obj.text()
elif isinstance(obj, QtGui.QSpinBox):
value = obj.value()
+ elif isinstance(obj, QtGui.QCheckBox):
+ value = obj.checkState() == QtCore.Qt.Checked
+
settings[settingName] = value
del self.dirtyObjects[:]
@@ -451,6 +464,11 @@
self.emit(QtCore.SIGNAL('isDirty(bool)'), False)
return True
+ def close(self):
+ """closes the controller and clears all references"""
+ del self.dirtyObjects[:]
+ self.objects = {}
+
def restoreDefaults(self):
"""resores the default settings and updates the values of the controlled widgets accordingly"""
for obj, settingName in self.objects.items():
@@ -459,6 +477,8 @@
obj.setText(value)
elif isinstance(obj, QtGui.QSpinBox):
obj.setValue(value)
+ elif isinstance(obj, QtGui.QCheckBox):
+ obj.setCheckState(QtCore.Qt.Checked if value else QtCore.Qt.Unchecked)
del self.dirtyObjects[:]
self.emit(QtCore.SIGNAL('isDirty(bool)'), False)
@@ -467,6 +487,17 @@
#########################
## event handlers
#########################
+ def onCheckBoxStateChanged(self, state):
+ checkBox = self.sender()
+ settingName = self.objects[checkBox]
+ if (checkBox.checkState() == QtCore.Qt.Checked) == self.settings.value(settingName):
+ if checkBox in self.dirtyObjects:
+ self.dirtyObjects.remove(checkBox)
+ else:
+ if checkBox not in self.dirtyObjects:
+ self.dirtyObjects.append(checkBox)
+ self.emit(QtCore.SIGNAL('isDirty(bool)'), bool(self.dirtyObjects))
+
def onLineEditTextChanged(self, text):
lineEdit = self.sender()
settingName = self.objects[lineEdit]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|