2017-01-22 10:25:24 -08:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import six
|
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
|
2017-09-22 20:54:38 -07:00
|
|
|
from PyQt5.QtGui import *
|
|
|
|
from PyQt5.QtCore import *
|
|
|
|
from PyQt5.QtWidgets import QFileDialog
|
2014-06-14 03:17:44 -07:00
|
|
|
|
2017-01-22 10:25:24 -08:00
|
|
|
from .util import ButtonsTextEdit, MessageBoxMixin
|
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-31 03:47:42 -07:00
|
|
|
def __init__(self, text=None):
|
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
|
|
|
|
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):
|
2017-01-30 01:36:56 -08:00
|
|
|
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:
|
2017-01-30 01:36:56 -08:00
|
|
|
s = self.toPlainText()
|
2014-09-04 10:13:43 -07:00
|
|
|
QRDialog(s).exec_()
|
2014-06-14 03:17:44 -07:00
|
|
|
|
2015-10-18 01:00:28 -07:00
|
|
|
def contextMenuEvent(self, e):
|
|
|
|
m = self.createStandardContextMenu()
|
|
|
|
m.addAction(_("Show as QR code"), self.qr_show)
|
|
|
|
m.exec_(e.globalPos())
|
|
|
|
|
|
|
|
|
2015-12-23 01:31:36 -08:00
|
|
|
class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin):
|
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):
|
2017-01-30 01:36:56 -08:00
|
|
|
fileName = QFileDialog.getOpenFileName(self, 'select file')
|
2015-04-23 15:14:21 -07:00
|
|
|
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:
|
2017-02-17 11:56:38 -08:00
|
|
|
data = qrscanner.scan_barcode(get_config().get_video_device())
|
2015-12-23 01:31:36 -08:00
|
|
|
except BaseException as e:
|
|
|
|
self.show_error(str(e))
|
2017-02-17 11:56:38 -08:00
|
|
|
data = ''
|
2014-07-12 09:39:28 -07:00
|
|
|
if type(data) != str:
|
2017-02-17 11:56:38 -08:00
|
|
|
data = ''
|
2014-07-12 09:39:28 -07:00
|
|
|
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())
|