2014-06-14 12:17:44 +02:00
|
|
|
from electrum.i18n import _
|
2014-11-01 12:40:46 +02:00
|
|
|
from electrum.plugins import run_hook
|
2014-06-14 12:17:44 +02:00
|
|
|
from PyQt4.QtGui import *
|
|
|
|
|
from PyQt4.QtCore import *
|
|
|
|
|
|
2015-04-20 11:49:27 +02:00
|
|
|
from util import ButtonsTextEdit
|
2015-03-14 10:47:09 +01:00
|
|
|
|
|
|
|
|
|
2015-04-20 11:49:27 +02:00
|
|
|
class ShowQRTextEdit(ButtonsTextEdit):
|
2014-10-24 15:45:10 +02:00
|
|
|
def __init__(self, text=None):
|
|
|
|
|
super(ShowQRTextEdit, self).__init__(text)
|
|
|
|
|
self.setReadOnly(1)
|
2015-04-20 11:49:27 +02:00
|
|
|
self.addButton(":icons/qrcode.png", self.qr_show, _("Show as QR code"))
|
2014-11-01 12:40:46 +02:00
|
|
|
run_hook('show_text_edit', self)
|
2014-06-14 12:17:44 +02:00
|
|
|
|
|
|
|
|
def qr_show(self):
|
|
|
|
|
from qrcodewidget import QRDialog
|
2014-09-04 19:13:43 +02:00
|
|
|
try:
|
|
|
|
|
s = str(self.toPlainText())
|
2014-09-04 23:33:31 +02:00
|
|
|
except:
|
|
|
|
|
s = unicode(self.toPlainText())
|
2014-09-04 19:13:43 +02:00
|
|
|
QRDialog(s).exec_()
|
2014-06-14 12:17:44 +02:00
|
|
|
|
2014-10-24 15:45:10 +02:00
|
|
|
def contextMenuEvent(self, e):
|
|
|
|
|
m = self.createStandardContextMenu()
|
|
|
|
|
m.addAction(_("Show as QR code"), self.qr_show)
|
|
|
|
|
m.exec_(e.globalPos())
|
|
|
|
|
|
|
|
|
|
|
2015-04-20 11:49:27 +02:00
|
|
|
class ScanQRTextEdit(ButtonsTextEdit):
|
2014-10-24 15:45:10 +02:00
|
|
|
def __init__(self, win, text=""):
|
|
|
|
|
super(ScanQRTextEdit,self).__init__(text)
|
|
|
|
|
self.setReadOnly(0)
|
|
|
|
|
self.win = win
|
|
|
|
|
assert win, "You must pass a window with access to the config to ScanQRTextEdit constructor."
|
|
|
|
|
if win:
|
|
|
|
|
assert hasattr(win,"config"), "You must pass a window with access to the config to ScanQRTextEdit constructor."
|
2015-04-24 09:10:03 +02:00
|
|
|
self.addButton(":icons/file.png", self.file_input, _("Read file"))
|
2015-04-20 11:49:27 +02:00
|
|
|
self.addButton(":icons/qrcode.png", self.qr_input, _("Read QR code"))
|
2014-11-01 12:40:46 +02:00
|
|
|
run_hook('scan_text_edit', self)
|
2014-10-24 15:45:10 +02:00
|
|
|
|
2015-04-24 00:14:21 +02:00
|
|
|
def file_input(self):
|
|
|
|
|
fileName = unicode(QFileDialog.getOpenFileName(self, 'select file'))
|
|
|
|
|
if not fileName:
|
|
|
|
|
return
|
|
|
|
|
with open(fileName, "r") as f:
|
|
|
|
|
data = f.read()
|
|
|
|
|
self.setText(data)
|
|
|
|
|
|
2014-06-14 12:17:44 +02:00
|
|
|
def qr_input(self):
|
2014-08-23 17:45:47 +02:00
|
|
|
from electrum import qrscanner
|
|
|
|
|
try:
|
|
|
|
|
data = qrscanner.scan_qr(self.win.config)
|
|
|
|
|
except BaseException, e:
|
2014-10-24 15:45:10 +02:00
|
|
|
QMessageBox.warning(self, _('Error'), _(e), _('OK'))
|
2014-10-24 17:11:05 +02:00
|
|
|
return ""
|
2014-07-12 18:39:28 +02:00
|
|
|
if type(data) != str:
|
|
|
|
|
return
|
|
|
|
|
self.setText(data)
|
2014-10-24 15:45:10 +02:00
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
def contextMenuEvent(self, e):
|
|
|
|
|
m = self.createStandardContextMenu()
|
|
|
|
|
m.addAction(_("Read QR code"), self.qr_input)
|
|
|
|
|
m.exec_(e.globalPos())
|