X-Git-Url: http://git.tremily.us/?p=hooke.git;a=blobdiff_plain;f=hooke%2Fcurve.py;h=42fa8079d44c90533b2964a98e3166bc86eb7baf;hp=12ac5eb98a2cb1cd2339d36d6edb69c16f9e5c82;hb=f35ab8638b8cf48a793f24006933ddd8de7686c4;hpb=77b87e6d2ec85ce01ff8950bff850315c0728704 diff --git a/hooke/curve.py b/hooke/curve.py index 12ac5eb..42fa807 100644 --- a/hooke/curve.py +++ b/hooke/curve.py @@ -92,8 +92,8 @@ class Data (numpy.ndarray): >>> import yaml >>> print yaml.dump(d) - null - ... + !hooke.curve.DataInfo + columns: [distance (m), force (N)] """ def __new__(subtype, shape, dtype=numpy.float, buffer=None, offset=0, @@ -189,6 +189,8 @@ class Curve (object): >>> z = pickle.loads(s) >>> z + >>> z.command_stack + [}>] >>> z.command_stack[-1].arguments['curve'] == z True >>> print yaml.dump(c) # doctest: +REPORT_UDIFF @@ -199,9 +201,6 @@ class Curve (object): arguments: curve: *id001 command: curve info - data: null - driver: null - info: {} name: path path: some/path @@ -226,9 +225,6 @@ class Curve (object): arguments: curve: !!python/object:hooke.curve.Curve command_stack: *id001 - data: null - driver: null - info: {} name: path path: some/path command: curve info @@ -251,22 +247,35 @@ class Curve (object): if self.name == None and path != None: self.name = os.path.basename(path) + def _setup_default_attrs(self): + # .data contains: {name of data: list of data sets [{[x], [y]}] + # ._hooke contains a Hooke instance for Curve.load() + self._default_attrs = { + '_hooke': None, + 'command_stack': [], + 'data': None, + 'driver': None, + 'info': {}, + 'name': None, + 'path': None, + } + def __getstate__(self): - state = dict(self.__dict__) # make a copy of the attribute dict. + state = dict(self.__dict__) # make a copy of the attribute dict. del(state['_hooke']) return state def __setstate__(self, state): - # .data contains: {name of data: list of data sets [{[x], [y]}] - # ._hooke contains a Hooke instance for Curve.load() - self.name = self.driver = self.data = self._hooke = None - self.info = {} - self.command_stack = CommandStack() - for key,value in state.items(): - setattr(self, key, value) - if self.info == None: + self._setup_default_attrs() + self.__dict__.update(self._default_attrs) + if state == True: + return + self.__dict__.update(state) + self.set_path(getattr(self, 'path', None)) + if self.info in [None, {}]: self.info = {} - self.set_path(state.get('path', None)) + if type(self.command_stack) == list: + self.command_stack = CommandStack() def set_hooke(self, hooke=None): if hooke != None: