11# -*- coding: utf-8 -*-
22
33from kivy .app import App
4- from kivy .lang import Builder
54from kivy .uix .boxlayout import BoxLayout
65from kivy .uix .image import Image
76from kivy .core .image import ImageData
109from kivy .properties import NumericProperty , ObjectProperty , BooleanProperty , StringProperty
1110from kivy .uix .behaviors import ToggleButtonBehavior
1211from kivy .graphics import Line , Color
13- from StringIO import StringIO
1412from img2pdf import pdfdoc
1513from datetime import datetime
1614import smtplib
2119
2220from .scanner import Scanner
2321
22+ try :
23+ from StringIO import StringIO
24+ except :
25+ from io import StringIO
26+
2427
2528class ScanMan (BoxLayout ):
2629 scan_button = ObjectProperty (None )
@@ -113,18 +116,18 @@ def set_connected(state):
113116 self .scanner .connected (set_connected )
114117
115118 def on_connected (self , instance , value ):
116- print 'connected' , value
119+ print ( 'connected' , value )
117120 self .reset_custom_status ()
118121 self ._update_status ()
119122
120123 def on_ready (self , instance , value ):
121- print 'ready' , value
124+ print ( 'ready' , value )
122125 if not self .scanning :
123126 self .reset_custom_status ()
124127 self ._update_status ()
125128
126129 def on_scanning (self , instance , value ):
127- print 'scanning' , value
130+ print ( 'scanning' , value )
128131 self ._update_status ()
129132
130133 def on_custom_status_text (self , instance , value ):
@@ -165,14 +168,14 @@ def scan(self):
165168 self .reset_custom_status ()
166169 self .scanning = True
167170 profile = self .settings ['profiles' ][self .ui .active_profile ()]
168- print 'scan with profile' , profile .get ('name' )
171+ print ( 'scan with profile' , profile .get ('name' ) )
169172
170173 pdf = pdfdoc ()
171174 dpi = self .scanner .dev .resolution
172175
173176 def scan_processor (page_index , image ):
174- print 'processing page %d' % (page_index + 1 )
175- self .custom_status_text = 'Processing page %d' % (page_index + 1 )
177+ print ( 'processing page {}' . format (page_index + 1 ) )
178+ self .custom_status_text = 'Processing page {}' . format (page_index + 1 )
176179 self ._update_preview (image )
177180 buf = StringIO ()
178181 image .save (buf , format = 'JPEG' , quality = 75 , optimize = True )
@@ -182,7 +185,7 @@ def scan_processor(page_index, image):
182185 buf .close ()
183186
184187 def done ():
185- print 'processing document'
188+ print ( 'processing document' )
186189 self .custom_status_text = 'Processing document…'
187190 self ._update_status ()
188191 filename = datetime .now ().strftime (self .settings .get ('filename' , '%Y%m%d-%H%M%S' ))
@@ -193,7 +196,7 @@ def done():
193196 att = MIMEApplication (pdf .tostring (), _subtype = 'pdf' )
194197 att .add_header ('content-disposition' , 'attachment' , filename = ('utf-8' , '' , filename + '.pdf' ))
195198 msg .attach (att )
196- print 'sending email' , profile
199+ print ( 'sending email' , profile )
197200 self .custom_status_text = 'Sending email…'
198201 s = smtplib .SMTP (profile .get ('smtp_server' , self .settings .get ('smtp_server' , 'localhost' )))
199202 if profile .get ('smtp_tls' , self .settings .get ('smtp_tls' , False )):
@@ -215,7 +218,7 @@ def cancelled():
215218 self .scanner .scan (scan_processor , done , cancelled )
216219
217220 def cancel (self ):
218- print 'cancelling'
221+ print ( 'cancelling' )
219222 self .scanning = False
220223 self .scanner .cancel ()
221224
@@ -224,7 +227,7 @@ def main():
224227 try :
225228 settings = yaml .safe_load (open (sys .argv [1 ]))
226229 except :
227- print " Syntax: scanman <path/to/config.yaml>"
230+ print ( ' Syntax: scanman <path/to/config.yaml>' )
228231 exit (1 )
229232 ScanManApp (settings ).run ()
230233
0 commit comments