3 """Tutorial driver for Hooke.
5 This example driver explains driver construction.
9 Here we define a simple file format that is read by this driver. The
10 file format is as following::
45 that is, two plots with two datasets each.
48 # The following are relative imports. See PEP 328 for details
49 # http://www.python.org/dev/peps/pep-0328/
50 from .. import curve as curve # this module defines data containers.
51 from .. import experiment as experiment # this module defines expt. types
52 from ..config import Setting # configurable setting class
53 from . import Driver as Driver # this is the Driver base class
55 # The driver must inherit from the parent
56 # :class:`hooke.driver.Driver` (which we have imported as `Driver`).
57 class TutorialDriver (Driver):
58 """Handle simple text data as an example Driver.
61 """YOU MUST OVERRIDE Driver.__init__.
63 Here you set a value for `name` to identify your driver. It
64 should match the module name.
66 super(TutorialDriver, self).__init__(name='tutorial')
68 def default_settings(self):
69 """Return a list of any configurable settings for your driver.
71 If your driver does not have any configurable settings, there
72 is no need to override this method.
75 Setting(section=self.setting_section, help=self.__doc__),
76 Setting(section=self.setting_section, option='x units', value='nm',
77 help='Set the units used for the x data.'),
81 """YOU MUST OVERRIDE Driver.is_me.
83 RETURNS: Boolean (`True` or `False`)
85 This method is a heuristic that looks at the file content and
86 decides if the file can be opened by the driver itself. It
87 returns `True` if the file opened can be interpreted by the
88 current driver, `False` otherwise. Defining this method allows
89 Hooke to understand what kind of files we're looking at
93 f = open(self.filename, 'r')
94 header = f.readline() # we only need the first line
97 """Our "magic fingerprint" is the TUTORIAL_FILE header. Of
98 course, depending on the data file, you can have interesting
99 headers, or patterns, etc. that you can use to guess the data
100 format. What matters is successful recognition and the boolean
103 if header.startswith('TUTORIAL_FILE'):
107 def read(self, path):
108 f = open(path,'r') # open the file for reading
109 """In this case, we have a data format that is just a list of
110 ASCII values, so we can just divide that in rows, and generate
111 a list with each item being a row. Of course if your data
112 files are binary, or follow a different approach, do whatever
115 self.data = list(self.filedata)
116 f.close() # remember to close the file
119 info = {'filetype':'tutorial', 'experiment':'generic'}