SF.net SVN: fclient:[804] trunk/fclient/src/fclient/impl/lib/qt4ex/ dlgpreferences.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-28 19:25:39
|
Revision: 804
http://fclient.svn.sourceforge.net/fclient/?rev=804&view=rev
Author: jUrner
Date: 2008-07-28 19:25:47 +0000 (Mon, 28 Jul 2008)
Log Message:
-----------
comb over ..apply button is now global
Modified Paths:
--------------
trunk/fclient/src/fclient/impl/lib/qt4ex/dlgpreferences.py
Modified: trunk/fclient/src/fclient/impl/lib/qt4ex/dlgpreferences.py
===================================================================
--- trunk/fclient/src/fclient/impl/lib/qt4ex/dlgpreferences.py 2008-07-28 19:25:01 UTC (rev 803)
+++ trunk/fclient/src/fclient/impl/lib/qt4ex/dlgpreferences.py 2008-07-28 19:25:47 UTC (rev 804)
@@ -9,16 +9,15 @@
# page.initialize()
# page.setVisible(flag)
#
-# x. apply and resoreDefaults behaviour is not well designed
-# apply: aply changes on all pages. isDirty is for all pages
-# restoreDfaults: restore defaults of the current page
-# x. should restoreDefaults be disabled when already restored?
+# x. appply button is global for all pages. if one page is dorty, apply is enabled for all pages
+# maybe add a notification to allow for feedback?
# x. docs are outdated
-# x. UUID is probably not a good idea. use objectName() instead
+# x. UUID is maybe not a good idea. maybe use objectName() instead
+# x. maybe call close on all pages to allow for cleanup
+# x. maybe weakref this thingy
+# x. user hits apply then hits cancel. can't tell from the top of my head ...should we undo changes?
#
#*******************************************************************************
-
-
"""Preferences dialog"""
from __future__ import absolute_import
if __name__ == '__main__': # see --> http://bugs.python.org/issue1510172 . works only current dir and below
@@ -270,6 +269,7 @@
self.lastSelectedPage = None
self.pageContainer = pageContainer
self.pages = pages
+ self.dirtyPages = []
# buttons handld by the controler
self.buttonBoxButtons = {
@@ -281,12 +281,10 @@
}
# page depandend buttons of the button box
self.buttonBoxOptionalButtons = (
- QtGui.QDialogButtonBox.Apply,
QtGui.QDialogButtonBox.Help,
QtGui.QDialogButtonBox.RestoreDefaults,
)
-
# dump sections and pages to tree
if pages is not None:
@@ -318,14 +316,23 @@
self.onStandardButtonClicked
)
self.adjustStandardButtons(None)
+ buttonApply = self.buttonBox.button(QtGui.QDialogButtonBox.Apply)
+ buttonApply.setEnabled(False)
+
################################################
## slots
################################################
- def onPageDirtyChanged(self, flag):
+ def onPageDirtyChanged(self, isDirty):
+ page = self.sender()
+ if page in self.dirtyPages:
+ if not isDirty:
+ self.dirtyPages.remove(page)
+ else:
+ if isDirty:
+ self.dirtyPages.append(page)
bt = self.buttonBox.button(QtGui.QDialogButtonBox.Apply)
- if bt.isVisible():
- bt.setEnabled(flag)
+ bt.setEnabled(bool(self.dirtyPages))
def onStandardButtonClicked(self, button):
@@ -337,21 +344,26 @@
standardButtonName = self.buttonBoxButtons.get(standardButton, None)
if standardButtonName == 'Ok': # handled on DlgPreferences.accept()
return
- if standardButtonName is not None:
+ elif standardButtonName == 'Apply':
+ for page in self.pages.walk():
+ if page.isDirty():
+ methodName = self.PrefixCapabilityApply + standardButtonName
+ method = getattr(page, methodName, None)
+ if method is None:
+ raise valueError('Pages must provide a "%s" method' % methodName)
+ if method():
+ page.setDirty(False)
+ elif standardButtonName is not None:
methodName = self.PrefixCapabilityApply + standardButtonName
method = getattr(page, methodName, None)
if method is None:
raise valueError('Pages must provide a "%s" method' % methodName)
- if method():
- if standardButton == QtGui.QDialogButtonBox.Apply:
- page.setDirty(False)
-
-
+ method()
+
##################################################
## methods
##################################################
def adjustStandardButtons(self, page):
-
for standardButton in self.buttonBoxOptionalButtons:
bt = self.buttonBox.button(standardButton)
if bt is None:
@@ -370,14 +382,7 @@
bt.setEnabled(flag)
bt.setVisible(flag)
- # enable Apply button if necessary
- if flag and standardButton == QtGui.QDialogButtonBox.Apply:
- method = getattr(page, self.MethodNameIsDirty, None)
- if method is None:
- raise valueError('Pages must prvide a "%s" method' % self.MethodNameIsDirty)
- bt.setEnabled(method())
-
-
+
def close(self):
"""Close the controler
@note: make shure to call this method on exit to apply outstanding changes
@@ -389,6 +394,7 @@
if method is None:
raise ValueError('Pages must provide a "%s" method' % self.MethodNameApply)
method()
+ del self.dirtyPages[:]
def currentPage(self):
@@ -668,13 +674,11 @@
state = cPickle.loads(state)
assert isinstance(state, dict)
except Exception, d:
- print Exception, d
return False
else:
try:
self.restoreGeometry(state.get('geometry', None))
except Exception, d:
- print 2
return False
try:
self.controlById(self.IdSplitter).restoreState(state.get('splitter', None))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|