Exemple #1
0
def convert_svg2eps(svg_filename, eps_filename, location=None):
    if location is None:
        location = get_external_program_location("inkscape")
        if location is None:
            location = "inkscape"
    try:
        process = subprocess.Popen(stdin=subprocess.PIPE,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   args=[
                                       location, "--export-area-page",
                                       "--export-eps", eps_filename,
                                       svg_filename
                                   ])
    except OSError as err_msg:
        log.error(
            "SVGImporter: failed to execute 'inkscape' (%s): %s%sMaybe you need to install "
            "Inkscape (http://inkscape.org)?", location, err_msg, os.linesep)
        return False
    returncode = process.wait()
    if returncode == 0:
        return True
    else:
        log.warn(
            "SVGImporter: failed to convert SVG file (%s) to EPS file (%s): %s",
            svg_filename, eps_filename, process.stderr.read())
        return False
Exemple #2
0
 def _locate_external_program(self, widget=None, key=None):
     # the button was just activated
     location = get_external_program_location(key)
     if not location:
         log.error("Failed to locate the external program '%s'. Please install the program and "
                   "try again.%sOr maybe you need to specify the location manually.",
                   key, os.linesep)
     else:
         # store the new setting
         self.settings.set("external_program_%s" % key, location)
Exemple #3
0
 def _locate_external_program(self, widget=None, key=None):
     # the button was just activated
     location = get_external_program_location(key)
     if not location:
         log.error("Failed to locate the external program '%s'. " % key \
                 + "Please install the program and try again." \
                 + os.linesep \
                 + "Or maybe you need to specify the location manually.")
     else:
         # store the new setting
         self.settings.set("external_program_%s" % key, location)
Exemple #4
0
def convert_eps2dxf(eps_filename, dxf_filename, location=None, unit="mm"):
    if location is None:
        location = get_external_program_location("pstoedit")
        if location is None:
            location = "pstoedit"
    args = [location, "-dt", "-nc", "-f", "dxf:-polyaslines"]
    if unit == "mm":
        # eps uses inch by default - we need to scale
        args.extend(("-xscale", "25.4", "-yscale", "25.4"))
    args.append(eps_filename)
    args.append(dxf_filename)
    try:
        process = subprocess.Popen(stdin=subprocess.PIPE,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   args=args)
    except OSError as err_msg:
        log.error(
            "SVGImporter: failed to execute 'pstoedit' (%s): %s%sMaybe you need to install "
            "pstoedit (http://pstoedit.net)?", location, err_msg, os.linesep)
        return False
    returncode = process.wait()
    if returncode == 0:
        try:
            # pstoedit fails with exitcode=0 if ghostscript is not installed.
            # The resulting file seems to be quite small (268 byte). But it is
            # not certain, that this filesize is fixed in case of this problem.
            if os.path.getsize(dxf_filename) < 280:
                log.warn(
                    "SVGImporter: maybe there was a problem with the conversion from EPS "
                    "(%s) to DXF.\nProbably you need to install 'ghostscript' "
                    "(http://pages.cs.wisc.edu/~ghost).", str(eps_filename))
            return True
        except OSError:
            # The dxf file was not created.
            log.warn(
                "SVGImporter: no DXF file was created, even though no error code was "
                "returned. This seems to be a bug of 'pstoedit'. Please send the original "
                "model file to the PyCAM developers. Thanks!")
            return False
    elif returncode == -11:
        log.warn(
            "SVGImporter: maybe there was a problem with the conversion from EPS (%s) to "
            "DXF.\n Users of Ubuntu 'lucid' should install the package 'libpstoedit0c2a' "
            "from the 'maverick' repository to avoid this warning.",
            str(eps_filename))
        return True
    else:
        log.warn(
            "SVGImporter: failed to convert EPS file (%s) to DXF file (%s): %s",
            eps_filename, dxf_filename, process.stderr.read())
        return False
Exemple #5
0
def convert_svg2eps(svg_filename, eps_filename, location=None):
    if location is None:
        location = get_external_program_location("inkscape")
        if location is None:
            location = "inkscape"
    try:
        process = subprocess.Popen(stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   args=[location, "--export-area-page", "--export-eps",
                                         eps_filename, svg_filename])
    except OSError as exc:
        raise LoadFileError("SVGImporter: failed to execute 'inkscape' ({}): {}{}Maybe you need "
                            "to install Inkscape (http://inkscape.org)?"
                            .format(location, exc, os.linesep))
    returncode = process.wait()
    if returncode != 0:
        raise LoadFileError("SVGImporter: failed to convert SVG file ({}) to EPS file ({}): {}"
                            .format(svg_filename, eps_filename, process.stderr.read()))
Exemple #6
0
def convert_svg2eps(svg_filename, eps_filename, location=None):
    if location is None:
        location = get_external_program_location("inkscape")
        if location is None:
            location = "inkscape"
    try:
        process = subprocess.Popen(stdin=subprocess.PIPE,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   args=[
                                       location, "--export-area-page",
                                       "--export-eps", eps_filename,
                                       svg_filename
                                   ])
    except OSError, err_msg:
        log.error(("SVGImporter: failed to execute 'inkscape' (%s): %s%s" + \
                "Maybe you need to install Inkscape (http://inkscape.org)?") % \
                (location, err_msg, os.linesep))
        return False
Exemple #7
0
def convert_svg2eps(svg_filename, eps_filename, location=None):
    if location is None:
        location = get_external_program_location("inkscape")
        if location is None:
            location = "inkscape"
    try:
        process = subprocess.Popen(
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            args=[location, "--export-area-page", "--export-eps", eps_filename, svg_filename],
        )
    except OSError, err_msg:
        log.error(
            (
                "SVGImporter: failed to execute 'inkscape' (%s): %s%s"
                + "Maybe you need to install Inkscape (http://inkscape.org)?"
            )
            % (location, err_msg, os.linesep)
        )
        return False
Exemple #8
0
def convert_eps2dxf(eps_filename, dxf_filename, location=None, unit="mm"):
    if location is None:
        location = get_external_program_location("pstoedit")
        if location is None:
            location = "pstoedit"
    args = [location, "-dt", "-nc", "-f", "dxf:-polyaslines"]
    if unit == "mm":
        # eps uses inch by default - we need to scale
        args.extend(("-xscale", "25.4", "-yscale", "25.4"))
    args.append(eps_filename)
    args.append(dxf_filename)
    try:
        process = subprocess.Popen(stdin=subprocess.PIPE,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   args=args)
    except OSError, err_msg:
        log.error(("SVGImporter: failed to execute 'pstoedit' (%s): %s%s" + \
                "Maybe you need to install pstoedit (http://pstoedit.net)?") % \
                (location, err_msg, os.linesep))
        return False
Exemple #9
0
def convert_eps2dxf(eps_filename, dxf_filename, location=None, unit="mm"):
    if location is None:
        location = get_external_program_location("pstoedit")
        if location is None:
            location = "pstoedit"
    args = [location, "-dt", "-nc", "-f", "dxf:-polyaslines"]
    if unit == "mm":
        # eps uses inch by default - we need to scale
        args.extend(("-xscale", "25.4", "-yscale", "25.4"))
    args.append(eps_filename)
    args.append(dxf_filename)
    try:
        process = subprocess.Popen(stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, args=args)
    except OSError, err_msg:
        log.error(
            (
                "SVGImporter: failed to execute 'pstoedit' (%s): %s%s"
                + "Maybe you need to install pstoedit (http://pstoedit.net)?"
            )
            % (location, err_msg, os.linesep)
        )
        return False