def _get_scanner_info(self): self.emit('scan-progression', self.STEP_SCANNER, 0.0) logger.info("====== START OF SCANNER INFO ======") devices = pyinsane2.get_devices() logger.info("{} scanners found".format(len(devices))) for device in pyinsane2.get_devices(): logger.info("=== {} ===".format(str(device))) for opt in device.options.values(): logger.info("Option: {}".format(opt.name)) logger.info(" Title: {}".format(opt.title)) logger.info(" Desc: {}".format(opt.desc)) logger.info(" Type: {}".format(str(opt.val_type))) logger.info(" Unit: {}".format(str(opt.unit))) logger.info(" Size: {}".format(opt.size)) logger.info(" Capabilities: {}".format( str(opt.capabilities)) ) logger.info(" Constraint type: {}".format( str(opt.constraint_type)) ) logger.info(" Constraint: {}".format(str(opt.constraint))) try: logger.info(" Value: {}".format(str(opt.value))) except pyinsane2.PyinsaneException 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 ... logger.warning(" Value: *FAILED*") logger.exception(exc) logger.info("====== END OF SCANNER INFORMATIONS ======")
def test_get_devices(self): devices = pyinsane2.get_devices() if len(devices) == 0: # if there are no devices found, create a virtual device. # see sane-test(5) and /etc/sane.d/test.conf pyinsane2.Scanner("test")._open() devices = pyinsane2.get_devices() self.assertTrue(len(devices) > 0)
def get_devices(): '''Return devices, perhaps after creating a test device.''' devices = pyinsane2.get_devices() if len(devices) == 0: # if there are no devices found, create a virtual device. # see sane-test(5) and /etc/sane.d/test.conf pyinsane2.Scanner("test").scan() devices = pyinsane2.get_devices() return devices
def scan_cards(): pyinsane2.init() devices = pyinsane2.get_devices() try: device = devices[0] print(f'PyInsane2 initiatied using {device.name}.') # device.options['AutoDocumentSize'] # Specify color scanning pyinsane2.set_scanner_opt(device, 'mode', ['24bit Color[Fast]']) # Set scan resolution pyinsane2.set_scanner_opt(device, 'resolution', [200]) pyinsane2.maximize_scan_area(device) try: pyinsane2.set_scanner_opt( device, 'source', ['Automatic Document Feeder(center aligned,Duplex)']) except pyinsane2.PyinsaneException as e: print('No document feeder found', e) try: scan_session = device.scan(multiple=True) print("Scanning ...") while True: try: scan_session.scan.read() except EOFError: print('scanning page') except StopIteration: im_list = scan_session.images pyinsane2.exit() return im_list except: pyinsane2.exit()
def run(self): temp_img_name = "1.png" temp_img_path = os.path.join(self.tempdir, temp_img_name) new_list = [] try: devices = pyinsane2.get_devices() if len(devices) <= 0: print("Scanning failed") self.scan_done.emit(None) return device = devices[0] print("Using scanner: %s" % (str(device))) pyinsane2.set_scanner_opt(device, "resolution", [300]) pyinsane2.set_scanner_opt(device, "mode", ["Color"]) pyinsane2.maximize_scan_area(device) # self.statusBar().showMessage("Scanning") scan_session = device.scan(multiple=False) try: while True: scan_session.scan.read() except EOFError: pass image = scan_session.images[-1] image.save(temp_img_path, "PNG") new_list.append(temp_img_path) self.scan_done.emit(new_list) finally: print("exiting")
def getImageFromScanner(): try: import pyinsane2 except: print "Scanning feature not supported on this OS. Disabling it..." pyinsane2.init() try: devices = pyinsane2.get_devices() assert (len(devices) > 0) device = devices[0] print("I'm going to use the following scanner: %s" % (str(device))) pyinsane2.set_scanner_opt(device, 'resolution', [75]) # Beware: Some scanners have "Lineart" or "Gray" as default mode # better set the mode everytime # Beware: by default, some scanners only scan part of the area # they could scan. pyinsane2.maximize_scan_area(device) scan_session = device.scan(multiple=False) try: while True: scan_session.scan.read() except EOFError: pass finally: image = scan_session.images[-1] return image finally: pyinsane2.exit() return None
def main(): import pyinsane2 pyinsane2.init() try: devices = pyinsane2.get_devices() assert(len(devices) > 0) device = devices[0] print("I'm going to use the following scanner: %s" % (str(device))) pyinsane2.set_scanner_opt(device, 'resolution', [300]) # Beware: Some scanners have "Lineart" or "Gray" as default mode # better set the mode everytime pyinsane2.set_scanner_opt(device, 'mode', ['Color']) # Beware: by default, some scanners only scan part of the area # they could scan. pyinsane2.maximize_scan_area(device) scan_session = device.scan(multiple=False) try: while True: scan_session.scan.read() except EOFError: pass image = scan_session.images[-1] image.save("output/"+str(datetime.datetime.now())+".png") finally: pyinsane2.exit()
def main(args): dstdir = args[0] devices = pyinsane2.get_devices() assert (len(devices) > 0) device = devices[0] print("Will use the scanner [%s](%s)" % (str(device), device.name)) pyinsane2.set_scanner_opt(device, "source", ["ADF", "Feeder"]) # Beware: Some scanner have "Lineart" or "Gray" as default mode pyinsane2.set_scanner_opt(device, "mode", ["Color"]) pyinsane2.set_scanner_opt(device, "resolution", [300]) pyinsane2.maximize_scan_area(device) # Note: If there is no page in the feeder, the behavior of device.scan() # is not guaranteed : It may raise StopIteration() immediately # or it may raise it when scan.read() is called try: scan_session = device.scan(multiple=True) 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(): devices = pyinsane2.get_devices() if (len(devices) <= 0): wx.MessageBox('Scanner device not found', 'Error', wx.OK | wx.ICON_WARNING) sys.exit(1) device = devices[0] #pyinsane2.set_scanner_opt(device, 'source', ['Auto', 'FlatBed']) pyinsane2.set_scanner_opt(device, 'resolution', [300]) try: pyinsane2.maximize_scan_area(device) except Exception as exc: print("Failed to maximize scan area: {}".format(exc)) pyinsane2.set_scanner_opt(device, 'mode', ['Color']) scan_session = device.scan(multiple=False) try: i = -1 while True: i += 1 i %= len(PROGRESSION_INDICATOR) sys.stdout.write("\b%s" % PROGRESSION_INDICATOR[i]) sys.stdout.flush() scan_session.scan.read() except EOFError: print("Scan compleated!") FOLDER = os.getcwd() FOLDER_SCAN = os.path.join(FOLDER, '..', 'ui') os.chdir(FOLDER_SCAN) img = scan_session.images[0] img.save("KharkivPy19.jpg", "JPEG") os.chdir(FOLDER)
def main(): device = selectDevice(pyinsane2.get_devices()) pyinsane2.maximize_scan_area(device) options = selectOptions(device.options.values()) applyOptions(device=device, options=options) print("will scan with following options:") for opt in device.options.values(): try: print(opt.name, opt.value) except pyinsane2.PyinsaneException as exc: pass filePath = selectFilePath() nameRoot = selectNameRoot() print("scanning will begin after you press <enter>") scan_count = 0 while True: _input = input("(<enter> or <q+enter>) ") if not _input: fileNumber = str(scan_count) fileNumber = "".join(['0'*(5-len(fileNumber)), fileNumber]) fileName = "".join([nameRoot, fileNumber, ".tif"]) print("Scanning ", fileName) image = scan(device) print("Done. Saving", fileName) saveImage(image, fileName, filePath) scan_count = scan_count + 1 continue if _input == "q": print("Exiting") break
def _get_scanner_info(self): self.emit('scan-progression', self.STEP_SCANNER, 0.0) logger.info("====== START OF SCANNER INFO ======") devices = pyinsane2.get_devices() logger.info("{} scanners found".format(len(devices))) for device in devices: logger.info("=== {} ===".format(str(device))) for opt in device.options.values(): logger.info("Option: {}".format(opt.name)) logger.info(" Title: {}".format(opt.title)) logger.info(" Desc: {}".format(opt.desc)) logger.info(" Type: {}".format(str(opt.val_type))) logger.info(" Unit: {}".format(str(opt.unit))) logger.info(" Size: {}".format(opt.size)) logger.info(" Capabilities: {}".format( str(opt.capabilities)) ) logger.info(" Constraint type: {}".format( str(opt.constraint_type)) ) logger.info(" Constraint: {}".format(str(opt.constraint))) try: logger.info(" Value: {}".format(str(opt.value))) except pyinsane2.PyinsaneException 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 ... logger.warning(" Value: *FAILED*") logger.exception(exc) logger.info("====== END OF SCANNER INFORMATIONS ======")
def main(args): dstdir = args[0] devices = pyinsane2.get_devices() assert(len(devices) > 0) device = devices[0] print("Will use the scanner [%s](%s)" % (str(device), device.name)) pyinsane2.set_scanner_opt(device, "source", ["ADF", "Feeder"]) # Beware: Some scanner have "Lineart" or "Gray" as default mode pyinsane2.set_scanner_opt(device, "mode", ["Color"]) pyinsane2.set_scanner_opt(device, "resolution", [300]) pyinsane2.maximize_scan_area(device) # Note: If there is no page in the feeder, the behavior of device.scan() # is not guaranteed : It may raise StopIteration() immediately # or it may raise it when scan.read() is called try: scan_session = device.scan(multiple=True) 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 scanthread(self): self.countread =0 pyinsane2.init() try: devices = pyinsane2.get_devices() if len(devices) > 0 : assert(len(devices) > 0) device = devices[0] GLib.idle_add(self.showprogressbar) pyinsane2.set_scanner_opt(device, 'resolution', [300]) # Beware: Some scanners have "Lineart" or "Gray" as default mode # better set the mode everytime pyinsane2.set_scanner_opt(device, 'mode', ['Color']) # Beware: by default, some scanners only scan part of the area # they could scan. pyinsane2.maximize_scan_area(device) scan_session = device.scan(multiple=False) try: while True: scan_session.scan.read() GLib.idle_add(self.updatescanprogress) except EOFError: pass scannedimage = scan_session.images[-1] GLib.idle_add(self.closescanprogress) jsonFile = open('conf.json', 'r') conf = json.load(jsonFile) ws_dir = conf["workspace_dir"] filename = ws_dir +"/" + str(datetime.datetime.now()) global imgloc imgloc = filename scannedimage.save(filename,"JPEG") jsonFile.close() textviewinitial = builder.get_object("outputtextview") textviewinitial.get_buffer().set_text('') img = builder.get_object("previmage") img.set_from_file(imgloc) global skewcorrected skewcorrected = 0 global zoomout zoomout = 1 else: GLib.idle_add(self.nodeviceconnected) finally: pyinsane2.exit()
def login(): pyinsane2.init() try: devices = pyinsane2.get_devices() assert (len(devices) > 0) device = devices[0] print("I'm going to use the following scanner: %s" % (str(device))) scanner_id = device.name finally: pyinsane2.exit()
def check_scanner_alive(cls): pyinsane2.init() try: devices = pyinsane2.get_devices() device = None if devices: device = devices[0] return str(device) else: return "No device" finally: pyinsane2.exit()
def get_scanner(config, preferred_sources=None): devid = config['scanner_devid'].value try: return _get_scanner(config, devid, preferred_sources) except (KeyError, pyinsane2.PyinsaneException) as exc: logger.warning("Exception while configuring scanner: %s: %s" % (type(exc), 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)
def do(self): self.emit("device-finding-start") self._wait(2.0) try: logger.info("Looking for scan devices ...") sys.stdout.flush() devices = pyinsane2.get_devices() for device in devices: selected = (self.__selected_devid == device.name) name = self.__get_dev_name(device) logger.info("Device found: [%s] -> [%s]" % (name, device.name)) sys.stdout.flush() self.emit('device-found', name, device.name, selected) logger.info("End of scan for device") finally: self.emit("device-finding-end")
def do(self): self.emit("device-finding-start") self._wait(2.0) try: logger.info("Looking for scan devices ...") sys.stdout.flush() devices = pyinsane2.get_devices() for device in devices: selected = (self.__selected_devid == device.name) name = self.__get_dev_name(device) logger.info("Device found: [%s] -> [%s]" % (name, device.name)) sys.stdout.flush() self.emit('device-found', name, device.name, selected) logger.info("End of scan for device") finally: self.emit("device-finding-end")
def main(): parser = argparse.ArgumentParser() parser.add_argument("-o", "--output_name", default="scansione.jpg", help="string to search into") parser.add_argument("-r", "--resolution", default="150", help="string to search into") args = parser.parse_args() output_name = args.output_name resolution = args.resolution pyinsane2.init() try: devices = pyinsane2.get_devices() assert (len(devices) > 0) device = devices[0] print("I'm going to use the following scanner: %s" % (str(device))) pyinsane2.set_scanner_opt(device, 'resolution', [int(resolution)]) # Beware: Some scanners have "Lineart" or "Gray" as default mode # better set the mode everytime # pyinsane2.set_scanner_opt(device, 'mode', 'Gray') # Beware: by default, some scanners only scan part of the area # they could scan. pyinsane2.maximize_scan_area(device) scan_session = device.scan(multiple=False) try: while True: scan_session.scan.read() except EOFError: pass image = scan_session.images[-1] image.save(output_name, "JPEG") print("Done") finally: pyinsane2.exit()
def main(): import pyinsane2 pyinsane2.init() try: devices = pyinsane2.get_devices() assert (len(devices) > 0) device = devices[0] print("I'm going to use the following scanner: %s" % (str(device))) try: pyinsane2.set_scanner_opt(device, 'source', ['ADF', 'Feeder']) except PyinsaneException: print("No document feeder found") return # Beware: Some scanners have "Lineart" or "Gray" as default mode # better set the mode everytime pyinsane2.set_scanner_opt(device, 'mode', ['Color']) # Beware: by default, some scanners only scan part of the area # they could scan. pyinsane2.maximize_scan_area(device) scan_session = device.scan(multiple=True) try: while True: try: scan_session.scan.read() except EOFError: print("Got a page ! (current number of pages read: %d)" % (len(scan_session.images))) except StopIteration: print("Document feeder is now empty. Got %d pages" % len(scan_session.images)) for idx in range(0, len(scan_session.images)): image = scan_session.images[idx] image.save("output/" + str(datetime.datetime.now()) + ".png") finally: pyinsane2.exit()
def get_scanner(config, preferred_sources=None): devid = config['scanner_devid'].value try: return _get_scanner(config, devid, preferred_sources) except (KeyError, pyinsane2.PyinsaneException) as exc: logger.warning("Exception while configuring scanner: %s: %s" % (type(exc), exc)) logger.exception(exc) 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 interest us is the first # exception, not the one from the fallback raise exc
def setup_device(device_name=None, resolution=300, mode="Gray"): pyinsane2.init() if device_name is not None: device = pyinsane2.Scanner(name="brother4:net1;dev0") else: devices = pyinsane2.get_devices() print("Scanners found:") for i, d in enumerate(devices): print(f"[{i}] {d}") device = devices[int(input("Select which one to use: "))] print(f"Will use: {device}") pyinsane2.set_scanner_opt(device, "source", ["Auto", "FlatBed"]) pyinsane2.set_scanner_opt(device, "resolution", [resolution]) try: pyinsane2.maximize_scan_area(device) except Exception as exc: print(f"Failed to maximize scan area: {exc}") pyinsane2.set_scanner_opt(device, "mode", [mode]) return device
def main(): parser = argparse.ArgumentParser() parser.add_argument("-o", "--output_name", default="scansione.jpg", help="string to search into") parser.add_argument("-r", "--resolution", default="150", help="string to search into") args = parser.parse_args() output_name=args.output_name resolution=args.resolution pyinsane2.init() try: devices = pyinsane2.get_devices() assert(len(devices) > 0) device = devices[0] print("I'm going to use the following scanner: %s" % (str(device))) pyinsane2.set_scanner_opt(device, 'resolution', [int(resolution)]) # Beware: Some scanners have "Lineart" or "Gray" as default mode # better set the mode everytime # pyinsane2.set_scanner_opt(device, 'mode', 'Gray') # Beware: by default, some scanners only scan part of the area # they could scan. pyinsane2.maximize_scan_area(device) scan_session = device.scan(multiple=False) try: while True: scan_session.scan.read() except EOFError: pass image = scan_session.images[-1] image.save(output_name, "JPEG") print("Done") finally: pyinsane2.exit()
def scan_document(self, filename): """ Scan a new document and save it as 'filename' possible resolutions are : 75, 100, 200, 300, 600, 1200 """ pyinsane2.init() try: devices = pyinsane2.get_devices() device = None if devices: device = devices[0] print("I'm going to use the following scanner: %s" % (str(device))) pyinsane2.set_scanner_opt(device, 'resolution', [75]) else: print( "Check if scanner is online, and you have the correct WIFI connection!" ) # Scan in color mode pyinsane2.set_scanner_opt(device, 'mode', ['Color']) pyinsane2.maximize_scan_area(device) scan_session = device.scan(multiple=False) try: print("Initiating Scan operation") while True: scan_session.scan.read() except EOFError: pass image = scan_session.images[-1] print("Saving image") image.save(filename) finally: pyinsane2.exit()
def get_scanner(config, preferred_sources=None): devid = config['scanner_devid'].value try: return _get_scanner(config, devid, preferred_sources) except (KeyError, pyinsane2.PyinsaneException) as exc: logger.warning("Exception while configuring scanner: %s: %s" % (type(exc), exc)) logger.exception(exc) 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 interest us is the first # exception, not the one from the fallback raise exc
def main(): steps = False args = sys.argv[1:] if len(args) <= 0 or args[0] == "-h" or args[0] == "--help": print("Syntax:") print(" %s [-s] <output file (JPG)>" % sys.argv[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 = pyinsane2.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("") # For the possible resolutions, look at # device.options['resolution'].constraint # It will either be: # - None: unknown # - a tuple: (min resolution, max resolution) # - a list: [75, 150, 300, 600, 1200, ...] pyinsane2.set_scanner_opt(device, 'source', ['Auto', 'FlatBed']) pyinsane2.set_scanner_opt(device, 'resolution', [300]) try: pyinsane2.maximize_scan_area(device) except Exception as exc: print("Failed to maximize scan area: {}".format(exc)) # Beware: Some scanner have "Lineart" or "Gray" as default mode pyinsane2.set_scanner_opt(device, 'mode', ['Color']) print("") print("Scanning ... ") scan_session = device.scan(multiple=False) if steps and scan_session.scan.expected_size[1] < 0: print("Warning: requested step by step scan images, but" " scanner didn't report the expected number of lines" " in the final image --> can't do") print("Step by step scan images won't be recorded") steps = False if steps: last_line = 0 expected_size = scan_session.scan.expected_size img = Image.new("RGB", expected_size, "#ff00ff") sp = output_file.split(".") steps_filename = (".".join(sp[:-1]), sp[-1]) try: PROGRESSION_INDICATOR = ['|', '/', '-', '\\'] i = -1 while True: i += 1 i %= len(PROGRESSION_INDICATOR) sys.stdout.write("\b%s" % PROGRESSION_INDICATOR[i]) sys.stdout.flush() scan_session.scan.read() if steps: next_line = scan_session.scan.available_lines[1] if (next_line > last_line + 100): subimg = scan_session.scan.get_image(last_line, next_line) img.paste(subimg, (0, last_line)) img.save("%s-%05d.%s" % (steps_filename[0], last_line, steps_filename[1]), "JPEG") last_line = next_line except EOFError: pass print("\b ") print("Writing output file ...") img = scan_session.images[0] img.save(output_file, "JPEG") print("Done")
def setUp(self): pyinsane2.init() devices = pyinsane2.get_devices() self.assertTrue(len(devices) > 0) self.dev = devices[0]
def sane(sanevariables, resolution=100, mode="Color", multiple=False ): # 先查看iventory文件夹是否存在 inventory = createPageDir(InventoryPath) try: pyinsane2.init() devices = pyinsane2.get_devices() print(devices) if len(devices) > 0 : device = devices[0] print('I am going to use the following scanner: %s' %(str(device))) scanner_id = device.name try: pyinsane2.set_scan_area_pos(device, 'source', ['ADF', 'Feeder']) except Exception as e: print(e) # pyinsane2.set_scanner_opt(device, 'resolution', [resolution]) # pyinsane2.set_scanner_opt(device, 'mode', [mode]) # pyinsane2.maximize_scan_area(device) # try : # scan_session = device.scan(multiple=multiple) # print('scanning--------------------') # while True: # try: # scan_session.scan.read() # except EOFError: # print("Got page %d" % (len(scan_session.images))) # img = scan_session.images[-1] # SaneTime = str(int(time.time())) # # 以时间戳的形式存储扫描结果为 "时间戳.jpg" # SanPathName = createPagePath(inventory, SaneTime+'.jpg') # # imgpath = os.path.join('test111.jpg') # img.save(SanPathName) # # 将扫描出来的多余大片白色区域去掉 # reshapeImg = origin_reshape.reshape(SanPathName, sanevariables) # # 寻找学号填写的格子,来判断是否是可以解析的扫描结果 # # studentFrames.dectionStudentIDFrame(reshapeImg, ) # # 判断是否是上下颠倒的图片 # # upsideDown = origin_reshape.upsideDown() # cv2.imwrite(SanPathName, reshapeImg) # except StopIteration: # print("Got %d pages" % len(scan_session.images)) # else: # print('没有找到打印机') except EOFError as err: # print(err) print('f**k') finally: print(1111)
#!/usr/bin/env python3 import pyinsane2 if __name__ == "__main__": pyinsane2.init() try: for device in pyinsane2.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 pyinsane2.PyinsaneException 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("") finally: pyinsane2.exit()
# ## Scanner and board detection # In[7]: ## Detecting Boards Availible_boards = [ i.split(".")[0] for i in os.listdir('./boards/') if '.board' in i ] if len(Availible_boards) == 0: Availible_boards = ['There are no boards available'] ## Detecting scanners pyinsane2.init() Devices = pyinsane2.get_devices() if len(Devices) > 1: Scanner_dict = { dev[1].nice_name + ' -- ' + dev[1].options['dev_id'].value.split('\\')[1]: dev[0] for dev in enumerate(Devices) } elif len(Devices) == 0: Scanner_dict = {'Error: No detected Scanners': 0} else: Scanner_dict = { Devices[0].nice_name + ' -- ' + Devices[0].options['dev_id'].value.split('\\')[1]: 0 } List_of_Scanners = list(Scanner_dict.keys())
def setUp(self): # to speed up the scanner search during tests, we do one right now pyinsane2.get_devices() self.pw = paperwork.PaperworkInstance()
def com_hardware_scanner_find(self): return pyinsane2.get_devices()
#!/usr/bin/env python3 import pyinsane2 if __name__ == "__main__": pyinsane2.init() try: for device in pyinsane2.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 pyinsane2.PyinsaneException 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("") finally: