Added var plotting using js.
[smonitor.git] / monitor / extra / Gnuplot / gp_win32.py
blob03281ff52364a70dc7a0d10ac9ed37392db29891
1 # $Id: gp_win32.py 292 2006-03-03 09:49:04Z mhagger $
3 # Copyright (C) 1999-2003 Michael Haggerty <mhagger@alum.mit.edu>
5 # This file is licensed under the GNU Lesser General Public License
6 # (LGPL). See LICENSE.txt for details.
8 """gp_win32 -- an interface to gnuplot for Windows.
10 """
12 import Errors
14 # ############ Configuration variables: ################################
16 class GnuplotOpts:
17 """The configuration options for gnuplot under windows.
19 See gp_unix.py for details about the meaning of these options.
20 Please let me know if you know better choices for these settings.
22 """
24 # Command to start up the gnuplot program. Note that on windows
25 # the main gnuplot program cannot be used directly because it can
26 # not read commands from standard input. See README for more
27 # information.
29 # If pgnuplot is in a subdirectory with spaces in its name, extra
30 # quoting is required for windows for it to launch gnuplot.
31 # Moreover, it is suggested to use a raw string to avoid having to
32 # quote backslashes in the filename. Example:
34 # gnuplot_command = r'"C:\Program Files\gp371w32\pgnuplot.exe"'
35 gnuplot_command = r'pgnuplot.exe'
37 # The '-persist' option is not supported on windows:
38 recognizes_persist = 0
40 # As far as I know, gnuplot under windows can use binary data:
41 recognizes_binary_splot = 1
43 # Apparently gnuplot on windows can use inline data, but we use
44 # non-inline data (i.e., temporary files) by default for no
45 # special reason:
46 prefer_inline_data = 0
48 # os.mkfifo is apparently not supported under Windows.
49 support_fifo = 0
50 prefer_fifo_data = 0
52 # The default choice for the 'set term' command (to display on
53 # screen):
54 default_term = 'windows'
56 # According to the gnuplot help manual, the following can be used
57 # to print directly to a printer under windows. (Of course it
58 # won't help if your printer can't handle postscript!)
59 default_lpr = 'PRN'
61 # Used the 'enhanced' option of postscript by default? Set to
62 # None (*not* 0!) if your version of gnuplot doesn't support
63 # enhanced postscript.
64 prefer_enhanced_postscript = 1
66 # ############ End of configuration options ############################
69 try:
70 from sys import hexversion
71 except ImportError:
72 hexversion = 0
74 if hexversion >= 0x02000000:
75 # Apparently at least as of Python 2.0b1, popen support for
76 # windows is adequate. Give that a try:
77 from os import popen
78 else:
79 # For earlier versions, you have to have the win32 extensions
80 # installed and we use the popen that it provides.
81 from win32pipe import popen
84 # Mac doesn't recognize persist.
85 def test_persist():
86 return 0
89 class GnuplotProcess:
90 """Unsophisticated interface to a running gnuplot program.
92 See gp_unix.py for usage information.
94 """
96 def __init__(self, persist=0):
97 """Start a gnuplot process.
99 Create a 'GnuplotProcess' object. This starts a gnuplot
100 program and prepares to write commands to it.
102 Keyword arguments:
104 'persist' -- the '-persist' option is not supported under
105 Windows so this argument must be zero.
109 if persist:
110 raise Errors.OptionError(
111 '-persist is not supported under Windows!')
113 self.gnuplot = popen(GnuplotOpts.gnuplot_command, 'w')
115 # forward write and flush methods:
116 self.write = self.gnuplot.write
117 self.flush = self.gnuplot.flush
119 def close(self):
120 if self.gnuplot is not None:
121 self.gnuplot.close()
122 self.gnuplot = None
124 def __del__(self):
125 self.close()
127 def __call__(self, s):
128 """Send a command string to gnuplot, followed by newline."""
130 self.write(s + '\n')
131 self.flush()