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