qt: new qrreader using QtMultimedia; drop CalinsQRReader(mac)
This commit ports the work of EchterAgo and cculianu from Electron-Cash, to implement a new toolchain to scan qr codes. Previously, on Linux and Win, we have been using zbar to access the camera and read qrcodes; and on macOS we used CalinsQRReader (an objective-C project by cculianu). The new toolchain added here can use QtMultimedia to access the camera, and then feed that image into zbar. When used this way, zbar needs fewer dependencies and is easier to compile, in particular it can be compiled for macOS. The new toolchain works on all three platforms, with some caveats (see code comments in related commits) -- so we also keep the end-to-end zbar toolchain; but at least we can drop CalinsQRReader. The related changes in Electron-Cash are spread over 50+ commits (several PRs and direct pushes to master), but see in particular: https://github.com/Electron-Cash/Electron-Cash/pull/1376 some other interesting links:b2b737001c163224cf1f3b31e0fcb1eda015908ehttps://github.com/Electron-Cash/Electron-Cash/pull/1545052aa06c23
This commit is contained in:
@@ -50,11 +50,10 @@ except BaseException as e1:
|
||||
libzbar = ctypes.cdll.LoadLibrary(name)
|
||||
except BaseException as e2:
|
||||
libzbar = None
|
||||
if sys.platform != 'darwin':
|
||||
_logger.error(f"failed to load zbar. exceptions: {[e1,e2]!r}")
|
||||
_logger.error(f"failed to load zbar. exceptions: {[e1,e2]!r}")
|
||||
|
||||
|
||||
def scan_barcode_ctypes(device='', timeout=-1, display=True, threaded=False) -> Optional[str]:
|
||||
def scan_barcode(device='', timeout=-1, display=True, threaded=False) -> Optional[str]:
|
||||
if libzbar is None:
|
||||
raise UserFacingException("Cannot start QR scanner: zbar not available.")
|
||||
libzbar.zbar_symbol_get_data.restype = ctypes.c_char_p
|
||||
@@ -82,28 +81,6 @@ def scan_barcode_ctypes(device='', timeout=-1, display=True, threaded=False) ->
|
||||
data = libzbar.zbar_symbol_get_data(symbol)
|
||||
return data.decode('utf8')
|
||||
|
||||
def scan_barcode_osx(*args_ignored, **kwargs_ignored):
|
||||
import subprocess
|
||||
# NOTE: This code needs to be modified if the positions of this file changes with respect to the helper app!
|
||||
# This assumes the built macOS .app bundle which ends up putting the helper app in
|
||||
# .app/contrib/osx/CalinsQRReader/build/Release/CalinsQRReader.app.
|
||||
root_ec_dir = os.path.abspath(os.path.dirname(__file__) + "/../")
|
||||
prog = root_ec_dir + "/" + "contrib/osx/CalinsQRReader/build/Release/CalinsQRReader.app/Contents/MacOS/CalinsQRReader"
|
||||
if not os.path.exists(prog):
|
||||
raise UserFacingException("Cannot start QR scanner: helper app not found.")
|
||||
data = ''
|
||||
try:
|
||||
# This will run the "CalinsQRReader" helper app (which also gets bundled with the built .app)
|
||||
# Just like the zbar implementation -- the main app will hang until the QR window returns a QR code
|
||||
# (or is closed). Communication with the subprocess is done via stdout.
|
||||
# See contrib/CalinsQRReader for the helper app source code.
|
||||
with subprocess.Popen([prog], stdout=subprocess.PIPE) as p:
|
||||
data = p.stdout.read().decode('utf-8').strip()
|
||||
return data
|
||||
except OSError as e:
|
||||
raise UserFacingException("Cannot start camera helper app: {}".format(e.strerror))
|
||||
|
||||
scan_barcode = scan_barcode_osx if sys.platform == 'darwin' else scan_barcode_ctypes
|
||||
|
||||
def _find_system_cameras():
|
||||
device_root = "/sys/class/video4linux"
|
||||
|
||||
Reference in New Issue
Block a user