show popup if qr scanner not enabled
authorThomasV <thomasv@gitorious>
Tue, 17 Jun 2014 14:45:45 +0000 (16:45 +0200)
committerThomasV <thomasv@gitorious>
Tue, 17 Jun 2014 14:45:45 +0000 (16:45 +0200)
gui/qt/paytoedit.py
gui/qt/qrtextedit.py
lib/plugins.py

index 44db585..db47080 100644 (file)
@@ -45,10 +45,7 @@ class PayToEdit(QRTextEdit):
         self.textChanged.connect(self.check_text)
         self.outputs = []
         self.is_pr = False
-
-    def qr_input(self):
-        from electrum.plugins import run_hook
-        run_hook('scan_qr_hook', lambda x: self.win.pay_from_URI(x))
+        self.scan_f = self.win.pay_from_URI
 
     def lock_amount(self):
         self.amount_edit.setFrozen(True)
index d4308e4..4d6a67e 100644 (file)
@@ -11,11 +11,8 @@ class QRTextEdit(QTextEdit):
         self.button.setStyleSheet("QToolButton { border: none; padding: 0px; }")
         self.button.setVisible(True)
         self.button.clicked.connect(lambda: self.qr_show() if self.isReadOnly() else self.qr_input())
-        #frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
-        #self.setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(self.button.sizeHint().width() + frameWidth + 1))
-        #msz = self.minimumSizeHint()
-        #self.setMinimumSize(max(msz.width(), self.button.sizeHint().height() + frameWidth * 2 + 2),
-        #                    max(msz.height(), self.button.sizeHint().height() + frameWidth * 2 + 2))
+        self.scan_f = self.setText
+
 
     def resizeEvent(self, e):
         o = QTextEdit.resizeEvent(self, e)
@@ -39,5 +36,5 @@ class QRTextEdit(QTextEdit):
 
     def qr_input(self):
         from electrum.plugins import run_hook
-        run_hook('scan_qr_hook', self.setText)
-
+        if not run_hook('scan_qr_hook', self.scan_f):
+            QMessageBox.warning(self, _('Error'), _('QR Scanner not enabled'), _('OK'))
index a3ba5bc..700dbc2 100644 (file)
@@ -34,6 +34,8 @@ def run_hook(name, *args):
     
     global plugins
 
+    found = 0
+
     for p in plugins:
 
         if not p.is_enabled():
@@ -43,13 +45,15 @@ def run_hook(name, *args):
         if not callable(f):
             continue
 
+        found += 1
+
         try:
             f(*args)
         except Exception:
             print_error("Plugin error")
             traceback.print_exc(file=sys.stdout)
             
-    return
+    return found