Fix relative import syntax.
[calibcant.git] / calibcant / common.py
1 # calibcant - tools for thermally calibrating AFM cantilevers
2 #
3 # Copyright (C) 2008-2010 W. Trevor King <wking@drexel.edu>
4 #
5 # This file is part of CalibCant.
6 #
7 # CalibCant is free software: you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation, either
10 # version 3 of the License, or (at your option) any later version.
11 #
12 # CalibCant is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with CalibCant.  If not, see
19 # <http://www.gnu.org/licenses/>.
20
21 from . import VERSION
22 from . import config
23
24
25 # handle extra verbose input modules, only imported if we need them
26 _flush_plot = None
27 _final_flush_plot = None
28 _pylab = None
29 def _dummy_fn(): pass
30
31 def _import_pylab() :  # TODO: auto detect no DISPLAY and abort
32     """Import pylab plotting functions for when we need to plot.  This
33     function can be called multiple times, and ensures that the pylab
34     setup is only imported once.  It defines the functions
35       _flush_plot() to be called after incremental changes,
36       _final_flush_plot(), to be called at the end of any graphical processing, and
37       _pylab, a reference to the pylab module."""
38     global _pylab
39     global _flush_plot
40     global _final_flush_plot
41     if _pylab == None :
42         import pylab as _pylab
43     if _flush_plot == None :
44         if config.PYLAB_INTERACTIVE :
45             _flush_plot = _pylab.draw
46         else :
47             _flush_plot = _pylab.show #_dummy_fn
48     if _final_flush_plot == None :
49         if config.PYLAB_INTERACTIVE :
50             _final_flush_plot = _pylab.draw
51         else :
52             _final_flush_plot = _dummy_fn # _pylab.show
53
54 def write_array(ofile, array, seperator):
55     """Erite an iterable array seperated by seperator.
56     Terminate the output with an endline."""
57     strings = [repr(x) for x in array]
58     ofile.write(seperator.join(strings))
59     ofile.write('\n')