Transition from v0.1 XML playlists to v0.2 YAML playlists.
[hooke.git] / hooke / curve.py
index ed76c8a557d08566d6495c2a7e86854f473970cc..629e0a8bd5da99ef95e37e150aa6724fe1b28f8c 100644 (file)
@@ -41,6 +41,7 @@ class NotRecognized (ValueError):
             super(NotRecognized, self).__init__(msg)
             self.curve = data
 
+
 class Data (numpy.ndarray):
     """Stores a single, continuous data set.
 
@@ -164,13 +165,13 @@ class Curve (object):
     """
     def __init__(self, path, info=None):
         #the data dictionary contains: {name of data: list of data sets [{[x], [y]}]
-        self.path = path
+        self.name = None
+        self.set_path(path)
         self.driver = None
         self.data = None
         if info == None:
             info = {}
         self.info = info
-        self.name = os.path.basename(path)
         self.command_stack = CommandStack()
         self._hooke = None  # Hooke instance for Curve.load()
 
@@ -183,6 +184,31 @@ class Curve (object):
     def __repr__(self):
         return self.__str__()
 
+    def set_path(self, path):
+        self.path = path
+        if self.name == None and path != None:
+            self.name = os.path.basename(path)
+
+    def __getstate__(self):
+        state = dict(self.__dict__)
+        del(state['_hooke'])
+        dc = state['command_stack']
+        if hasattr(dc, '__getstate__'):
+            state['command_stack'] = dc.__getstate__()
+        return state
+
+    def __setstate__(self, state):
+        self.name = self._hooke = None
+        for key,value in state.items():
+            if key == 'path':
+                self.set_path(value)
+                continue
+            elif key == 'command_stack':
+                v = CommandStack()
+                v.__setstate__(value)
+                value = v
+            setattr(self, key, value)
+
     def set_hooke(self, hooke=None):
         if hooke != None:
             self._hooke = hooke