Browse Source

init qrscanner processor in scan_qr

283
ThomasV 10 years ago
parent
commit
311a91c03c
  1. 6
      gui/qt/main_window.py
  2. 8
      gui/qt/qrtextedit.py
  3. 19
      lib/qrscanner.py

6
gui/qt/main_window.py

@ -2144,12 +2144,6 @@ class ElectrumWindow(QMainWindow):
def read_tx_from_qrcode(self):
from electrum import qrscanner
if qrscanner.proc is None:
try:
qrscanner.init(self.config)
except Exception, e:
QMessageBox.warning(self, _('Error'), _(e), _('OK'))
return
try:
data = qrscanner.scan_qr(self.config)
except BaseException, e:

8
gui/qt/qrtextedit.py

@ -53,17 +53,11 @@ class ScanQRTextEdit(QRTextEdit):
def qr_input(self):
from electrum import qrscanner
if qrscanner.proc is None:
try:
qrscanner.init(self.win.config)
except Exception, e:
QMessageBox.warning(self, _('Error'), _(e), _('OK'))
return
try:
data = qrscanner.scan_qr(self.win.config)
except BaseException, e:
QMessageBox.warning(self, _('Error'), _(e), _('OK'))
return
return ""
if type(data) != str:
return
self.setText(data)

19
lib/qrscanner.py

@ -8,21 +8,18 @@ except ImportError:
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):
def scan_qr(config):
global proc
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")
device = config.get("video_device", "default")
if device == 'default':
device = ''
proc = zbar.Processor()
proc.init(video_device=device)
proc.visible = True
while True:
try:

Loading…
Cancel
Save