From d7b1e9ef47a0ea4ffa9e36005e3169fccc37eb21 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Thu, 20 Aug 2015 11:36:48 +0000 Subject: Work around multi-page scan bug in python-sane 2.6.1 python-sane 2.6.1 doesn't correctly recognise the end of a multi-page scane in sane._SaneIterator and raises an exception instead of stopping the iteration. Detect end of scan (signalled by libsane via the 'error' message "Document feeder out of documents") ourselves and handle it properly. --- diff --git a/scan.py b/scan.py index cdd5cc8..9398f2f 100644 --- a/scan.py +++ b/scan.py @@ -515,12 +515,17 @@ class ScanThread(threading.Thread): images = [] try: self._dpi = self._device.resolution - for image in scan_iter: - images.append(self._process_image(image)) - if self._check_action(['stop', 'quit']): - break + try: + for image in scan_iter: + images.append(self._process_image(image)) + if self._check_action(['stop', 'quit']): + break - self._dpi = self._device.resolution + self._dpi = self._device.resolution + except sane.error, exc: + # Work around python-sane bug. + if str(exc) != 'Document feeder out of documents': + raise self._images = images -- cgit v0.9.1