| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ | |||
| 15 | 15 | import getopt | |
| 16 | 16 | import os | |
| 17 | 17 | import sys | |
| 18 | + import subprocess | ||
| 18 | 19 | ||
| 19 | 20 | VERSION = "pilprint 0.3/2003-05-05" | |
| 20 | 21 | ||
@@ -46,8 +47,8 @@ def description(filepath, image): | |||
| 46 | 47 | print(v) | |
| 47 | 48 | sys.exit(1) | |
| 48 | 49 | ||
| 49 | - printer = None # print to stdout | ||
| 50 | - monochrome = 1 # reduce file size for most common case | ||
| 50 | + printerArgs = [] # print to stdout | ||
| 51 | + monochrome = 1 # reduce file size for most common case | ||
| 51 | 52 | ||
| 52 | 53 | for o, a in opt: | |
| 53 | 54 | if o == "-d": | |
@@ -60,10 +61,10 @@ def description(filepath, image): | |||
| 60 | 61 | monochrome = 0 | |
| 61 | 62 | elif o == "-p": | |
| 62 | 63 | # default printer channel | |
| 63 | - printer = "lpr" | ||
| 64 | + printerArgs = ["lpr"] | ||
| 64 | 65 | elif o == "-P": | |
| 65 | 66 | # printer channel | |
| 66 | - printer = "lpr -P%s" % a | ||
| 67 | + printerArgs = ["lpr","-P%s" % a] | ||
| 67 | 68 | ||
| 68 | 69 | for filepath in argv: | |
| 69 | 70 | try: | |
@@ -76,8 +77,9 @@ def description(filepath, image): | |||
| 76 | 77 | im.draft("L", im.size) | |
| 77 | 78 | im = im.convert("L") | |
| 78 | 79 | ||
| 79 | - if printer: | ||
| 80 | - fp = os.popen(printer, "w") | ||
| 80 | + if printerArgs: | ||
| 81 | + p = subprocess.Popen(printerArgs, stdin=subprocess.PIPE) | ||
| 82 | + fp = p.stdin | ||
| 81 | 83 | else: | |
| 82 | 84 | fp = sys.stdout | |
| 83 | 85 | ||
@@ -91,6 +93,9 @@ def description(filepath, image): | |||
| 91 | 93 | ps.image(letter, im) | |
| 92 | 94 | ps.end_document() | |
| 93 | 95 | ||
| 96 | + if printerArgs: | ||
| 97 | + fp.close() | ||
| 98 | + | ||
| 94 | 99 | except: | |
| 95 | 100 | print("cannot print image", end=' ') | |
| 96 | 101 | print("(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1])) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments