@@ -19,50 +19,71 @@ def __init__(self, left: int, width: int, top: int, height: int):
19
19
20
20
class Scanner :
21
21
paper_formats = {
22
- 'A3' : PaperFormat (0 , 297 , 0 , 420 ),
23
- 'A4' : PaperFormat (0 , 210 , 0 , 297 ),
24
- 'A5' : PaperFormat (0 , 149 , 0 , 218 ),
22
+ "A3" : PaperFormat (0 , 297 , 0 , 420 ),
23
+ "A4" : PaperFormat (0 , 210 , 0 , 297 ),
24
+ "A5" : PaperFormat (0 , 149 , 0 , 218 ),
25
25
}
26
- page_file_suffix = ' .pnm'
26
+ page_file_suffix = " .pnm"
27
27
28
28
def __init__ (self , options : argparse .Namespace ):
29
-
30
- args = ['scanimage' , '-b' , '--format=pnm' ]
29
+ args = ["scanimage" , "-b" , "--format=pnm" ]
31
30
32
31
if options .device :
33
32
args += ["-d" , options .device ]
34
33
35
- color_mode = ' Gray'
36
- if options .color_mode == 'bw' :
37
- color_mode = ' Lineart'
38
- elif options .color_mode == ' color' :
39
- color_mode = ' Color'
40
- args += [' --mode' , color_mode ]
34
+ color_mode = " Gray"
35
+ if options .color_mode == "bw" :
36
+ color_mode = " Lineart"
37
+ elif options .color_mode == " color" :
38
+ color_mode = " Color"
39
+ args += [" --mode" , color_mode ]
41
40
42
41
if options .flatbed :
43
- args += [' --source' , ' Flatbed' , ' --batch-count' , '1' ]
42
+ args += [" --source" , " Flatbed" , " --batch-count" , "1" ]
44
43
else :
45
- args += [' --source' , ' Automatic Document Feeder' ]
46
- args += [' --adf-mode' , ' Duplex' if options .duplex else ' Simplex' ]
44
+ args += [" --source" , " Automatic Document Feeder" ]
45
+ args += [" --adf-mode" , " Duplex" if options .duplex else " Simplex" ]
47
46
48
- args += [' --resolution' , str (options .resolution )]
47
+ args += [" --resolution" , str (options .resolution )]
49
48
50
49
if options .threshold :
51
- args += ['--halftoning' , 'None' , '--threshold' , str (options .threshold )]
52
-
53
- paper_format = self .paper_formats .get (options .paper_format , self .paper_formats ['A4' ])
54
-
55
- args += ['-l' , str (int (options .paper_left if options .paper_left else paper_format .left ))]
56
- args += ['-x' , str (int (options .paper_width if options .paper_width else paper_format .width ))]
57
- args += ['-t' , str (int (options .paper_top if options .paper_top else paper_format .top ))]
58
- args += ['-y' , str (int (options .paper_height if options .paper_height else paper_format .height ))]
50
+ args += ["--halftoning" , "None" , "--threshold" , str (options .threshold )]
51
+
52
+ paper_format = self .paper_formats .get (
53
+ options .paper_format , self .paper_formats ["A4" ]
54
+ )
55
+
56
+ args += [
57
+ "-l" ,
58
+ str (int (options .paper_left if options .paper_left else paper_format .left )),
59
+ ]
60
+ args += [
61
+ "-x" ,
62
+ str (
63
+ int (options .paper_width if options .paper_width else paper_format .width )
64
+ ),
65
+ ]
66
+ args += [
67
+ "-t" ,
68
+ str (int (options .paper_top if options .paper_top else paper_format .top )),
69
+ ]
70
+ args += [
71
+ "-y" ,
72
+ str (
73
+ int (
74
+ options .paper_height
75
+ if options .paper_height
76
+ else paper_format .height
77
+ )
78
+ ),
79
+ ]
59
80
60
81
logger .debug ("call %s" , " " .join (args ))
61
82
retval = subprocess .call (args )
62
83
logger .debug ("call retured %d" , retval )
63
84
64
85
def get_page_file_basenames (self ) -> List [str ]:
65
- output_files = glob .glob (' out*' + self .page_file_suffix )
86
+ output_files = glob .glob (" out*" + self .page_file_suffix )
66
87
output_files = sorted (output_files , key = cmp_to_key (self .compare_output_names ))
67
88
68
89
return [os .path .splitext (output_file )[0 ] for output_file in output_files ]
0 commit comments