gs_frontend.py :  » Chart-Report » Pychart » PyChart-1.39 » pychart » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Chart Report » Pychart 
Pychart » PyChart 1.39 » pychart » gs_frontend.py
#
# Copyright (C) 2000-2005 by Yasushi Saito (yasushi.saito@gmail.com)
# 
# Jockey is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.
#
# Jockey is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
import pychart_util
import theme
import sys
import os
import os.path
import pscanvas
import tempfile
import basecanvas
from scaling import *

def _get_gs_path():
    """Guess where the Ghostscript executable is
    and return its absolute path name."""
    path = os.environ.get("PATH", os.defpath)
    
    for dir in path.split(os.pathsep):
        for name in ("gs", "gs.exe", "gswin32c.exe"):
            g = os.path.join(dir, name)
            if os.path.exists(g):
                return g
    raise Exception, "Ghostscript not found. path=%s" % str(path)

class T(pscanvas.T):
    """This class is a special kind of canvas that runs ghostscript
    on the generated postscript contents. It is not used stand-alone, but as
    a component of PNG and X11 display functionality."""
    
    def __write_contents(self, fp):
        fp.write(pscanvas.preamble_text)
        for name, id in self.__font_ids.items():
            fp.write("/%s {/%s findfont SF} def\n" % (id, name))
        fp.write("%d %d translate\n" % (-self.bbox[0], -self.bbox[1]))
        fp.writelines(self.__output_lines)
        fp.write("showpage end\n")
        fp.flush()

    def close(self):
        # Don't call pscanvas.T.close, as it creates a
        # ps file. 
        basecanvas.T.close(self)
        
    def start_gs(self, arg):
        self.bbox = theme.adjust_bounding_box([xscale(self.__xmin),
                                               yscale(self.__ymin),
                                               xscale(self.__xmax),
                                               yscale(self.__ymax)])
        
        gs_path = _get_gs_path()
        self.pipe_fp = None
  if self.__output_lines == []:
      return

        if sys.platform != "win32" and hasattr(os, "popen"):
            # UNIX-like systems
            cmdline = "\"%s\" -q %s -g%dx%d -q >/dev/null 2>&1" % \
            (gs_path, arg,
             self.bbox[2] - self.bbox[0],
             self.bbox[3] - self.bbox[1])
            self.pipe_fp = os.popen(cmdline, "w")
            self.__write_contents(self.pipe_fp)
        else:
            # XXX should use mktemp, but need to support python<=2.2 as well.
            fname = tempfile.mktemp("xxx")
            fp = open(fname, "wb")
            self.__write_contents(fp)
            fp.close()
            cmdline = "\"%s\" -q %s -g%dx%d -q <%s >NUL" % \
            (gs_path, arg,
             self.bbox[2] - self.bbox[0],
             self.bbox[3] - self.bbox[1], fname)
            os.system(cmdline)
            os.unlink(fname)
    def close_gs(self):
        if self.pipe_fp:
            self.pipe_fp.close()
            self.pipe_fp = None
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.