Example #1
0
def main(args):
    dstdir = args[0]

    devices = pyinsane.get_devices()
    assert (len(devices) > 0)
    device = devices[0]

    print("Will use the scanner [%s](%s)" % (str(device), device.name))

    possible_srcs = device.options['source'].constraint
    adf_src = None
    for src in possible_srcs:
        if "ADF" in src or "Feeder" in src:
            adf_src = src
            break

    if adf_src is None:
        print("No document feeder found")
        sys.exit(1)

    print("Will use the source [%s]" % adf_src)

    device.options['source'].value = "ADF"
    # Beware: Some scanner have "Lineart" or "Gray" as default mode
    device.options['mode'].value = 'Color'
    scan_session = device.scan(multiple=True)

    try:
        print("Scanning ...")
        while True:
            try:
                scan_session.scan.read()
            except EOFError:
                print("Got page %d" % (len(scan_session.images)))
                img = scan_session.images[-1]
                imgpath = os.path.join(dstdir,
                                       "%d.jpg" % (len(scan_session.images)))
                img.save(imgpath)
    except StopIteration:
        print("Got %d pages" % len(scan_session.images))
Example #2
0
def main(args):
    dstdir = args[0]

    devices = pyinsane.get_devices()
    assert len(devices) > 0
    device = devices[0]

    print("Will use the scanner [%s]" % (str(device)))
    scanner_id = device.name

    possible_srcs = device.options["source"].constraint
    adf_src = None
    for src in possible_srcs:
        if "ADF" in src or "Feeder" in src:
            adf_src = src
            break

    if adf_src is None:
        print("No document feeder found")
        sys.exit(1)

    print("Will use the source [%s]" % adf_src)

    device.options["source"].value = "ADF"
    # Beware: Some scanner have "Lineart" or "Gray" as default mode
    device.options["mode"].value = "Color"
    scan_session = device.scan(multiple=True)

    try:
        print("Scanning ...")
        while True:
            try:
                scan_session.scan.read()
            except EOFError:
                print("Got page %d" % (len(scan_session.images)))
                img = scan_session.images[-1]
                imgpath = os.path.join(dstdir, "%d.jpg" % (len(scan_session.images)))
                img.save(imgpath)
    except StopIteration:
        print("Got %d pages" % len(scan_session.images))
Example #3
0
#!/usr/bin/env python

import sys

import src.abstract as pyinsane

if __name__ == "__main__":
    for device in pyinsane.get_devices():
        print("%s" % (str(device)))

        for opt in device.options.values():
            print("  Option: %s" % (opt.name))
            print("    Title: %s" % (opt.title))
            print("    Desc: %s" % (opt.desc))
            print("    Type: %s" % (str(opt.val_type)))
            print("    Unit: %s" % (str(opt.unit)))
            print("    Size: %d" % (opt.size))
            print("    Capabilities: %s" % (str(opt.capabilities)))
            print("    Constraint type: %s" % (str(opt.constraint_type)))
            print("    Constraint: %s" % (str(opt.constraint)))
            try:
                print("    Value: %s" % (str(opt.value)))
            except pyinsane.SaneException as exc:
                # Some scanner allow changing a value, but not reading it.
                # For instance Canon Lide 110 allow setting the resolution,
                # but not reading it
                print("    Value: Failed to get the value: %s" % str(exc))

        print("")
Example #4
0
        print("")
        print("Options:")
        print("  -s : Generate intermediate images (may generate a lot of"
              " images !)")
        sys.exit(1)

    for arg in args[:]:
        if arg == "-s":
            steps = True
            args.remove(arg)

    output_file = args[0]
    print("Output file: %s" % output_file)

    print("Looking for scanners ...")
    devices = pyinsane.get_devices()
    if (len(devices) <= 0):
        print("No scanner detected !")
        sys.exit(1)
    print("Devices detected:")
    print("- " + "\n- ".join([str(d) for d in devices]))

    print("")

    device = devices[0]
    print("Will use: %s" % str(device))

    print("")

    source = 'Auto'
    # beware: don't select a source that is not in the constraint,
Example #5
0
        print("")
        print("Options:")
        print("  -s : Generate intermediate images (may generate a lot of"
              " images !)")
        sys.exit(1)

    for arg in args[:]:
        if arg == "-s":
            steps = True
            args.remove(arg)

    output_file = args[0]
    print("Output file: %s" % output_file)

    print("Looking for scanners ...")
    devices = pyinsane.get_devices()
    if (len(devices) <= 0):
        print("No scanner detected !")
        sys.exit(1)
    print("Devices detected:")
    print("- " + "\n- ".join([str(d) for d in devices]))

    print("")

    device = devices[0]
    print("Will use: %s" % str(device))

    print("")

    source = 'Auto'
    # beware: don't select a source that is not in the constraint,
Example #6
0
        scanner.options[opt].value = value
    except rawapi.SaneException, exc:
        print "Failed to set %s to %s: %s" % (opt, str(value), str(exc))


if __name__ == "__main__":
    if len(sys.argv) <= 1:
        print "Syntax:"
        print "  %s <output file (JPG)>" % sys.argv[0]
        sys.exit(1)

    output_file = sys.argv[1]
    print "Output file: %s" % output_file

    print "Looking for scanners ..."
    devices = abstract.get_devices()
    if (len(devices) <= 0):
        print "No scanner detected !"
        sys.exit(1)
    print "Devices detected:"
    print "- " + "\n- ".join([str(d) for d in devices])

    print ""

    device = devices[0]
    print "Will use: %s" % str(device)

    print ""

    set_scanner_opt(device, 'resolution', 300)
    set_scanner_opt(device, 'source', 'Auto')
Example #7
0
#!/usr/bin/env python

try:
    import src.abstract as pyinsane
except ImportError:
    import pyinsane.abstract as pyinsane

if __name__ == "__main__":
    for device in pyinsane.get_devices():
        print("%s" % (str(device)))

        for opt in device.options.values():
            print("  Option: %s" % (opt.name))
            print("    Title: %s" % (opt.title))
            print("    Desc: %s" % (opt.desc))
            print("    Type: %s" % (str(opt.val_type)))
            print("    Unit: %s" % (str(opt.unit)))
            print("    Size: %d" % (opt.size))
            print("    Capabilities: %s" % (str(opt.capabilities)))
            print("    Constraint type: %s" % (str(opt.constraint_type)))
            print("    Constraint: %s" % (str(opt.constraint)))
            try:
                print("    Value: %s" % (str(opt.value)))
            except pyinsane.SaneException as exc:
                # Some scanner allow changing a value, but not reading it.
                # For instance Canon Lide 110 allow setting the resolution,
                # but not reading it
                print("    Value: Failed to get the value: %s" % str(exc))

        print("")