Package PyFoam :: Package ThirdParty :: Package Gnuplot :: Module gp_mac
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.ThirdParty.Gnuplot.gp_mac

  1  # $Id: gp_mac.py 292 2006-03-03 09:49:04Z mhagger $ 
  2   
  3  # Copyright (C) 1999-2003 Michael Haggerty <mhagger@alum.mit.edu> 
  4  # Thanks to Tony Ingraldi and Noboru Yamamoto for their contributions. 
  5  # 
  6  # This file is licensed under the GNU Lesser General Public License 
  7  # (LGPL).  See LICENSE.txt for details. 
  8   
  9  """gp_mac -- an interface to gnuplot for the Macintosh. 
 10   
 11  """ 
 12   
 13  import os, string 
 14   
 15  import Errors 
 16   
 17   
 18  # ############ Configuration variables: ################################ 
 19   
20 -class GnuplotOpts:
21 """The configuration options for gnuplot on the Macintosh. 22 23 See gp.py for details about the meaning of these options. Please 24 let me know if you know better choices for these settings.""" 25 26 # The '-persist' option is not supported on the Mac: 27 recognizes_persist = 0 28 29 # Apparently the Mac can use binary data: 30 recognizes_binary_splot = 1 31 32 # Apparently the Mac can not use inline data: 33 prefer_inline_data = 0 34 35 # os.mkfifo is not supported on the Mac. 36 support_fifo = 0 37 prefer_fifo_data = 0 38 39 # The default choice for the 'set term' command (to display on screen). 40 # Terminal types are different in Gnuplot 3.7.1c. 41 # For earlier versions, this was default_term = 'macintosh' 42 default_term = 'pict' 43 44 # I don't know how to print directly to a printer on the Mac: 45 default_lpr = '| lpr' 46 47 # Used the 'enhanced' option of postscript by default? Set to 48 # None (*not* 0!) if your version of gnuplot doesn't support 49 # enhanced postscript. 50 prefer_enhanced_postscript = 1
51 52 # ############ End of configuration options ############################ 53 54 55 # The Macintosh doesn't support pipes so communication is via 56 # AppleEvents. 57 58 import gnuplot_Suites 59 import Required_Suite 60 import aetools 61 62 63 # Mac doesn't recognize persist.
64 -def test_persist():
65 return 0
66 67
68 -class _GNUPLOT(aetools.TalkTo, 69 Required_Suite.Required_Suite, 70 gnuplot_Suites.gnuplot_Suite, 71 gnuplot_Suites.odds_and_ends, 72 gnuplot_Suites.Standard_Suite, 73 gnuplot_Suites.Miscellaneous_Events):
74 """Start a gnuplot program and emulate a pipe to it.""" 75
76 - def __init__(self):
77 aetools.TalkTo.__init__(self, '{GP}', start=1)
78 79
80 -class GnuplotProcess:
81 """Unsophisticated interface to a running gnuplot program. 82 83 See gp_unix.GnuplotProcess for usage information. 84 85 """ 86
87 - def __init__(self, persist=0):
88 """Start a gnuplot process. 89 90 Create a 'GnuplotProcess' object. This starts a gnuplot 91 program and prepares to write commands to it. 92 93 Keyword arguments: 94 95 'persist' -- the '-persist' option is not supported on the 96 Macintosh so this argument must be zero. 97 98 """ 99 100 if persist: 101 raise Errors.OptionError( 102 '-persist is not supported on the Macintosh!') 103 104 self.gnuplot = _GNUPLOT()
105
106 - def close(self):
107 if self.gnuplot is not None: 108 self.gnuplot.quit() 109 self.gnuplot = None
110
111 - def __del__(self):
112 self.close()
113
114 - def write(self, s):
115 """Mac gnuplot apparently requires '\r' to end statements.""" 116 117 self.gnuplot.gnuexec(string.replace(s, '\n', os.linesep))
118
119 - def flush(self):
120 pass
121
122 - def __call__(self, s):
123 """Send a command string to gnuplot, for immediate execution.""" 124 125 # Apple Script doesn't seem to need the trailing '\n'. 126 self.write(s) 127 self.flush()
128