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

Source Code for Module PyFoam.ThirdParty.Gnuplot.gp_cygwin

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