electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 8116b807655b61691fc7126e2920e9de021f24f8
parent f24a449d376f2cd33fe53566a4ce79a198d0ba79
Author: ThomasV <thomasv@electrum.org>
Date:   Tue, 26 Jun 2018 17:12:25 +0200

Merge pull request #3700 from bauerj/console-warning

Add a warning about harmful code to the console
Diffstat:
Mgui/qt/console.py | 40++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+), 0 deletions(-)

diff --git a/gui/qt/console.py b/gui/qt/console.py @@ -7,6 +7,7 @@ from PyQt5 import QtCore from PyQt5 import QtGui from PyQt5 import QtWidgets from electrum import util +from electrum.i18n import _ if platform.system() == 'Windows': @@ -17,6 +18,33 @@ else: MONOSPACE_FONT = 'monospace' +class OverlayLabel(QtWidgets.QLabel): + STYLESHEET = ''' + QLabel, QLabel link { + color: rgb(0, 0, 0); + background-color: rgb(248, 240, 200); + border: 1px solid; + border-color: rgb(255, 114, 47); + padding: 2px; + } + ''' + def __init__(self, text, parent): + super().__init__(text, parent) + self.setMinimumHeight(150) + self.setGeometry(0, 0, self.width(), self.height()) + self.setStyleSheet(self.STYLESHEET) + self.setMargin(0) + parent.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) + self.setWordWrap(True) + + def mousePressEvent(self, e): + self.hide() + + def on_resize(self, w): + padding = 2 # px, from the stylesheet above + self.setFixedWidth(w - padding) + + class Console(QtWidgets.QPlainTextEdit): def __init__(self, prompt='>> ', startup_message='', parent=None): QtWidgets.QPlainTextEdit.__init__(self, parent) @@ -35,6 +63,18 @@ class Console(QtWidgets.QPlainTextEdit): self.updateNamespace({'run':self.run_script}) self.set_json(False) + warning_text = "<h1>{}</h1><br>{}<br><br>{}".format( + _("Warning!"), + _("Do not paste code here that you don't understand. Executing the wrong code could lead " + "to your coins being irreversibly lost."), + _("Click here to hide this message.") + ) + self.messageOverlay = OverlayLabel(warning_text, self) + + def resizeEvent(self, e): + self.messageOverlay.on_resize(self.width() - self.verticalScrollBar().width()) + + def set_json(self, b): self.is_json = b