Exemple #1
0
def scan():
    resolution = request.args.get('resolution', '')
    print 'resolution: {}'.format(resolution)
    devices = pyinsane.get_devices()
    assert(len(devices) > 0)
    device = devices[0]
    if resolution and resolution in ['75', '150', '300', '600', '1200', '2400']:
        device.options['resolution'].value = int(resolution)
    print device.options['resolution'].value
    print device.name
    # for option in device.options:
    #     try:
    #         print option, device.options[option].value
    #     except:
    #         print option
    scan_session = device.scan(multiple=False)
    try:
        while True:
            print '.'
            scan_session.scan.read()
    except EOFError:
        pass
    print 'scan done'

    image = scan_session.images[0]
    tmp_file = NamedTemporaryFile(delete=False)
    image.save(tmp_file.name, "JPEG")
    image_id = tmp_file.name.rpartition('/')[-1]
    images.append({'id': image_id, 'path': tmp_file.name})
    return image_id, 200
Exemple #2
0
def get_devices(local_only):
    global device_cache

    devices = pyinsane.get_devices(local_only)
    device_cache = {}
    for device in devices:
        device_cache[device.name] = device
    return devices
Exemple #3
0
def setup_scanner(options):
    devices = pyinsane.get_devices()
    if len(devices) <= 0:
        print('no scanner available')
        return None
    device = devices[0]
    print("I'm going to use the following scanner: %s" % (str(device)))
    device = set_device_options(options, device)
    return device
	def __init__(self):
		self.context = zmq.Context()
		self.pull = self.context.socket(zmq.PULL)
		self.pull.bind("tcp://*:8890")
		self.pub = self.context.socket(zmq.PUB)
		self.pub.bind("tcp://*:8891")
		self.loop = ioloop.IOLoop.instance()
		self.stream = zmqstream.ZMQStream(self.pull)
		self.stream.on_recv(self.handle_msg)
		self.device = pyinsane.get_devices()[0]
Exemple #5
0
 def __init__(self):
     self.context = zmq.Context()
     self.pull = self.context.socket(zmq.PULL)
     self.pull.bind("tcp://*:8890")
     self.pub = self.context.socket(zmq.PUB)
     self.pub.bind("tcp://*:8891")
     self.loop = ioloop.IOLoop.instance()
     self.stream = zmqstream.ZMQStream(self.pull)
     self.stream.on_recv(self.handle_msg)
     self.device = pyinsane.get_devices()[0]
    def __init__(self, deviceint):

        devices = pyinsane.get_devices()
        while len(devices) <= 0:
            print "Can not find scanner, retrying in 10 seconds"
            sleep(10)
            devices = pyinsane.get_devices()

        self.device = devices[deviceint]

        print "Using scanner: %s" % str(self.device.model)
        print "Address: %s" % str(self.device.name)

        self.device.options['resolution'].value = 75
        self.device.options['mode'].value = 'Color'
        if 'preview' in self.device.options.keys(): self.device.options['preview'].value = True

        self.subimg = Image.new("RGB", (1, 1), "#F00")

        self.is_scanning = False
def main_list_devices(cmdline):
    try:
        devices = pyinsane.get_devices()
    except Exception as ex:
        raise Error('Unable to list devices. Is sane installed?', inner=ex)

    if len(devices) == 0:
        raise Error('no devices found')

    for device in devices:
        print(device.name)
    def __init__(self, deviceint):

        devices = pyinsane.get_devices()
        while len(devices) <= 0:
            print "Can not find scanner, retrying in 10 seconds"
            sleep(10)
            devices = pyinsane.get_devices()

        self.device = devices[deviceint]

        print "Using scanner: %s" % str(self.device.model)
        print "Address: %s" % str(self.device.name)

        self.device.options['resolution'].value = 75
        self.device.options['mode'].value = 'Color'
        if 'preview' in self.device.options.keys():
            self.device.options['preview'].value = True

        self.subimg = Image.new("RGB", (1, 1), "#F00")

        self.is_scanning = False
def list_devices():

    devices = {}

    for device in pyinsane.get_devices():
        devices[str(device)] = {}
        d = devices[str(device)]

        for opt in device.options.values():
            d[opt.name] = opt.constraint

    if len(devices) == 0:
        return make_response(jsonify({'error': 'No devices found'}), 200)

    return jsonify(**devices)
Exemple #10
0
 def getDevices(self):
     """
     Obtain deviceList and update the Gui with its contents.
     """
     
     self.deviceList = pyinsane.get_devices()
     try:
         # Presume we obtained at least one device
         assert len(self.deviceList) > 0
         for device in self.deviceList:
             self.deviceDict[device.name] = device
     except AssertionError:
         # Presumption was wrong; there are no 
         # devices in self.deviceList
         self.deviceList = []
     
     # Update Gui
     self.m_interface.updateDevices()
Exemple #11
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))
def scan_view():

    if request.method == 'POST':
        resolution = int(request.form['resolution'])
        format = request.form['format']
        mode = request.form['mode']
        device_choice = request.form['device']

        devices = pyinsane.get_devices()
        # I hate the way pyinsane returns available devices - this sadly worked the best for what I needed
        scanner = [device for device in devices if device.name in device_choice][0]

        image, log = perform_scan(scanner, resolution=resolution, mode=mode)

        temp_filename = temp_name_dir_handler(format)

        if image:
            image.save(temp_dir + temp_filename, quality=100)
            return render_template('scan.html', image=temp_filename, format=format)

        else:
            flash(log)
            return redirect(url_for('index'))
Exemple #13
0
def main():
    json.dump({'devices': map(make, get_devices())}, sys.stdout)
import tempfile
from PIL import Image
import os
import sys

if len(sys.argv) == 1:
  sessionName = raw_input("What filename will you give this session? [foo.png] ")
else:
  sessionName = sys.argv[1]

if sessionName == '':
  sessionName = 'foo.png'

pageNum = 0

devices = pyinsane.get_devices()

device = pyinsane.Scanner(name=devices[1].name)

dpi = 300
imgWidth = int(dpi * 8.5)
imgHeight = int(dpi * 11)
device.options['resolution'].value = dpi
device.options['mode'].value = 'Gray'

while True:
  session = device.scan(multiple=False)

  try:
    while True:
      session.scan.read()
Exemple #15
0
def find_devices():
    devices = pyinsane.get_devices()
    return devices
Exemple #16
0
def find_devices():
    devices = pyinsane.get_devices()
    return devices