~ubuntu-branches/ubuntu/trusty/python-imaging/trusty

« back to all changes in this revision

Viewing changes to PIL/Image.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-04-09 16:29:57 UTC
  • Revision ID: james.westby@ubuntu.com-20080409162957-muwihgc7iu0n937p
Tags: 1.1.6-1ubuntu4
Search for available image viewers. LP: #67755.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
import ImageMode
69
69
import ImagePalette
70
70
 
71
 
import os, string, sys
 
71
import os, stat, string, sys
72
72
 
73
73
# type stuff
74
74
from types import IntType, StringType, TupleType
2065
2065
    else:
2066
2066
        format = None
2067
2067
        if not command:
2068
 
            command = "xv"
2069
 
            if title:
 
2068
            for cmd in ["eog", "gqview", "gwenview", "xv"]:
 
2069
                if _iscommand(cmd):
 
2070
                    command = cmd
 
2071
                    break
 
2072
            if not command:
 
2073
                # raise OSError, "no image viewer found"
 
2074
                print "no image viewer found"
 
2075
            if command in ("xv") and title:
2070
2076
                command = command + " -name \"%s\"" % title
2071
2077
 
2072
2078
    if image.mode == "I;16":
2091
2097
        command = "(%s %s; rm -f %s)&" % (command, file, file)
2092
2098
 
2093
2099
    os.system(command)
 
2100
 
 
2101
def _isexecutable(cmd):
 
2102
    if os.path.isfile(cmd):
 
2103
        mode = os.stat(cmd)[stat.ST_MODE]
 
2104
        if mode & stat.S_IXUSR or mode & stat.S_IXGRP or mode & stat.S_IXOTH:
 
2105
            return True
 
2106
    return False
 
2107
 
 
2108
def _iscommand(cmd):
 
2109
    """Return True if cmd is executable or can be found on the executable
 
2110
    search path."""
 
2111
    if _isexecutable(cmd):
 
2112
        return True
 
2113
    path = os.environ.get("PATH")
 
2114
    if not path:
 
2115
        return False
 
2116
    for d in path.split(os.pathsep):
 
2117
        exe = os.path.join(d, cmd)
 
2118
        if _isexecutable(exe):
 
2119
            return True
 
2120
    return False