2017-01-22 21:25:24 +03:00
|
|
|
|
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
|
2017-09-23 05:54:38 +02:00
|
|
|
from PyQt5.QtGui import *
|
|
|
|
|
from PyQt5.QtCore import *
|
|
|
|
|
from PyQt5.QtWidgets import QFileDialog
|
2014-06-14 12:17:44 +02:00
|
|
|
|
2017-10-04 15:09:31 +02:00
|
|
|
from .util import ButtonsTextEdit, MessageBoxMixin, ColorScheme
|
2015-03-14 10:47:09 +01:00
|
|
|
|
|
|
|
|
|
2015-04-20 11:49:27 +02:00
|
|
|
class ShowQRTextEdit(ButtonsTextEdit):
|
2015-05-08 19:58:29 +02:00
|
|
|
|
2015-10-31 11:47:42 +01:00
|
|
|
def __init__(self, text=None):
|
2015-05-08 20:00:13 +02:00
|
|
|
ButtonsTextEdit.__init__(self, text)
|
2014-10-24 15:45:10 +02:00
|
|
|
self.setReadOnly(1)
|
2015-04-20 11:49:27 +02:00
|
|
|
self.addButton(":icons/qrcode.png", self.qr_show, _("Show as QR code"))
|
2015-10-18 15:42:11 +08:00
|
|
|
|
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):
|
2017-01-30 12:36:56 +03:00
|
|
|
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:
|
2017-01-30 12:36:56 +03:00
|
|
|
s = self.toPlainText()
|
2014-09-04 19:13:43 +02:00
|
|
|
QRDialog(s).exec_()
|
2014-06-14 12:17:44 +02:00
|
|
|
|
2015-10-18 16:00:28 +08:00
|
|
|
def contextMenuEvent(self, e):
|
|
|
|
|
m = self.createStandardContextMenu()
|
|
|
|
|
m.addAction(_("Show as QR code"), self.qr_show)
|
|
|
|
|
m.exec_(e.globalPos())
|
|
|
|
|
|
|
|
|
|
|
2015-12-23 18:31:36 +09:00
|
|
|
class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin):
|
2015-05-08 19:58:29 +02:00
|
|
|
|
|
|
|
|
def __init__(self, text=""):
|
|
|
|
|
ButtonsTextEdit.__init__(self, text)
|
2014-10-24 15:45:10 +02:00
|
|
|
self.setReadOnly(0)
|
2015-04-24 09:10:03 +02:00
|
|
|
self.addButton(":icons/file.png", self.file_input, _("Read file"))
|
2017-10-04 15:09:31 +02:00
|
|
|
icon = ":icons/qrcode_white.png" if ColorScheme.dark_scheme else ":icons/qrcode.png"
|
|
|
|
|
self.addButton(icon, 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):
|
2017-09-24 04:44:11 +02:00
|
|
|
fileName, __ = QFileDialog.getOpenFileName(self, 'select file')
|
2015-04-24 00:14:21 +02:00
|
|
|
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):
|
2015-05-08 19:58:29 +02:00
|
|
|
from electrum import qrscanner, get_config
|
2014-08-23 17:45:47 +02:00
|
|
|
try:
|
2017-02-17 20:56:38 +01:00
|
|
|
data = qrscanner.scan_barcode(get_config().get_video_device())
|
2015-12-23 18:31:36 +09:00
|
|
|
except BaseException as e:
|
|
|
|
|
self.show_error(str(e))
|
2017-02-17 20:56:38 +01:00
|
|
|
data = ''
|
2014-07-12 18:39:28 +02:00
|
|
|
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())
|