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
62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# Electron Cash - lightweight Bitcoin client
|
|
# Copyright (C) 2019 Axel Gembe <derago@gmail.com>
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person
|
|
# obtaining a copy of this software and associated documentation files
|
|
# (the "Software"), to deal in the Software without restriction,
|
|
# including without limitation the rights to use, copy, modify, merge,
|
|
# publish, distribute, sublicense, and/or sell copies of the Software,
|
|
# and to permit persons to whom the Software is furnished to do so,
|
|
# subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be
|
|
# included in all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
# SOFTWARE.
|
|
|
|
from typing import Optional
|
|
|
|
from ..logging import get_logger
|
|
|
|
from .abstract_base import AbstractQrCodeReader, QrCodeResult
|
|
|
|
|
|
_logger = get_logger(__name__)
|
|
|
|
|
|
class MissingLib(RuntimeError):
|
|
''' Raised by underlying implementation if missing libs '''
|
|
pass
|
|
|
|
|
|
def get_qr_reader() -> Optional[AbstractQrCodeReader]:
|
|
"""
|
|
Get the Qr code reader for the current platform
|
|
"""
|
|
try:
|
|
from .zbar import ZbarQrCodeReader
|
|
return ZbarQrCodeReader()
|
|
"""
|
|
# DEBUG CODE BELOW
|
|
# If you want to test this code on a platform that doesn't yet work or have
|
|
# zbar, use the below...
|
|
class Fake(AbstractQrCodeReader):
|
|
def read_qr_code(self, buffer, buffer_size, dummy, width, height, frame_id = -1):
|
|
''' fake noop to test '''
|
|
return []
|
|
return Fake()
|
|
"""
|
|
except MissingLib as e:
|
|
_logger.exception("")
|
|
|
|
return None
|