From: W. Trevor King Date: Tue, 28 Oct 2008 11:43:38 +0000 (-0400) Subject: Added python interface to stripchart program (shell out). X-Git-Url: http://git.tremily.us/?p=stripchart.git;a=commitdiff_plain;h=c71ea9750d77cdc057328b6cec2bb4fb62403d63 Added python interface to stripchart program (shell out). --- diff --git a/stripchart.py b/stripchart.py new file mode 100644 index 0000000..bf27ca1 --- /dev/null +++ b/stripchart.py @@ -0,0 +1,42 @@ +import os + +class stripchart : + def __init__(self, pipename='strip_pipe', maxY=10, minY=-10, + npoints=100, title='chart', axes=True) : + self.pipename = pipename + self.maxY = maxY + self.minY = minY + self.npoints = npoints + self.title = title + self.axes = axes + self.status = 'closed' + self.pipe = None + def __del__(self) : + self.close() + def open(self, debug=False) : + if self.status == 'closed' : + os.mkfifo(self.pipename) + cmd = "stripchart -t '%s' -p '%s' -u -M '%g' -m '%g' -n '%d'" % \ + (self.title, self.pipename, self.maxY, self.minY, + self.npoints) + if self.axes == False : + cmd += " -a" + cmd += " &" + if debug : + print cmd + os.system(cmd) + self.pipe = open(self.pipename,'w') + self.status = 'open' + def close(self) : + if self.status == 'open' : + print >> self.pipe, "q" + self.pipe.close() + self.pipe = None + self.status = 'closed' + def _add_point(self, point) : + print >> self.pipe, point + def _flush(self) : + self.pipe.flush() + def add_point(self, point) : + self._add_point(point) + self._flush()