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

Source Code for Module PyFoam.ThirdParty.Gnuplot.gp_win32

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