Merge pull request #1 from radarhere/image_grab_wayland_kde

Do not create temporary file if no utility is available
This commit is contained in:
Adian Kozlica 2025-03-29 23:44:12 +01:00 committed by GitHub
commit 2f672935eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -78,15 +78,15 @@ def grab(
size, data = Image.core.grabscreen_x11(display_name)
except OSError:
if display_name is None and sys.platform not in ("darwin", "win32"):
if shutil.which("gnome-screenshot"):
args = ["gnome-screenshot", "-f"]
elif shutil.which("spectacle"):
args = ["spectacle", "-n", "-b", "-f", "-o"]
else:
raise
fh, filepath = tempfile.mkstemp(".png")
os.close(fh)
if shutil.which("gnome-screenshot"):
subprocess.call(["gnome-screenshot", "-f", filepath])
elif shutil.which("spectacle"):
subprocess.call(["spectacle", "-n", "-b", "-f", "-o", filepath])
else:
os.unlink(filepath)
raise
subprocess.call(args + [filepath])
im = Image.open(filepath)
im.load()
os.unlink(filepath)