1
2
3
4
5
6
7
8 """gp_java -- an interface to gnuplot used under Jython/Java.
9
10 This file implements a low-level interface to a gnuplot program run
11 via Jython/Java. This file should be imported through gp.py, which in
12 turn should be imported via 'import Gnuplot' rather than these
13 low-level interfaces.
14
15 """
16
17 __cvs_version__ = '$Revision: 2.3 $'
18
19
20
21
45
46
47
48 import sys
49
50 from java.lang import Thread
51 from java.lang import Runtime
52
53
60
61
63 """In a separate thread, read from one InputStream and output to a file.
64
65 """
66
67 - def __init__(self, name, input, output):
73
77
78
80 """Unsophisticated interface to a running gnuplot program.
81
82 This represents a running gnuplot program and the means to
83 communicate with it at a primitive level (i.e., pass it commands
84 or data). When the object is destroyed, the gnuplot program exits
85 (unless the 'persist' option was set). The communication is
86 one-way; gnuplot's text output just goes to stdout with no attempt
87 to check it for error messages.
88
89 Members:
90
91
92 Methods:
93
94 '__init__' -- start up the program.
95
96 '__call__' -- pass an arbitrary string to the gnuplot program,
97 followed by a newline.
98
99 'write' -- pass an arbitrary string to the gnuplot program.
100
101 'flush' -- cause pending output to be written immediately.
102
103 """
104
106 """Start a gnuplot process.
107
108 Create a 'GnuplotProcess' object. This starts a gnuplot
109 program and prepares to write commands to it.
110
111 Keyword arguments:
112
113 'persist=1' -- start gnuplot with the '-persist' option,
114 (which leaves the plot window on the screen even after
115 the gnuplot program ends, and creates a new plot window
116 each time the terminal type is set to 'x11'). This
117 option is not available on older versions of gnuplot.
118
119 """
120
121 if persist is None:
122 persist = GnuplotOpts.prefer_persist
123 command = [GnuplotOpts.gnuplot_command]
124 if persist:
125 if not test_persist():
126 raise ('-persist does not seem to be supported '
127 'by your version of gnuplot!')
128 command.append('-persist')
129
130
131
132
133
134
135
136 exec_method = getattr(Runtime.getRuntime(), 'exec')
137 self.process = exec_method(command)
138
139 self.outprocessor = OutputProcessor(
140 'gnuplot standard output processor',
141 self.process.getInputStream(), sys.stdout
142 )
143 self.outprocessor.start()
144 self.errprocessor = OutputProcessor(
145 'gnuplot standard error processor',
146 self.process.getErrorStream(), sys.stderr
147 )
148 self.errprocessor.start()
149
150 self.gnuplot = self.process.getOutputStream()
151
153 self.gnuplot.write(s)
154
157
159 """Send a command string to gnuplot, followed by newline."""
160
161 self.write(s + '\n')
162 self.flush()
163