Added gnuplot backend.
[smonitor.git] / monitor / extra / Gnuplot / gp_cygwin.py
blob8e00ea03946692b4f5a8687044924200b8a08019
1 # $Id: gp_cygwin.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_cygwin -- an interface to gnuplot for cygwin under Windows.
10 This is identical to gp_win32.py except that prefer_inline_data is
11 set.
13 """
15 import Errors
17 # ############ Configuration variables: ################################
19 class GnuplotOpts:
20 """The configuration options for gnuplot under windows.
22 See gp_unix.py for details about the meaning of these options.
23 Please let me know if you know better choices for these settings.
25 """
27 # Command to start up the gnuplot program. Note that on windows
28 # the main gnuplot program cannot be used directly because it can
29 # not read commands from standard input. See README for more
30 # information.
32 # If pgnuplot is in a subdirectory with spaces in its name, extra
33 # quoting is required for windows for it to launch gnuplot.
34 # Moreover, any backslashes in the filename have to be escaped by
35 # writing them as "\\". Example:
37 # gnuplot_command = '"C:\\Program Files\\gp371w32\\pgnuplot.exe"'
38 gnuplot_command = 'pgnuplot.exe'
40 # The '-persist' option is not supported on windows:
41 recognizes_persist = 0
43 # As far as I know, gnuplot under windows can use binary data:
44 recognizes_binary_splot = 1
46 # Apparently gnuplot on windows can use inline data, but we use
47 # non-inline data (i.e., temporary files) by default for no
48 # special reason:
49 prefer_inline_data = 1
51 # os.mkfifo is apparently not supported under Windows.
52 support_fifo = 0
53 prefer_fifo_data = 0
55 # The default choice for the 'set term' command (to display on
56 # screen):
57 default_term = 'windows'
59 # According to the gnuplot help manual, the following can be used
60 # to print directly to a printer under windows. (Of course it
61 # won't help if your printer can't handle postscript!)
62 default_lpr = 'PRN'
64 # Used the 'enhanced' option of postscript by default? Set to
65 # None (*not* 0!) if your version of gnuplot doesn't support
66 # enhanced postscript.
67 prefer_enhanced_postscript = 1
69 # ############ End of configuration options ############################
72 try:
73 from sys import hexversion
74 except ImportError:
75 hexversion = 0
77 if hexversion >= 0x02000000:
78 # Apparently at least as of Python 2.0b1, popen support for
79 # windows is adequate. Give that a try:
80 from os import popen
81 else:
82 # For earlier versions, you have to have the win32 extensions
83 # installed and we use the popen that it provides.
84 from win32pipe import popen
87 # Mac doesn't recognize persist.
88 def test_persist():
89 return 0
92 class GnuplotProcess:
93 """Unsophisticated interface to a running gnuplot program.
95 See gp_unix.py for usage information.
97 """
99 def __init__(self, persist=0):
100 """Start a gnuplot process.
102 Create a 'GnuplotProcess' object. This starts a gnuplot
103 program and prepares to write commands to it.
105 Keyword arguments:
107 'persist' -- the '-persist' option is not supported under
108 Windows so this argument must be zero.
112 if persist:
113 raise Errors.OptionError(
114 '-persist is not supported under Windows!')
116 self.gnuplot = popen(GnuplotOpts.gnuplot_command, 'w')
118 # forward write and flush methods:
119 self.write = self.gnuplot.write
120 self.flush = self.gnuplot.flush
122 def close(self):
123 if self.gnuplot is not None:
124 self.gnuplot.close()
125 self.gnuplot = None
127 def __del__(self):
128 self.close()
130 def __call__(self, s):
131 """Send a command string to gnuplot, followed by newline."""
133 self.write(s + '\n')
134 self.flush()