X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=hooke%2Fcurve.py;h=ed76c8a557d08566d6495c2a7e86854f473970cc;hb=88a7796aa570a5667556755bcc0b0b76e2ae863d;hp=552eda6abe5582c2bf3b47f1926a8899f3829e77;hpb=8e89eecbde44ef0be854d898455e8543a30204b7;p=hooke.git diff --git a/hooke/curve.py b/hooke/curve.py index 552eda6..ed76c8a 100644 --- a/hooke/curve.py +++ b/hooke/curve.py @@ -20,7 +20,9 @@ storing force curves. """ +import logging import os.path + import numpy from .command_stack import CommandStack @@ -170,6 +172,20 @@ class Curve (object): self.info = info self.name = os.path.basename(path) self.command_stack = CommandStack() + self._hooke = None # Hooke instance for Curve.load() + + def __str__(self): + return str(self.__unicode__()) + + def __unicode__(self): + return u'<%s %s>' % (self.__class__.__name__, self.name) + + def __repr__(self): + return self.__str__() + + def set_hooke(self, hooke=None): + if hooke != None: + self._hooke = hooke def identify(self, drivers): """Identify the appropriate :class:`hooke.driver.Driver` for @@ -188,20 +204,30 @@ class Curve (object): return raise NotRecognized(self) - def load(self, *args, **kwargs): + def load(self, hooke=None): """Use the driver to read the curve into memory. Also runs any commands in :attr:`command_stack`. All arguments are passed through to :meth:`hooke.command_stack.CommandStack.execute`. """ + self.set_hooke(hooke) + log = logging.getLogger('hooke') + log.debug('loading curve %s with driver %s' % (self.name, self.driver)) data,info = self.driver.read(self.path, self.info) self.data = data for key,value in info.items(): self.info[key] = value - self.command_stack.execute(*args, **kwargs) + if self._hooke != None: + self.command_stack.execute(self._hooke) + elif len(self.command_stack) > 0: + log.warn( + 'could not execute command stack for %s without Hooke instance' + % self.name) def unload(self): """Release memory intensive :attr:`.data`. """ + log = logging.getLogger('hooke') + log.debug('unloading curve %s' % self.name) self.data = None