diff options
Diffstat (limited to 'tutorius/properties.py')
-rw-r--r-- | tutorius/properties.py | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/tutorius/properties.py b/tutorius/properties.py index a462782..f273569 100644 --- a/tutorius/properties.py +++ b/tutorius/properties.py @@ -19,6 +19,7 @@ TutoriusProperties have the same behaviour as python properties (assuming you also use the TPropContainer), with the added benefit of having builtin dialog prompts and constraint validation. """ +import uuid from copy import copy, deepcopy from .constraints import Constraint, \ @@ -35,6 +36,9 @@ from .propwidgets import PropWidget, \ FloatPropWidget, \ IntArrayPropWidget +import logging +LOGGER = logging.getLogger("properties") + class TPropContainer(object): """ A class containing properties. This does the attribute wrapping between @@ -60,6 +64,14 @@ class TPropContainer(object): self._props[attr_name] = propinstance.validate( copy(propinstance.default)) + self.__id = hash(uuid.uuid4()) + # The differences dictionary. This is a structure that holds all the + # modifications that were made to the properties since the action + # was last installed or the last moment the notification was executed. + # Every property change will be logged inside it and it will be sent + # to the creator to update its action edition dialog. + self._diff_dict = {} + def __getattribute__(self, name): """ Process the 'fake' read of properties in the appropriate instance @@ -93,8 +105,11 @@ class TPropContainer(object): try: # We attempt to get the property object with __getattribute__ # to work through inheritance and benefit of the MRO. - return props.__setitem__(name, + real_value = props.__setitem__(name, object.__getattribute__(self, name).validate(value)) + LOGGER.debug("Action :: caching %s = %s in diff dict"%(name, str(value))) + self._diff_dict[name] = value + return real_value except AttributeError: return object.__setattr__(self, name, value) @@ -125,24 +140,8 @@ class TPropContainer(object): """ return deepcopy(self._props) - # Providing the hash methods necessary to use TPropContainers - # in a dictionary, according to their properties - def __hash__(self): - #Return a hash of properties (key, value) sorted by key - #We need to transform the list of property key, value lists into - # a tuple of key, value tuples - return hash(tuple(map(tuple,sorted(self._props.items(), cmp=lambda x, y: cmp(x[0], y[0]))))) - def __eq__(self, e2): - return isinstance(e2, type(self)) and self._props == e2._props - - # Adding methods for pickling and unpickling an object with - # properties - def __getstate__(self): - return self._props.copy() - - def __setstate__(self, dict): - self._props.update(dict) + return (isinstance(e2, type(self)) and self._props == e2._props) class TutoriusProperty(object): """ |