コード例 #1
0
ファイル: draw.py プロジェクト: BackupTheBerlios/pyformex-svn
def saveImage(fn,fmt=None,verbose=False):
    """Save the current rendering on file fn in format fmt.

    If no format is specified, it is derived from the extension.
    fmt should be one of the valid formats as returned by imageFormats()
    If the file has no extension, one is added based on the format.
    If verbose=True, error/warnings are activated. 
    """
    ext = os.path.splitext(fn)[1]
    if not fmt:
        fmt = utils.imageFormatFromExt(ext)
    fmt = checkImageFormat(fmt,verbose)
    if fmt:
        if len(ext) == 0:
            ext = '.%s' % fmt.lower()
            fn += ext
        GD.canvas.save(fn,fmt)
コード例 #2
0
ファイル: draw.py プロジェクト: BackupTheBerlios/pyformex-svn
def saveMulti(fn=None,fmt=None,verbose=False):
    """Save a sequence of images.

    If the filename supplied has a trailing numeric part, subsequent images
    will be numbered continuing from this number. Otherwise a numeric part
    -000, -001, will be added to the filename.

    Without filename, switches off multisave mode.
    """
    global multisave
    # Leave multisave mode
    if not fn:
        if multisave:
            log("Leaving multi save mode")
            QtCore.QObject.disconnect(GD.canvas,QtCore.SIGNAL("Save"),saveNext)
        multisave = None
        return

    # Enter multisave mode
    log("Entering multiple save mode to files:")
    setWorkdirFromFile(fn)
    name,ext = os.path.splitext(fn)
    fmt = utils.imageFormatFromExt(ext)
    log("%s-???.%s (%s)" % (name,ext,fmt))
    fmt = checkImageFormat(fmt,verbose)
    if fmt:
        name,number = utils.splitEndDigits(name)
        if len(number) > 0:
            nr = int(number)
            name += "%%0%dd" % len(number)
        else:
            nr = 0
            name += "-%03d"
        if len(ext) == 0:
            ext = '.%s' % fmt.lower()
        name += ext
        if verbose:
            warning("Each time you hit the 'S' key,\nthe image will be saved to the next number.")
        QtCore.QObject.connect(GD.canvas,QtCore.SIGNAL("Save"),saveNext)
        multisave = [ name,nr,fmt ]
コード例 #3
0
ファイル: draw.py プロジェクト: BackupTheBerlios/pyformex-svn
def saveImage(filename=None,window=False,multi=False,hotkey=True,autosave=False,format=None,verbose=False):
    """Starts or stops saving a sequence of images.

    With a filename, this starts or changes the multisave mode.
    In multisave mode, each call to saveNext() will save an image to the
    next generated file name.
    Filenames are generated by incrementing a numeric part of the name.
    If the supplied filename (after removing the extension) has a trailing
    numeric part, subsequent images will be numbered continuing from this
    number. Otherwise a numeric part '-000' will be added to the filename.

    Without filename, exits the multisave mode. It is acceptable to have
    two subsequent saveMulti calls with a filename, without an intermediate
    call without filename.

    If window is True, the full pyFormex window is saved.
    If window is False, only the canvas is saved.

    If hotkey is True, a new image will be saved by hitting the 'S' key.
    If autosave is True, a new image will be saved on each execution of
    the 'draw' function.
    If neither hotkey nor autosave are True, images can only be saved by
    executing the saveNext() function from a script.

    If no format is specified, it is derived from the filename extension.
    fmt should be one of the valid formats as returned by imageFormats()
  
    If verbose=True, error/warnings are activated. This is usually done when
    this function is called from the GUI.
    
    """
    global multisave

    # Leave multisave mode
    if filename is None:
        if multisave:
            log("Leave multisave mode")
            QtCore.QObject.disconnect(GD.canvas,QtCore.SIGNAL("Save"),saveNext)
        multisave = None
        return

    setWorkdirFromFile(filename)
    name,ext = os.path.splitext(filename)
    # Get/Check format
    if format is None:
        format = checkImageFormat(utils.imageFormatFromExt(ext))
    if not format:
        return

    if multi: # Start multisave mode
        names = utils.FilenameSequence(name,ext)
        log("Start multisave mode to files: %s (%s)" % (names.name,format))
        print hotkey
        if hotkey:
             QtCore.QObject.connect(GD.canvas,QtCore.SIGNAL("Save"),saveNext)
             if verbose:
                 warning("Each time you hit the 'S' key,\nthe image will be saved to the next number.")
        multisave = (names,format,window,hotkey,autosave)
        return multisave is None

    else: # Save the image
        if window:
            sta = save_window(filename,format)
        else:
            sta = GD.canvas.save(filename,format)
        if sta:
            GD.debug("Error while saving image %s" % filename)
        else:
            log("Image file %s written" % filename)
        return