Open Dhruv00710 opened 11 months ago
This error means that source does not support file transfer, therefore you need to use native transfer instead via acquire_natively
function.
sir i write this function and i scan more then one document
def scan(self):
parent_window_handle = int(self.winId())
self.logger.info('Creating source manager')
try:
def counter():
for i in range(1000):
yield i
count = counter()
# before = lambda file: 'd:/%s.jpg' % (next(count))
after = lambda file: 'd:/%s.jpg' % (next(count))
sm = twain.SourceManager(parent_window=parent_window_handle)
first_available = None
# with twain.SourceManager(parent_window=parent_window_handle) as sm:
self.logger.info('Opening source')
ss = sm.open_source(scanner)
if not ss:
self.logger.error('Failed to open a scanner source')
return None
self.logger.info('Request acquire')
ss.acquire_natively(before=lambda file: print(file),
after=after,
show_ui=True,
modal=True,
)
except Exception as e: self.logger.error(f'Error: {str(e)}') but i got error like Exception ignored in: <function _Image.del at 0x0362A848> Traceback (most recent call last): File "C:\Users\DELL\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\twain__init.py", line 112, in del self.close() File "C:\Users\DELL\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\twain\init__.py", line 116, in close self._free(self._handle) ^^^^^^^^^^ AttributeError: '_Image' object has no attribute '_free'
sir in above code if any changes then please tell me.
That is a bug in pytwain. You can try fixing it. First you need to add close, lock, unlock parameters to _Image class constructor and save them in _close, _lock, _unlock attributes https://github.com/denisenkom/pytwain/blob/4ce4712a3af35e056370bb97ce6cd1763dde18b2/src/twain/__init__.py#L128. Then change code that creates _Image instance here https://github.com/denisenkom/pytwain/blob/4ce4712a3af35e056370bb97ce6cd1763dde18b2/src/twain/__init__.py#L907 to pass values of respective _close, _lock, _unlock attributes of the Source class to _Image constructor. That should fix the error that you are getting. If that works please open a pull request.
sir i tried as you say above. but i not success. if you try and success then please tell me.
I made a fix https://github.com/denisenkom/pytwain/commit/6eb7c5861c10159d6424d53f1ff2be4159d2ca5e, it should fix the below error:
AttributeError: '_Image' object has no attribute '_free'
Try it.
i upgrade pytwain version 2.2.2 and my code is below
def scans(self): parent_window_handle = int(self.winId()) self.logger.info('Creating source manager') try: def counter(): for i in range(1000): yield i+1 count = counter() before = lambda file: 'd:/omr/output/multi%s.jpg' % (next(count)) sm = twain.SourceManager(parent_window=parent_window_handle) self.logger.info('Opening source') ss = sm.open_source(scanner) if not ss: self.logger.error('Failed to open a scanner source') return None self.logger.info('Request acquire') result = ss.acquire_natively(before=before, after=lambda file: print(file), show_ui=True, modal=True ) ss.close()
except Exception as e:
self.logger.error(f'Error: {str(e)}')
using above code i got also error Exception ignored in: <function _Image.del at 0x03C5AA28> Traceback (most recent call last): File "C:\Users\DELL\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\twain__init.py", line 114, in del self.close() File "C:\Users\DELL\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\twain\init.py", line 118, in close self._free(self._handle) ^^^^^^^^^^ AttributeError: '_Image' object has no attribute '_free' ERROR:main__:Error: name 'CancelAll' is not defined
res. sir below is my code and also show "SELECT SOURCE" but when i press scan button its get error like