2014-06-14 03:17:44 -07:00
|
|
|
from electrum.i18n import _
|
2014-11-01 03:40:46 -07:00
|
|
|
from electrum.plugins import run_hook
|
2014-06-14 03:17:44 -07:00
|
|
|
from PyQt4.QtGui import *
|
|
|
|
from PyQt4.QtCore import *
|
|
|
|
|
2015-04-20 02:49:27 -07:00
|
|
|
from util import ButtonsTextEdit
|
2015-03-14 02:47:09 -07:00
|
|
|
|
|
|
|
|
2015-04-20 02:49:27 -07:00
|
|
|
class ShowQRTextEdit(ButtonsTextEdit):
|
2015-05-08 10:58:29 -07:00
|
|
|
|
2015-10-18 00:42:11 -07:00
|
|
|
def __init__(self, text=None, paranoid=False):
|
2015-05-08 11:00:13 -07:00
|
|
|
ButtonsTextEdit.__init__(self, text)
|
2014-10-24 06:45:10 -07:00
|
|
|
self.setReadOnly(1)
|
2015-04-20 02:49:27 -07:00
|
|
|
self.addButton(":icons/qrcode.png", self.qr_show, _("Show as QR code"))
|
2015-10-18 00:42:11 -07:00
|
|
|
|
|
|
|
if paranoid:
|
|
|
|
# Paranoid flag forces the user to write down what's in the box,
|
|
|
|
# like Mycelium does. This is useful since many users just copy
|
|
|
|
# and paste their code, then when disaster strikes they don't have
|
|
|
|
# it written down anywhere.
|
|
|
|
self.setAcceptDrops(False) # No dragging and dropping
|
|
|
|
# Use custom context menu to remove copy/paste from menu
|
|
|
|
self.setContextMenuPolicy(Qt.ActionsContextMenu)
|
|
|
|
self.qaction = QAction(_("Show as QR code"), self)
|
|
|
|
self.qaction.triggered.connect(self.qr_show)
|
|
|
|
self.addAction(self.qaction)
|
|
|
|
# No text selection allowed.
|
|
|
|
self.setTextInteractionFlags(Qt.NoTextInteraction)
|
|
|
|
|
2014-11-01 03:40:46 -07:00
|
|
|
run_hook('show_text_edit', self)
|
2014-06-14 03:17:44 -07:00
|
|
|
|
|
|
|
def qr_show(self):
|
|
|
|
from qrcodewidget import QRDialog
|
2014-09-04 10:13:43 -07:00
|
|
|
try:
|
|
|
|
s = str(self.toPlainText())
|
2014-09-04 14:33:31 -07:00
|
|
|
except:
|
|
|
|
s = unicode(self.toPlainText())
|
2014-09-04 10:13:43 -07:00
|
|
|
QRDialog(s).exec_()
|
2014-06-14 03:17:44 -07:00
|
|
|
|
2015-04-20 02:49:27 -07:00
|
|
|
class ScanQRTextEdit(ButtonsTextEdit):
|
2015-05-08 10:58:29 -07:00
|
|
|
|
|
|
|
def __init__(self, text=""):
|
|
|
|
ButtonsTextEdit.__init__(self, text)
|
2014-10-24 06:45:10 -07:00
|
|
|
self.setReadOnly(0)
|
2015-04-24 00:10:03 -07:00
|
|
|
self.addButton(":icons/file.png", self.file_input, _("Read file"))
|
2015-04-20 02:49:27 -07:00
|
|
|
self.addButton(":icons/qrcode.png", self.qr_input, _("Read QR code"))
|
2014-11-01 03:40:46 -07:00
|
|
|
run_hook('scan_text_edit', self)
|
2014-10-24 06:45:10 -07:00
|
|
|
|
2015-04-23 15:14:21 -07: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 03:17:44 -07:00
|
|
|
def qr_input(self):
|
2015-05-08 10:58:29 -07:00
|
|
|
from electrum import qrscanner, get_config
|
2014-08-23 08:45:47 -07:00
|
|
|
try:
|
2015-05-08 10:58:29 -07:00
|
|
|
data = qrscanner.scan_qr(get_config())
|
2014-08-23 08:45:47 -07:00
|
|
|
except BaseException, e:
|
2014-10-24 06:45:10 -07:00
|
|
|
QMessageBox.warning(self, _('Error'), _(e), _('OK'))
|
2014-10-24 08:11:05 -07:00
|
|
|
return ""
|
2014-07-12 09:39:28 -07:00
|
|
|
if type(data) != str:
|
|
|
|
return
|
|
|
|
self.setText(data)
|
2014-10-24 06:45:10 -07:00
|
|
|
return data
|
|
|
|
|
|
|
|
def contextMenuEvent(self, e):
|
|
|
|
m = self.createStandardContextMenu()
|
|
|
|
m.addAction(_("Read QR code"), self.qr_input)
|
|
|
|
m.exec_(e.globalPos())
|