forked from tschaume/gnuplot-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gp_cygwin.py
136 lines (95 loc) · 3.81 KB
/
gp_cygwin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# $Id$
# Copyright (C) 1999-2003 Michael Haggerty <[email protected]>
#
# This file is licensed under the GNU Lesser General Public License
# (LGPL). See LICENSE.txt for details.
"""gp_cygwin -- an interface to gnuplot for cygwin under Windows.
This is identical to gp_win32.py except that prefer_inline_data is
set.
"""
import Errors
# ############ Configuration variables: ################################
class GnuplotOpts:
"""The configuration options for gnuplot under windows.
See gp_unix.py for details about the meaning of these options.
Please let me know if you know better choices for these settings.
"""
# Command to start up the gnuplot program. Note that on windows
# the main gnuplot program cannot be used directly because it can
# not read commands from standard input. See README for more
# information.
#
# If pgnuplot is in a subdirectory with spaces in its name, extra
# quoting is required for windows for it to launch gnuplot.
# Moreover, any backslashes in the filename have to be escaped by
# writing them as "\\". Example:
#
# gnuplot_command = '"C:\\Program Files\\gp371w32\\pgnuplot.exe"'
gnuplot_command = 'pgnuplot.exe'
# The '-persist' option is not supported on windows:
recognizes_persist = 0
# As far as I know, gnuplot under windows can use binary data:
recognizes_binary_splot = 1
# Apparently gnuplot on windows can use inline data, but we use
# non-inline data (i.e., temporary files) by default for no
# special reason:
prefer_inline_data = 1
# os.mkfifo is apparently not supported under Windows.
support_fifo = 0
prefer_fifo_data = 0
# The default choice for the 'set term' command (to display on
# screen):
default_term = 'windows'
# According to the gnuplot help manual, the following can be used
# to print directly to a printer under windows. (Of course it
# won't help if your printer can't handle postscript!)
default_lpr = 'PRN'
# Used the 'enhanced' option of postscript by default? Set to
# None (*not* 0!) if your version of gnuplot doesn't support
# enhanced postscript.
prefer_enhanced_postscript = 1
# ############ End of configuration options ############################
try:
from sys import hexversion
except ImportError:
hexversion = 0
if hexversion >= 0x02000000:
# Apparently at least as of Python 2.0b1, popen support for
# windows is adequate. Give that a try:
from os import popen
else:
# For earlier versions, you have to have the win32 extensions
# installed and we use the popen that it provides.
from win32pipe import popen
# Mac doesn't recognize persist.
def test_persist():
return 0
class GnuplotProcess:
"""Unsophisticated interface to a running gnuplot program.
See gp_unix.py for usage information.
"""
def __init__(self, persist=0):
"""Start a gnuplot process.
Create a 'GnuplotProcess' object. This starts a gnuplot
program and prepares to write commands to it.
Keyword arguments:
'persist' -- the '-persist' option is not supported under
Windows so this argument must be zero.
"""
if persist:
raise Errors.OptionError(
'-persist is not supported under Windows!')
self.gnuplot = popen(GnuplotOpts.gnuplot_command, 'w')
# forward write and flush methods:
self.write = self.gnuplot.write
self.flush = self.gnuplot.flush
def close(self):
if self.gnuplot is not None:
self.gnuplot.close()
self.gnuplot = None
def __del__(self):
self.close()
def __call__(self, s):
"""Send a command string to gnuplot, followed by newline."""
self.write(s + '\n')
self.flush()