def __init__(self, name, obj, getter=None, setter=None, attr=None): """Wrap an object as a Parameter. name -- The name of this Parameter. obj -- The object to be wrapped. getter -- The unbound function that can be used to access the attribute containing the parameter value. getter(obj) should return the Parameter value. If getter is None (default), it is assumed that an attribute is accessed via attr. If attr is also specified, then the Parameter value will be accessed via getter(obj, attr). setter -- The unbound function that can be used to modify the attribute containing the parameter value. setter(obj, value) should set the attribute to the passed value. If setter is None (default), it is assumed that an attribute is accessed via attr. If attr is also specified, then the Parameter value will be set via setter(obj, attr, value). attr -- The name of the attribute that contains the value of the parameter. If attr is None (default), then both getter and setter must be specified. Raises ValueError if exactly one of getter or setter is not None, or if getter, setter and attr are all None. """ if getter is None and setter is None and attr is None: raise ValueError("Specify attribute access") if [getter, setter].count(None) == 1: raise ValueError("Specify both getter and setter") self.obj = obj self.getter = getter self.setter = setter self.attr = attr if attr is not None: if getter is None: self.getter = bind2nd(getattr, self.attr) else: self.getter = bind2nd(getter, self.attr) if setter is None: self.setter = bind2nd(setattr, self.attr) else: self.setter = bind2nd(setter, self.attr) value = self.getValue() Parameter.__init__(self, name, value) return
def __init__(self, name, obj, getter = None, setter = None, attr = None): """Wrap an object as a Parameter. name -- The name of this Parameter. obj -- The object to be wrapped. getter -- The unbound function that can be used to access the attribute containing the parameter value. getter(obj) should return the Parameter value. If getter is None (default), it is assumed that an attribute is accessed via attr. If attr is also specified, then the Parameter value will be accessed via getter(obj, attr). setter -- The unbound function that can be used to modify the attribute containing the parameter value. setter(obj, value) should set the attribute to the passed value. If setter is None (default), it is assumed that an attribute is accessed via attr. If attr is also specified, then the Parameter value will be set via setter(obj, attr, value). attr -- The name of the attribute that contains the value of the parameter. If attr is None (default), then both getter and setter must be specified. Raises ValueError if exactly one of getter or setter is not None, or if getter, setter and attr are all None. """ if getter is None and setter is None and attr is None: raise ValueError("Specify attribute access") if [getter, setter].count(None) == 1: raise ValueError("Specify both getter and setter") self.obj = obj self.getter = getter self.setter = setter self.attr = attr if attr is not None: if getter is None: self.getter = bind2nd(getattr, self.attr) else: self.getter = bind2nd(getter, self.attr) if setter is None: self.setter = bind2nd(setattr, self.attr) else: self.setter = bind2nd(setter, self.attr) value = self.getValue() Parameter.__init__(self, name, value) return
def _latsetter(par): return bind2nd(setattr, par)
def _latgetter(par): return bind2nd(getattr, par)
def _latsetter(par): return bind2nd(setattr, par)
def _latgetter(par): return bind2nd(getattr, par)