示例#1
0
    def save(self, path):
        """
        Saves state to a file.  Overrides the base method.

        Hides internal observable attributes when serializing.

        """
        attributes = self.remove_unserializable_attributes()
        Model.save(self, path)
        self.restore_unserializable_attributes(attributes)
示例#2
0
 def instance(path):
     """Override Model.instance() to account for unserializable data."""
     obj = Model.instance(path)
     if isinstance(obj, ObservableModel):
         # This ensures that clones always start out with no observers,
         # but retain the hidden _unserializable_attributes.
         unserializable_copy = copy.deepcopy(_unserializable_attributes)
         obj.restore_unserializable_attributes(unserializable_copy)
     return obj
示例#3
0
 def clone(self):
     """Override Model.clone() to handle observers"""
     # Go in and out of jsonpickle to create a clone
     attributes = self.remove_unserializable_attributes()
     clone = Model.clone(self)
     unserializable_copy = copy.deepcopy(_unserializable_attributes)
     self.restore_unserializable_attributes(attributes)
     clone.restore_unserializable_attributes(unserializable_copy)
     return clone
示例#4
0
 def set_param(self, param, value, notify=True):
     """Override Model.set_param() to handle notification"""
     Model.set_param(self, param, value)
     # Perform notifications
     if notify:
         self.notify_observers(param)
示例#5
0
 def __init__(self):
     Model.__init__(self)
     Observable.__init__(self)