electrum-bitcoinprivate/gui/qt/qrtextedit.py

66 lines
2.0 KiB
Python
Raw Normal View History

2017-01-22 10:25:24 -08:00
2014-06-14 03:17:44 -07:00
from electrum.i18n import _
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
from .util import ButtonsTextEdit, MessageBoxMixin, ColorScheme
class ShowQRTextEdit(ButtonsTextEdit):
def __init__(self, text=None):
2015-05-08 11:00:13 -07:00
ButtonsTextEdit.__init__(self, text)
self.setReadOnly(1)
self.addButton(":icons/qrcode.png", self.qr_show, _("Show as QR code"))
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
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()
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):
def __init__(self, text=""):
ButtonsTextEdit.__init__(self, text)
self.setReadOnly(0)
2015-04-24 00:10:03 -07:00
self.addButton(":icons/file.png", self.file_input, _("Read file"))
icon = ":icons/qrcode_white.png" if ColorScheme.dark_scheme else ":icons/qrcode.png"
self.addButton(icon, self.qr_input, _("Read QR code"))
run_hook('scan_text_edit', self)
def file_input(self):
fileName, __ = 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):
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
self.setText(data)
return data
def contextMenuEvent(self, e):
m = self.createStandardContextMenu()
m.addAction(_("Read QR code"), self.qr_input)
m.exec_(e.globalPos())