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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user