1
2
3
4
5
6
7
8 """gp_macosx -- an interface to the command line version of gnuplot
9 used under Mac OS X.
10
11 The only difference between this interface and gp_unix is that
12 default_term is 'aqua'.
13
14 This file implements a low-level interface to gnuplot. This file
15 should be imported through gp.py, which in turn should be imported via
16 'import Gnuplot' rather than using these low-level interfaces
17 directly.
18
19 """
20
21 __cvs_version__ = '$Revision: 1.3 $'
22
23
24
25
47
48
49
50 from os import popen
51
52
54 """Determine whether gnuplot recognizes the option '-persist'.
55
56 If the configuration variable 'recognizes_persist' is set (i.e.,
57 to something other than 'None'), return that value. Otherwise,
58 try to determine whether the installed version of gnuplot
59 recognizes the -persist option. (If it doesn't, it should emit an
60 error message with '-persist' in the first line.) Then set
61 'recognizes_persist' accordingly for future reference.
62
63 """
64
65 if GnuplotOpts.recognizes_persist is None:
66 import string
67 g = popen('echo | %s -persist 2>&1' % GnuplotOpts.gnuplot_command, 'r')
68 response = g.readlines()
69 g.close()
70 GnuplotOpts.recognizes_persist = (
71 (not response) or (string.find(response[0], '-persist') == -1))
72 return GnuplotOpts.recognizes_persist
73
74
76 """Unsophisticated interface to a running gnuplot program.
77
78 This represents a running gnuplot program and the means to
79 communicate with it at a primitive level (i.e., pass it commands
80 or data). When the object is destroyed, the gnuplot program exits
81 (unless the 'persist' option was set). The communication is
82 one-way; gnuplot's text output just goes to stdout with no attempt
83 to check it for error messages.
84
85 Members:
86
87 'gnuplot' -- the pipe to the gnuplot command.
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 if persist:
121 if not test_persist():
122 raise ('-persist does not seem to be supported '
123 'by your version of gnuplot!')
124 self.gnuplot = popen('%s -persist' % GnuplotOpts.gnuplot_command,
125 'w')
126 else:
127 self.gnuplot = popen(GnuplotOpts.gnuplot_command, 'w')
128
129 self.write = self.gnuplot.write
130 self.flush = self.gnuplot.flush
131
133 """Send a command string to gnuplot, followed by newline."""
134
135 self.write(s + '\n')
136 self.flush()
137