|
|
@@ -1236,39 +1236,7 @@ class ParamObj:
|
|
|
self._curParamStack = []
|
|
|
self._priorValuesStack = []
|
|
|
|
|
|
- def setterStub(param, setterFunc, self,
|
|
|
- value):
|
|
|
- # should we apply the value now or should we wait?
|
|
|
- # if this obj's params are locked, we track which values have
|
|
|
- # been set, and on unlock, we'll call the applyers for those
|
|
|
- # values
|
|
|
- if self._paramLockRefCount > 0:
|
|
|
- priorValues = self._priorValuesStack[-1]
|
|
|
- if param not in priorValues:
|
|
|
- try:
|
|
|
- priorValue = getSetter(self, param, 'get')()
|
|
|
- except:
|
|
|
- priorValue = None
|
|
|
- priorValues[param] = priorValue
|
|
|
- self._paramsSet[param] = None
|
|
|
- setterFunc(value)
|
|
|
- else:
|
|
|
- # prepare for call to getPriorValue
|
|
|
- self._priorValuesStack.append({
|
|
|
- param: getSetter(self, param, 'get')()
|
|
|
- })
|
|
|
- setterFunc(value)
|
|
|
- # call the applier, if there is one
|
|
|
- applier = getattr(self, getSetterName(param, 'apply'), None)
|
|
|
- if applier is not None:
|
|
|
- self._curParamStack.append(param)
|
|
|
- applier()
|
|
|
- self._curParamStack.pop()
|
|
|
- self._priorValuesStack.pop()
|
|
|
- if hasattr(self, 'handleParamChange'):
|
|
|
- self.handleParamChange((param,))
|
|
|
-
|
|
|
- # insert stub funcs for param setters
|
|
|
+ # insert stub funcs for param setters, to handle locked params
|
|
|
for param in self.ParamSet.getParams():
|
|
|
setterName = getSetterName(param)
|
|
|
getterName = getSetterName(param, 'get')
|
|
|
@@ -1277,6 +1245,7 @@ class ParamObj:
|
|
|
if not hasattr(self, setterName):
|
|
|
# no; provide the default
|
|
|
def defaultSetter(self, value, param=param):
|
|
|
+ #print '%s=%s for %s' % (param, value, id(self))
|
|
|
setattr(self, param, value)
|
|
|
self.__class__.__dict__[setterName] = defaultSetter
|
|
|
|
|
|
@@ -1289,27 +1258,74 @@ class ParamObj:
|
|
|
return getattr(self, param, default)
|
|
|
self.__class__.__dict__[getterName] = defaultGetter
|
|
|
|
|
|
- # grab a reference to the setter
|
|
|
- setterFunc = getattr(self, setterName)
|
|
|
- # if the setter is a direct member of this instance, move the setter
|
|
|
- # aside
|
|
|
- if setterName in self.__dict__:
|
|
|
- self.__dict__[setterName + '_MOVED'] = self.__dict__[setterName]
|
|
|
- setterFunc = self.__dict__[setterName]
|
|
|
- # install a setter stub that will a) call the real setter and
|
|
|
- # then the applier, or b) call the setter and queue the
|
|
|
- # applier, depending on whether our params are locked
|
|
|
- setattr(self, setterName, new.instancemethod(
|
|
|
- Functor(setterStub, param, setterFunc), self, self.__class__))
|
|
|
+ # have we already installed a setter stub?
|
|
|
+ origSetterName = '%s_ORIG' % (setterName,)
|
|
|
+ if not hasattr(self, origSetterName):
|
|
|
+ # move the original setter aside
|
|
|
+ origSetterFunc = getattr(self.__class__, setterName)
|
|
|
+ setattr(self.__class__, origSetterName, origSetterFunc)
|
|
|
+ """
|
|
|
+ # if the setter is a direct member of this instance, move the setter
|
|
|
+ # aside
|
|
|
+ if setterName in self.__dict__:
|
|
|
+ self.__dict__[setterName + '_MOVED'] = self.__dict__[setterName]
|
|
|
+ setterFunc = self.__dict__[setterName]
|
|
|
+ """
|
|
|
+ # install a setter stub that will a) call the real setter and
|
|
|
+ # then the applier, or b) call the setter and queue the
|
|
|
+ # applier, depending on whether our params are locked
|
|
|
+ """
|
|
|
+ setattr(self, setterName, new.instancemethod(
|
|
|
+ Functor(setterStub, param, setterFunc), self, self.__class__))
|
|
|
+ """
|
|
|
+ def setterStub(self, value, param=param, origSetterName=origSetterName):
|
|
|
+ # should we apply the value now or should we wait?
|
|
|
+ # if this obj's params are locked, we track which values have
|
|
|
+ # been set, and on unlock, we'll call the applyers for those
|
|
|
+ # values
|
|
|
+ if self._paramLockRefCount > 0:
|
|
|
+ priorValues = self._priorValuesStack[-1]
|
|
|
+ if param not in priorValues:
|
|
|
+ try:
|
|
|
+ priorValue = getSetter(self, param, 'get')()
|
|
|
+ except:
|
|
|
+ priorValue = None
|
|
|
+ priorValues[param] = priorValue
|
|
|
+ self._paramsSet[param] = None
|
|
|
+ getattr(self, origSetterName)(value)
|
|
|
+ else:
|
|
|
+ # prepare for call to getPriorValue
|
|
|
+ try:
|
|
|
+ priorValue = getSetter(self, param, 'get')()
|
|
|
+ except:
|
|
|
+ priorValue = None
|
|
|
+ self._priorValuesStack.append({
|
|
|
+ param: priorValue,
|
|
|
+ })
|
|
|
+ getattr(self, origSetterName)(value)
|
|
|
+ # call the applier, if there is one
|
|
|
+ applier = getattr(self, getSetterName(param, 'apply'), None)
|
|
|
+ if applier is not None:
|
|
|
+ self._curParamStack.append(param)
|
|
|
+ applier()
|
|
|
+ self._curParamStack.pop()
|
|
|
+ self._priorValuesStack.pop()
|
|
|
+ if hasattr(self, 'handleParamChange'):
|
|
|
+ self.handleParamChange((param,))
|
|
|
+
|
|
|
+ setattr(self.__class__, setterName, setterStub)
|
|
|
|
|
|
if params is not None:
|
|
|
params.applyTo(self)
|
|
|
|
|
|
def destroy(self):
|
|
|
+ """
|
|
|
for param in self.ParamSet.getParams():
|
|
|
setterName = getSetterName(param)
|
|
|
self.__dict__[setterName].destroy()
|
|
|
del self.__dict__[setterName]
|
|
|
+ """
|
|
|
+ pass
|
|
|
|
|
|
def setDefaultParams(self):
|
|
|
# set all the default parameters on ourself
|
|
|
@@ -1357,8 +1373,11 @@ class ParamObj:
|
|
|
def __repr__(self):
|
|
|
argStr = ''
|
|
|
for param in self.ParamSet.getParams():
|
|
|
- argStr += '%s=%s,' % (param,
|
|
|
- repr(getSetter(self, param, 'get')()))
|
|
|
+ try:
|
|
|
+ value = getSetter(self, param, 'get')()
|
|
|
+ except:
|
|
|
+ value = '<unknown>'
|
|
|
+ argStr += '%s=%s,' % (param, repr(value))
|
|
|
return '%s(%s)' % (self.__class__.__name__, argStr)
|
|
|
|
|
|
if __debug__:
|
|
|
@@ -1492,19 +1511,19 @@ class POD:
|
|
|
def getValue(self, name):
|
|
|
return getSetter(self, name, 'get')()
|
|
|
|
|
|
- # CLASS METHODS
|
|
|
+ @classmethod
|
|
|
def getDataNames(cls):
|
|
|
# returns safely-mutable list of datum names
|
|
|
cls._compileDefaultDataSet()
|
|
|
return cls._DataSet.keys()
|
|
|
- getDataNames = classmethod(getDataNames)
|
|
|
+ @classmethod
|
|
|
def getDefaultValue(cls, name):
|
|
|
cls._compileDefaultDataSet()
|
|
|
dv = cls._DataSet[name]
|
|
|
if callable(dv):
|
|
|
dv = dv()
|
|
|
return dv
|
|
|
- getDefaultValue = classmethod(getDefaultValue)
|
|
|
+ @classmethod
|
|
|
def _compileDefaultDataSet(cls):
|
|
|
if cls.__dict__.has_key('_DataSet'):
|
|
|
# we've already compiled the defaults for this class
|
|
|
@@ -1537,8 +1556,6 @@ class POD:
|
|
|
if c.__dict__.has_key('DataSet'):
|
|
|
# apply this class' default data values to our dict
|
|
|
cls._DataSet.update(c.DataSet)
|
|
|
- _compileDefaultDataSet = classmethod(_compileDefaultDataSet)
|
|
|
- # END CLASS METHODS
|
|
|
|
|
|
def __repr__(self):
|
|
|
argStr = ''
|