Compare commits

..

No commits in common. "c86630230a41f6c3f96d9a6f2e1c4164ea8ec749" and "df8c4042c4d23d7f755dd911bc081b854b7d7b44" have entirely different histories.

2 changed files with 23 additions and 20 deletions

View File

@ -1 +0,0 @@
Piotr Chmura

38
xsanecli.py Normal file → Executable file
View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# GIMP 3.0 plug-in for scanning via XSane # GIMP 3.0 plug-in for scanning via XSane
# Copyright (C) 2024-2025 Lee Yingtong Li (RunasSudo) and CONTRIBUTORS # Copyright (C) 2024-2025 Lee Yingtong Li (RunasSudo)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -52,25 +52,29 @@ def xsanecli_run(procedure, config, run_data, *args):
args = ['xsane', '--save', '--no-mode-selection', '--force-filename', png_out, '--print-filenames'] + ([DEVICE_NAME] if DEVICE_NAME else []) args = ['xsane', '--save', '--no-mode-selection', '--force-filename', png_out, '--print-filenames'] + ([DEVICE_NAME] if DEVICE_NAME else [])
proc = subprocess.Popen(args, stdout=subprocess.PIPE, encoding='utf-8', env=xsane_env) proc = subprocess.Popen(args, stdout=subprocess.PIPE, encoding='utf-8', env=xsane_env)
while proc.poll() is None: while True:
# Wait until XSane prints the name of the scanned file, indicating scanning is finished # Wait until XSane prints the name of the scanned file, indicating scanning is finished
# This blocks Python but that is ok because GIMP UI is not affected # This blocks Python but that is ok because GIMP UI is not affected
try: result = proc.stdout.readline().strip()
result = proc.stdout.readline().strip()
except UnicodeDecodeError as e:
result = ''
if result == 'XSANE_IMAGE_FILENAME: ' + png_out: if result == '':
# Open image # XSane was closed
image = Gimp.file_load(Gimp.RunMode.NONINTERACTIVE, Gio.File.new_for_path(png_out)) break
Gimp.Display.new(image)
# Remove temporary files if result != 'XSANE_IMAGE_FILENAME: ' + png_out:
os.unlink(png_out) Gimp.message('Unexpected XSane result')
return Gimp.ValueArray.new_from_values([GObject.Value(Gimp.PDBStatusType, Gimp.PDBStatusType.EXECUTION_ERROR)])
if not SCAN_MULTIPLE: # Open image
proc.terminate() image = Gimp.file_load(Gimp.RunMode.NONINTERACTIVE, Gio.File.new_for_path(png_out))
Gimp.Display.new(image)
# Remove temporary files
os.unlink(png_out)
if not SCAN_MULTIPLE:
proc.terminate()
break
os.rmdir(tempdir) os.rmdir(tempdir)
@ -95,9 +99,9 @@ class XSaneCLI(Gimp.PlugIn):
raise Exception('Unknown procedure') raise Exception('Unknown procedure')
procedure.set_attribution( procedure.set_attribution(
'Lee Yingtong Li (RunasSudo) and CONTRIBUTORS', # Author 'Lee Yingtong Li (RunasSudo)', # Author
'Lee Yingtong Li (RunasSudo) and CONTRIBUTORS', # Copyright 'Lee Yingtong Li (RunasSudo)', # Copyright
'2024–2025' # Year 'Lee Yingtong Li (RunasSudo)' # Year
) )
return procedure return procedure