Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Commit

Permalink
Improve tolerance to crappy scanner drivers: don't stop if pyinsane_m…
Browse files Browse the repository at this point in the history
…aximize_area() fails

Signed-off-by: Jerome Flesch <[email protected]>
  • Loading branch information
jflesch committed Nov 22, 2016
1 parent 541bc57 commit 55b72fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
11 changes: 9 additions & 2 deletions src/paperwork/frontend/settingswindow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,20 @@ def _do(self):
resolution, exc
)
)
logger.exception(exc)
resolution = int(dev.options['resolution'].value)
logger.warning("Falling back to current resolution: {}".format(resolution))
try:
pyinsane2.set_scanner_opt(dev, 'mode', ["Color"])
except pyinsane2.PyinsaneException as exc:
logger.warning("Unable to set scanner mode ! May be 'Lineart'")
logger.warning("Unable to set scanner mode ! May be 'Lineart': {}".format(exc))
logger.exception(exc)

pyinsane2.maximize_scan_area(dev)
try:
pyinsane2.maximize_scan_area(dev)
except pyinsane2.PyinsaneException as exc:
logger.warning("Failed to maximize the scan area. May only scan part of the image: {}".format(exc))
logger.exception(exc)

scan_session = dev.scan(multiple=False)
scan_size = scan_session.scan.expected_size
Expand Down
26 changes: 18 additions & 8 deletions src/paperwork/frontend/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,13 @@ def _get_scanner(config, devid, preferred_sources=None):
pyinsane2.set_scanner_opt(dev, 'mode', ['Color'])
except pyinsane2.PyinsaneException as exc:
logger.warning("Failed to set scan mode: {}".format(exc))
logger.exception(exc)

pyinsane2.maximize_scan_area(dev)
try:
pyinsane2.maximize_scan_area(dev)
except pyinsane2.PyinsaneException as exc:
logger.warning("Failed to maximize scan area: {}".format(exc))
logger.exception(exc)
return (dev, resolution)


Expand All @@ -354,10 +359,15 @@ def get_scanner(config, preferred_sources=None):
logger.warning("Exception while configuring scanner: %s: %s"
% (type(exc), exc))
logger.exception(exc)
# we didn't find the scanner at the given ID
# but maybe there is only one, so we can guess the scanner to use
devices = [x for x in pyinsane2.get_devices() if x[:4] != "v4l:"]
if len(devices) != 1:
raise
logger.info("Will try another scanner id: %s" % devices[0].name)
return _get_scanner(config, devices[0].name, preferred_sources)
try:
# we didn't find the scanner at the given ID
# but maybe there is only one, so we can guess the scanner to use
devices = [x for x in pyinsane2.get_devices() if x.name[:4] != "v4l:"]
if len(devices) != 1:
raise
logger.info("Will try another scanner id: %s" % devices[0].name)
return _get_scanner(config, devices[0].name, preferred_sources)
except pyinsane2.PyinsaneException:
# this is a fallback mechanism, but what interrest us is the first exception,
# not the one from the fallback
raise exc

0 comments on commit 55b72fb

Please sign in to comment.