~ubuntu-branches/ubuntu/trusty/python-gnuplot/trusty

« back to all changes in this revision

Viewing changes to gp_win32.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2002-04-11 08:52:48 UTC
  • Revision ID: james.westby@ubuntu.com-20020411085248-r5kbl460aa2g9kdb
Tags: upstream-1.5
ImportĀ upstreamĀ versionĀ 1.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# $Id: gp_win32.py,v 2.9 2001/01/07 21:35:14 mhagger Exp $
 
2
 
 
3
# Copyright (C) 1999 Michael Haggerty <mhagger@alum.mit.edu>
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.  This program is distributed in
 
9
# the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 
10
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 
11
# PARTICULAR PURPOSE.  See the GNU General Public License for more
 
12
# details; it is available at <http://www.fsf.org/copyleft/gpl.html>,
 
13
# or by writing to the Free Software Foundation, Inc., 59 Temple Place
 
14
# - Suite 330, Boston, MA 02111-1307, USA.
 
15
 
 
16
"""gp_win32 -- an interface to gnuplot for Windows.
 
17
 
 
18
"""
 
19
 
 
20
__cvs_version__ = '$Revision: 2.9 $'
 
21
 
 
22
 
 
23
# ############ Configuration variables: ################################
 
24
 
 
25
class GnuplotOpts:
 
26
    """The configuration options for gnuplot under windows.
 
27
 
 
28
    See gp_unix.py for details about the meaning of these options.
 
29
    Please let me know if you know better choices for these settings.
 
30
 
 
31
    """
 
32
 
 
33
    # Command to start up the gnuplot program.  Note that on windows
 
34
    # the main gnuplot program cannot be used directly because it can
 
35
    # not read commands from standard input.  See README for more
 
36
    # information.
 
37
    gnuplot_command = 'pgnuplot.exe'
 
38
 
 
39
    # The '-persist' option is not supported on windows:
 
40
    recognizes_persist = 0
 
41
 
 
42
    # As far as I know, gnuplot under windows can use binary data:
 
43
    recognizes_binary_splot = 1
 
44
 
 
45
    # Apparently gnuplot on windows can use inline data, but we use
 
46
    # non-inline data (i.e., temporary files) by default for no
 
47
    # special reason:
 
48
    prefer_inline_data = 0
 
49
 
 
50
    # The default choice for the 'set term' command (to display on
 
51
    # screen):
 
52
    default_term = 'windows'
 
53
 
 
54
    # According to the gnuplot help manual, the following can be used
 
55
    # to print directly to a printer under windows.  (Of course it
 
56
    # won't help if your printer can't handle postscript!)
 
57
    default_lpr = 'PRN'
 
58
 
 
59
    # Used the 'enhanced' option of postscript by default?  Set to
 
60
    # None (*not* 0!) if your version of gnuplot doesn't support
 
61
    # enhanced postscript.
 
62
    prefer_enhanced_postscript = 1
 
63
 
 
64
# ############ End of configuration options ############################
 
65
 
 
66
 
 
67
try:
 
68
    from sys import hexversion
 
69
except ImportError:
 
70
    hexversion = 0
 
71
 
 
72
if hexversion >= 0x02000000:
 
73
    # Apparently at least as of Python 2.0b1, popen support for
 
74
    # windows is adequate.  Give that a try:
 
75
    from os import popen
 
76
else:
 
77
    # For earlier versions, you have to have the win32 extensions
 
78
    # installed and we use the popen that it provides.
 
79
    from win32pipe import popen
 
80
 
 
81
 
 
82
# Mac doesn't recognize persist.
 
83
def test_persist():
 
84
    return 0
 
85
 
 
86
 
 
87
class GnuplotProcess:
 
88
    """Unsophisticated interface to a running gnuplot program.
 
89
 
 
90
    See gp_unix.py for usage information.
 
91
 
 
92
    """
 
93
 
 
94
    def __init__(self, persist=0):
 
95
        """Start a gnuplot process.
 
96
 
 
97
        Create a 'GnuplotProcess' object.  This starts a gnuplot
 
98
        program and prepares to write commands to it.
 
99
 
 
100
        Keyword arguments:
 
101
 
 
102
            'persist' -- the '-persist' option is not supported under
 
103
                Windows so this argument must be zero.
 
104
 
 
105
        """
 
106
 
 
107
        assert not persist, '-persist is not supported under Windows!'
 
108
 
 
109
        self.gnuplot = popen(GnuplotOpts.gnuplot_command, 'w')
 
110
 
 
111
        # forward write and flush methods:
 
112
        self.write = self.gnuplot.write
 
113
        self.flush = self.gnuplot.flush
 
114
 
 
115
    def __call__(self, s):
 
116
        """Send a command string to gnuplot, followed by newline."""
 
117
 
 
118
        self.write(s + '\n')
 
119
        self.flush()
 
120
 
 
121