From 635880b3cb5fe8cd422357de6ceab24fb9e7d759 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 16 Aug 2023 17:38:42 +0000 Subject: [PATCH] qt gui: input_qr_from_screenshot: better msg if screenshot is black The input_qr_from_screenshot functionality is broken on some Linux machines: on some machines, `screen.grabWindow(0)` returns an all-black image. In such cases, instead of telling the user "No QR code was found on the screen", we will tell them "Failed to take screenshot". To test: `QApplication.instance().primaryScreen().grabWindow(0).save("/home/user/wspace/tmp/pic2.png", "png")` Tested on: - machine 1: - ubuntu 22.04, gnome, wayland - pyqt.version: 5.15.9 - qt.version: 5.15.2 => gets all-black image for screenshot - machine 2: - manjaro, kde, x11 - pyqt.version: 5.15.9 - qt.version: 5.15.8 => screenshot works I guess it might be due to x11 vs wayland. --- electrum/gui/qt/util.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py index ac4920e48..dee323a19 100644 --- a/electrum/gui/qt/util.py +++ b/electrum/gui/qt/util.py @@ -585,10 +585,15 @@ class GenericInputHandler: if setText is None: setText = self.setText from .qrreader import scan_qr_from_image + screenshots = [screen.grabWindow(0).toImage() + for screen in QApplication.instance().screens()] + if all(screen.allGray() for screen in screenshots): + show_error(_("Failed to take screenshot.")) + return scanned_qr = None - for screen in QApplication.instance().screens(): + for screenshot in screenshots: try: - scan_result = scan_qr_from_image(screen.grabWindow(0).toImage()) + scan_result = scan_qr_from_image(screenshot) except MissingQrDetectionLib as e: show_error(_("Unable to scan image.") + "\n" + repr(e)) return