コード例 #1
0
        else:
            if dev.options['source'].capabilities.is_active():
                dev.options['source'].value = config_source
            logger.info("Will scan using source %s" % str(config_source))

    if 'resolution' not in dev.options:
        logger.warning("Can't set the resolution on this scanner."
                       " Option not found")
    else:
        try:
            dev.options['resolution'].value = resolution
        except pyinsane.SaneException:
            logger.warning("Unable to set scanner resolution to %d: %s" %
                           (resolution, exc))

    if 'mode' not in dev.options:
        logger.warning("Can't set the mode on this scanner. Option not found")
    else:
        if dev.options['mode'].capabilities.is_active():
            if "Color" in dev.options['mode'].constraint:
                dev.options['mode'].value = "Color"
                logger.info("Scanner mode set to 'Color'")
            elif "Gray" in dev.options['mode'].constraint:
                dev.options['mode'].value = "Gray"
                logger.info("Scanner mode set to 'Gray'")
            else:
                logger.warning("Unable to set scanner mode ! May be 'Lineart'")

    maximize_scan_area(dev)
    return (dev, resolution)
コード例 #2
0
    def do(self):
        self.can_run = True
        self.emit('calibration-scan-start')

        # find the best resolution : the default calibration resolution
        # is not always available
        resolutions = [x[1] for x in self.__resolutions_store]
        resolutions.sort()

        resolution = DEFAULT_CALIBRATION_RESOLUTION
        for nresolution in resolutions:
            if nresolution > DEFAULT_CALIBRATION_RESOLUTION:
                break
            resolution = nresolution

        logger.info("Will do the calibration scan with a resolution of %d"
                    % resolution)

        # scan
        dev = pyinsane.Scanner(name=self.__devid)
        if dev.options['source'].capabilities.is_active():
            dev.options['source'].value = self.__source
        logger.info("Scanner source set to '%s'" % self.__source)
        try:
            dev.options['resolution'].value = resolution
        except pyinsane.SaneException as exc:
            logger.warning("Unable to set scanner resolution to %d: %s"
                           % (resolution, exc))
        if dev.options['mode'].capabilities.is_active():
            if "Color" in dev.options['mode'].constraint:
                dev.options['mode'].value = "Color"
                logger.info("Scanner mode set to 'Color'")
            elif "Gray" in dev.options['mode'].constraint:
                dev.options['mode'].value = "Gray"
                logger.info("Scanner mode set to 'Gray'")
            else:
                logger.warning("Unable to set scanner mode ! May be 'Lineart'")
        maximize_scan_area(dev)

        scan_session = dev.scan(multiple=False)
        scan_size = scan_session.scan.expected_size
        self.emit('calibration-scan-info', scan_size[0], scan_size[1])

        last_line = 0
        try:
            while self.can_run:
                scan_session.scan.read()

                next_line = scan_session.scan.available_lines[1]
                if (next_line > last_line):
                    chunk = scan_session.scan.get_image(last_line, next_line)
                    self.emit('calibration-scan-chunk', last_line, chunk)
                    last_line = next_line

                time.sleep(0)  # Give some CPU time to PyGtk
            if not self.can_run:
                self.emit('calibration-scan-canceled')
                scan_session.scan.cancel()
        except EOFError:
            pass

        img = scan_session.get_img()
        self.emit('calibration-scan-done', img, resolution)
コード例 #3
0
def _get_scanner(config, devid, preferred_sources=None):
    logger.info("Will scan using %s" % str(devid))
    resolution = config['scanner_resolution'].value
    logger.info("Will scan at a resolution of %d" % resolution)

    dev = pyinsane.Scanner(name=devid)

    config_source = config['scanner_source'].value
    use_config_source = False

    if 'source' not in dev.options:
        logger.warning(
            "Can't set the source on this scanner. Option not found")
    else:
        if preferred_sources:
            use_config_source = False
            regexs = [
                re.compile(x, flags=re.IGNORECASE) for x in preferred_sources
            ]
            for regex in regexs:
                if regex.match(config_source):
                    use_config_source = True
                    break

        if not use_config_source and preferred_sources:
            try:
                set_scanner_opt('source', dev.options['source'],
                                preferred_sources)
            except (KeyError, pyinsane.SaneException) as exc:
                config_source = config['scanner_source'].value
                logger.error(
                    "Warning: Unable to set scanner source to '%s': %s" %
                    (preferred_sources, exc))
                if dev.options['source'].capabilities.is_active():
                    dev.options['source'].value = config_source
        else:
            if dev.options['source'].capabilities.is_active():
                dev.options['source'].value = config_source
            logger.info("Will scan using source %s" % str(config_source))

    if 'resolution' not in dev.options:
        logger.warning("Can't set the resolution on this scanner."
                       " Option not found")
    else:
        try:
            dev.options['resolution'].value = resolution
        except pyinsane.SaneException:
            logger.warning("Unable to set scanner resolution to %d: %s" %
                           (resolution, exc))

    if 'mode' not in dev.options:
        logger.warning("Can't set the mode on this scanner. Option not found")
    else:
        if dev.options['mode'].capabilities.is_active():
            if "Color" in dev.options['mode'].constraint:
                dev.options['mode'].value = "Color"
                logger.info("Scanner mode set to 'Color'")
            elif "24bit Color" in dev.options['mode'].constraint:
                # Brother MVC-J410 support ... (@$*#@#!!)
                dev.options['mode'].value = "24bit Color"
                logger.info("Scanner mode set to '24bit Color'")
            elif "Gray" in dev.options['mode'].constraint:
                dev.options['mode'].value = "Gray"
                logger.info("Scanner mode set to 'Gray'")
            else:
                logger.warning("Unable to set scanner mode ! May be 'Lineart'")

    maximize_scan_area(dev)
    return (dev, resolution)