LBRY-Vault/lib/qrscanner.py
Tafelpoot 256a467dd7 QR code fixes
New classes ScanQRTextEdit and ShowQRTextEdit.
Reason: dependencies on zbar availability and issues with the QRTextEdit constructor.
- ScanQRTextEdit needs access to the config (fetch camera). It needs to load
the zbar processor properly before trying to scan. Keeping a reference to
the processor in qrscaner fixes the crashes on windows.
- ShowQRTextEdit should not have access to scan_qr().
- no need to setReadOnly anymore. It is clear from the class name.

Show master pub keys now has a Combobox if multiple accounts are
available.
2014-10-24 15:45:10 +02:00

48 lines
1.5 KiB
Python

import os
from i18n import _
try:
import zbar
except ImportError:
zbar = None
proc = None
def init(config):
if not zbar:
raise BaseException("\n".join([_("Cannot start QR scanner."),_("The zbar package is not available."),_("On Linux, try 'sudo apt-get install python-zbar'")]))
device = config.get("video_device", "default")
if device == 'default':
device = ''
global proc
proc = zbar.Processor()
proc.init(video_device=device)
def scan_qr(self):
if not zbar:
raise BaseException("\n".join([_("Cannot start QR scanner."),_("The zbar package is not available."),_("On Linux, try 'sudo apt-get install python-zbar'")]))
if proc is None:
raise BaseException("Start proc first")
proc.visible = True
while True:
try:
proc.process_one()
except Exception:
# User closed the preview window
return ""
for r in proc.results:
if str(r.type) != 'QRCODE':
continue
# hiding the preview window stops the camera
proc.visible = False
return r.data
def _find_system_cameras():
device_root = "/sys/class/video4linux"
devices = {} # Name -> device
if os.path.exists(device_root):
for device in os.listdir(device_root):
name = open(os.path.join(device_root, device, 'name')).read()
name = name.strip('\n')
devices[name] = os.path.join("/dev",device)
return devices