Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/properties.py
diff options
context:
space:
mode:
Diffstat (limited to 'tutorius/properties.py')
-rw-r--r--tutorius/properties.py85
1 files changed, 36 insertions, 49 deletions
diff --git a/tutorius/properties.py b/tutorius/properties.py
index 6d30a8d..78e3c2b 100644
--- a/tutorius/properties.py
+++ b/tutorius/properties.py
@@ -95,39 +95,25 @@ class TPropContainer(object):
"""
return object.__getattribute__(self, "_props").keys()
- def is_identical(self, otherContainer):
- for prop in self._props.keys():
- found = False
- for otherProp in otherContainer._props.keys():
- if prop == otherProp:
- this_type = getattr(type(self), prop).type
- other_type = getattr(type(otherContainer), prop).type
- if this_type != other_type:
- return False
- if this_type == "addonlist":
- for inner_cont in self._props[prop]:
- inner_found = False
- for other_inner in otherContainer._props[prop]:
- if inner_cont.is_identical(other_inner):
- inner_found = True
- break
- if inner_found == False:
- return False
- found = True
- break
- elif this_type == "addon":
- if not self._props[prop].is_identical(otherContainer._props[prop]):
- return False
- found = True
- break
- else:
- if self._props[prop]== otherContainer._props[prop]:
- found = True
- break
- if found == False:
- return False
- return True
-
+ # 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 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)
+
class TutoriusProperty(object):
"""
The base class for all actions' properties. The interface is the following :
@@ -178,19 +164,6 @@ class TAddonListProperty(TutoriusProperty):
"""
pass
-
- def get_constraints(self):
- """
- Returns the list of constraints associated to this property.
- """
- if self._constraints is None:
- self._constraints = []
- for i in dir(self):
- typ = getattr(self, i)
- if isinstance(typ, Constraint):
- self._constraints.append(i)
- return self._constraints
-
class TIntProperty(TutoriusProperty):
"""
Represents an integer. Can have an upper value limit and/or a lower value
@@ -240,8 +213,20 @@ class TArrayProperty(TutoriusProperty):
self.type = "array"
self.max_size_limit = MaxSizeConstraint(max_size_limit)
self.min_size_limit = MinSizeConstraint(min_size_limit)
- self.default = self.validate(value)
+ self.default = tuple(self.validate(value))
+ #Make this thing hashable
+ def __setstate__(self, state):
+ self.max_size_limit = MaxSizeConstraint(state["max_size_limit"])
+ self.min_size_limit = MinSizeConstraint(state["min_size_limit"])
+ self.value = state["value"]
+
+ def __getstate__(self):
+ return dict(
+ max_size_limit=self.max_size_limit.limit,
+ min_size_limit=self.min_size_limit.limit,
+ value=self.value,
+ )
class TColorProperty(TutoriusProperty):
"""
Represents a RGB color with 3 8-bit integer values.
@@ -320,8 +305,10 @@ class TUAMProperty(TutoriusProperty):
"""
Represents a widget of the interface by storing its UAM.
"""
- # TODO : Pending UAM check-in (LP 355199)
- pass
+ def __init__(self, value=None):
+ TutoriusProperty.__init__(self)
+
+ self.type = "uam"
class TAddonProperty(TutoriusProperty):
"""