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
18
42
43
44
45 import sys
46
47 from java.lang import Thread
48 from java.lang import Runtime
49
50
57
58
60 """In a separate thread, read from one InputStream and output to a file.
61
62 """
63
64 - def __init__(self, name, input, output):
70
74
75
77 """Unsophisticated interface to a running gnuplot program.
78
79 This represents a running gnuplot program and the means to
80 communicate with it at a primitive level (i.e., pass it commands
81 or data). When the object is destroyed, the gnuplot program exits
82 (unless the 'persist' option was set). The communication is
83 one-way; gnuplot's text output just goes to stdout with no attempt
84 to check it for error messages.
85
86 Members:
87
88
89 Methods:
90
91 '__init__' -- start up the program.
92
93 '__call__' -- pass an arbitrary string to the gnuplot program,
94 followed by a newline.
95
96 'write' -- pass an arbitrary string to the gnuplot program.
97
98 'flush' -- cause pending output to be written immediately.
99
100 """
101
103 """Start a gnuplot process.
104
105 Create a 'GnuplotProcess' object. This starts a gnuplot
106 program and prepares to write commands to it.
107
108 Keyword arguments:
109
110 'persist=1' -- start gnuplot with the '-persist' option,
111 (which leaves the plot window on the screen even after
112 the gnuplot program ends, and creates a new plot window
113 each time the terminal type is set to 'x11'). This
114 option is not available on older versions of gnuplot.
115
116 """
117
118 if persist is None:
119 persist = GnuplotOpts.prefer_persist
120 command = [GnuplotOpts.gnuplot_command]
121 if persist:
122 if not test_persist():
123 raise ('-persist does not seem to be supported '
124 'by your version of gnuplot!')
125 command.append('-persist')
126
127
128
129
130
131
132
133 exec_method = getattr(Runtime.getRuntime(), 'exec')
134 self.process = exec_method(command)
135
136 self.outprocessor = OutputProcessor(
137 'gnuplot standard output processor',
138 self.process.getInputStream(), sys.stdout
139 )
140 self.outprocessor.start()
141 self.errprocessor = OutputProcessor(
142 'gnuplot standard error processor',
143 self.process.getErrorStream(), sys.stderr
144 )
145 self.errprocessor.start()
146
147 self.gnuplot = self.process.getOutputStream()
148
150
151 if self.gnuplot is not None:
152 self.gnuplot.close()
153 self.gnuplot = None
154
157
159 self.gnuplot.write(s)
160
163
165 """Send a command string to gnuplot, followed by newline."""
166
167 self.write(s + '\n')
168 self.flush()
169