Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/properties.py
diff options
context:
space:
mode:
authorerick <erick@sugar-dev-erick.(none)>2009-12-05 21:03:59 (GMT)
committer erick <erick@sugar-dev-erick.(none)>2009-12-05 21:03:59 (GMT)
commitc14688d67a82b7ec7746beda90da915c98600a3d (patch)
tree1b5fb911f16826290bb4fbebc29e3dd1308626de /tutorius/properties.py
parent3a1303ab5fa37d2a9881682af29fa4e177ea67ec (diff)
parent0e6a6e03c520b86ee36d79d4cd0daf06f84632a3 (diff)
Merge branch 'frame_integration' into revamped_dragndrop
Conflicts: tutorius/actions.py
Diffstat (limited to 'tutorius/properties.py')
-rw-r--r--tutorius/properties.py47
1 files changed, 34 insertions, 13 deletions
diff --git a/tutorius/properties.py b/tutorius/properties.py
index a462782..07b1645 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)
@@ -123,26 +138,32 @@ class TPropContainer(object):
"""
Return a deep copy of the dictionary of properties from that object.
"""
- return deepcopy(self._props)
+ 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
+ """
+ Deprecated.
+
+ Property containers should not be used as keys inside dictionary for
+ the time being. Since containers are mutable, we should definitely
+ use the addressing mechanism to refer to the containers.
+ """
+ # Many places we use containers as keys to store additional data.
+ # Since containers are mutable, there is a need for a hash function
+ # where the result is constant, so we can still lookup old instances.
+ return self.__id
# Adding methods for pickling and unpickling an object with
# properties
def __getstate__(self):
- return self._props.copy()
+ return dict(id=self.__id, props=self._props.copy())
def __setstate__(self, dict):
- self._props.update(dict)
+ self.__id = dict['id']
+ self._props.update(dict['props'])
+
+ def __eq__(self, e2):
+ return (isinstance(e2, type(self)) and self._props == e2._props)
class TutoriusProperty(object):
"""