qt: introduce PasswordLineEdit(QLineEdit)

This commit is contained in:
SomberNight 2020-04-07 16:48:26 +02:00
parent f11bf1dd4a
commit c798e5d9a1
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9
8 changed files with 30 additions and 30 deletions

View file

@ -34,7 +34,8 @@ from electrum.transaction import Transaction, PartialTransaction
from electrum.simple_config import FEERATE_WARNING_HIGH_FEE from electrum.simple_config import FEERATE_WARNING_HIGH_FEE
from electrum.wallet import InternalAddressCorruption from electrum.wallet import InternalAddressCorruption
from .util import WindowModalDialog, ColorScheme, HelpLabel, Buttons, CancelButton, BlockingWaitingDialog from .util import (WindowModalDialog, ColorScheme, HelpLabel, Buttons, CancelButton,
BlockingWaitingDialog, PasswordLineEdit)
from .fee_slider import FeeSlider from .fee_slider import FeeSlider
@ -144,8 +145,7 @@ class ConfirmTxDialog(TxEditor, WindowModalDialog):
grid.addWidget(self.message_label, 6, 0, 1, -1) grid.addWidget(self.message_label, 6, 0, 1, -1)
self.pw_label = QLabel(_('Password')) self.pw_label = QLabel(_('Password'))
self.pw_label.setVisible(self.password_required) self.pw_label.setVisible(self.password_required)
self.pw = QLineEdit() self.pw = PasswordLineEdit()
self.pw.setEchoMode(2)
self.pw.setVisible(self.password_required) self.pw.setVisible(self.password_required)
grid.addWidget(self.pw_label, 8, 0) grid.addWidget(self.pw_label, 8, 0)
grid.addWidget(self.pw, 8, 1, 1, -1) grid.addWidget(self.pw, 8, 1, 1, -1)

View file

@ -25,7 +25,7 @@ from electrum.i18n import _
from .seed_dialog import SeedLayout, KeysLayout from .seed_dialog import SeedLayout, KeysLayout
from .network_dialog import NetworkChoiceLayout from .network_dialog import NetworkChoiceLayout
from .util import (MessageBoxMixin, Buttons, icon_path, ChoicesLayout, WWLabel, from .util import (MessageBoxMixin, Buttons, icon_path, ChoicesLayout, WWLabel,
InfoButton, char_width_in_lineedit) InfoButton, char_width_in_lineedit, PasswordLineEdit)
from .password_dialog import PasswordLayout, PasswordLayoutForHW, PW_NEW from .password_dialog import PasswordLayout, PasswordLayoutForHW, PW_NEW
from electrum.plugin import run_hook, Plugins from electrum.plugin import run_hook, Plugins
@ -196,9 +196,8 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
msg_label = WWLabel('') msg_label = WWLabel('')
vbox.addWidget(msg_label) vbox.addWidget(msg_label)
hbox2 = QHBoxLayout() hbox2 = QHBoxLayout()
pw_e = QLineEdit('', self) pw_e = PasswordLineEdit('', self)
pw_e.setFixedWidth(17 * char_width_in_lineedit()) pw_e.setFixedWidth(17 * char_width_in_lineedit())
pw_e.setEchoMode(2)
pw_label = QLabel(_('Password') + ':') pw_label = QLabel(_('Password') + ':')
hbox2.addWidget(pw_label) hbox2.addWidget(pw_label)
hbox2.addWidget(pw_e) hbox2.addWidget(pw_e)

View file

@ -40,7 +40,8 @@ from electrum.interface import serialize_server, deserialize_server
from electrum.network import Network from electrum.network import Network
from electrum.logging import get_logger from electrum.logging import get_logger
from .util import Buttons, CloseButton, HelpButton, read_QIcon, char_width_in_lineedit from .util import (Buttons, CloseButton, HelpButton, read_QIcon, char_width_in_lineedit,
PasswordLineEdit)
_logger = get_logger(__name__) _logger = get_logger(__name__)
@ -267,9 +268,8 @@ class NetworkChoiceLayout(object):
self.proxy_port.setFixedWidth(fixed_width_port) self.proxy_port.setFixedWidth(fixed_width_port)
self.proxy_user = QLineEdit() self.proxy_user = QLineEdit()
self.proxy_user.setPlaceholderText(_("Proxy user")) self.proxy_user.setPlaceholderText(_("Proxy user"))
self.proxy_password = QLineEdit() self.proxy_password = PasswordLineEdit()
self.proxy_password.setPlaceholderText(_("Password")) self.proxy_password.setPlaceholderText(_("Password"))
self.proxy_password.setEchoMode(QLineEdit.Password)
self.proxy_password.setFixedWidth(fixed_width_port) self.proxy_password.setFixedWidth(fixed_width_port)
self.proxy_mode.currentIndexChanged.connect(self.set_proxy) self.proxy_mode.currentIndexChanged.connect(self.set_proxy)

View file

@ -33,7 +33,8 @@ from PyQt5.QtWidgets import QLineEdit, QLabel, QGridLayout, QVBoxLayout, QCheckB
from electrum.i18n import _ from electrum.i18n import _
from electrum.plugin import run_hook from electrum.plugin import run_hook
from .util import icon_path, WindowModalDialog, OkButton, CancelButton, Buttons from .util import (icon_path, WindowModalDialog, OkButton, CancelButton, Buttons,
PasswordLineEdit)
def check_password_strength(password): def check_password_strength(password):
@ -63,12 +64,9 @@ class PasswordLayout(object):
def __init__(self, msg, kind, OK_button, wallet=None, force_disable_encrypt_cb=False): def __init__(self, msg, kind, OK_button, wallet=None, force_disable_encrypt_cb=False):
self.wallet = wallet self.wallet = wallet
self.pw = QLineEdit() self.pw = PasswordLineEdit()
self.pw.setEchoMode(2) self.new_pw = PasswordLineEdit()
self.new_pw = QLineEdit() self.conf_pw = PasswordLineEdit()
self.new_pw.setEchoMode(2)
self.conf_pw = QLineEdit()
self.conf_pw.setEchoMode(2)
self.kind = kind self.kind = kind
self.OK_button = OK_button self.OK_button = OK_button
@ -290,8 +288,7 @@ class PasswordDialog(WindowModalDialog):
def __init__(self, parent=None, msg=None): def __init__(self, parent=None, msg=None):
msg = msg or _('Please enter your password') msg = msg or _('Please enter your password')
WindowModalDialog.__init__(self, parent, _("Enter Password")) WindowModalDialog.__init__(self, parent, _("Enter Password"))
self.pw = pw = QLineEdit() self.pw = pw = PasswordLineEdit()
pw.setEchoMode(2)
vbox = QVBoxLayout() vbox = QVBoxLayout()
vbox.addWidget(QLabel(msg)) vbox.addWidget(QLabel(msg))
grid = QGridLayout() grid = QGridLayout()

View file

@ -748,6 +748,12 @@ class ButtonsTextEdit(QPlainTextEdit, ButtonsWidget):
return o return o
class PasswordLineEdit(QLineEdit):
def __init__(self, *args, **kwargs):
QLineEdit.__init__(self, *args, **kwargs)
self.setEchoMode(QLineEdit.Password)
class TaskThread(QThread): class TaskThread(QThread):
'''Thread that runs background tasks. Callbacks are guaranteed '''Thread that runs background tasks. Callbacks are guaranteed
to happen in the context of its parent.''' to happen in the context of its parent.'''

View file

@ -33,7 +33,8 @@ from PyQt5.QtWidgets import QVBoxLayout, QLineEdit, QHBoxLayout, QLabel
from electrum.gui.qt.password_dialog import PasswordLayout, PW_PASSPHRASE from electrum.gui.qt.password_dialog import PasswordLayout, PW_PASSPHRASE
from electrum.gui.qt.util import (read_QIcon, WWLabel, OkButton, WindowModalDialog, from electrum.gui.qt.util import (read_QIcon, WWLabel, OkButton, WindowModalDialog,
Buttons, CancelButton, TaskThread, char_width_in_lineedit) Buttons, CancelButton, TaskThread, char_width_in_lineedit,
PasswordLineEdit)
from electrum.gui.qt.main_window import StatusBarButton, ElectrumWindow from electrum.gui.qt.main_window import StatusBarButton, ElectrumWindow
from electrum.gui.qt.installwizard import InstallWizard from electrum.gui.qt.installwizard import InstallWizard
@ -142,8 +143,7 @@ class QtHandlerBase(HardwareHandlerBase, QObject, Logger):
d.setLayout(vbox) d.setLayout(vbox)
passphrase = playout.new_password() if d.exec_() else None passphrase = playout.new_password() if d.exec_() else None
else: else:
pw = QLineEdit() pw = PasswordLineEdit()
pw.setEchoMode(2)
pw.setMinimumWidth(200) pw.setMinimumWidth(200)
vbox = QVBoxLayout() vbox = QVBoxLayout()
vbox.addWidget(WWLabel(msg)) vbox.addWidget(WWLabel(msg))

View file

@ -5,6 +5,8 @@ from PyQt5.QtWidgets import (QDialog, QLineEdit, QTextEdit, QVBoxLayout, QLabel,
from btchip.btchip import BTChipException from btchip.btchip import BTChipException
from electrum.gui.qt.util import PasswordLineEdit
from electrum.i18n import _ from electrum.i18n import _
from electrum import constants, bitcoin from electrum import constants, bitcoin
from electrum.logging import get_logger from electrum.logging import get_logger
@ -79,8 +81,7 @@ class LedgerAuthDialog(QDialog):
self.pinbox = QWidget() self.pinbox = QWidget()
pinlayout = QHBoxLayout() pinlayout = QHBoxLayout()
self.pinbox.setLayout(pinlayout) self.pinbox.setLayout(pinlayout)
self.pintxt = QLineEdit() self.pintxt = PasswordLineEdit()
self.pintxt.setEchoMode(2)
self.pintxt.setMaxLength(4) self.pintxt.setMaxLength(4)
self.pintxt.returnPressed.connect(return_pin) self.pintxt.returnPressed.connect(return_pin)
pinlayout.addWidget(QLabel(_("Enter PIN:"))) pinlayout.addWidget(QLabel(_("Enter PIN:")))
@ -121,8 +122,7 @@ class LedgerAuthDialog(QDialog):
pin_changed('') pin_changed('')
cardpin = QHBoxLayout() cardpin = QHBoxLayout()
cardpin.addWidget(QLabel(_("Enter PIN:"))) cardpin.addWidget(QLabel(_("Enter PIN:")))
self.cardtxt = QLineEdit() self.cardtxt = PasswordLineEdit()
self.cardtxt.setEchoMode(2)
self.cardtxt.setMaxLength(len(self.idxs)) self.cardtxt.setMaxLength(len(self.idxs))
self.cardtxt.textChanged.connect(pin_changed) self.cardtxt.textChanged.connect(pin_changed)
self.cardtxt.returnPressed.connect(return_pin) self.cardtxt.returnPressed.connect(return_pin)

View file

@ -8,7 +8,7 @@ from PyQt5.QtWidgets import (QVBoxLayout, QLabel, QGridLayout, QPushButton,
QMessageBox, QFileDialog, QSlider, QTabWidget) QMessageBox, QFileDialog, QSlider, QTabWidget)
from electrum.gui.qt.util import (WindowModalDialog, WWLabel, Buttons, CancelButton, from electrum.gui.qt.util import (WindowModalDialog, WWLabel, Buttons, CancelButton,
OkButton, CloseButton) OkButton, CloseButton, PasswordLineEdit)
from electrum.i18n import _ from electrum.i18n import _
from electrum.plugin import hook from electrum.plugin import hook
from electrum.util import bh2u from electrum.util import bh2u
@ -172,10 +172,8 @@ class QtHandler(QtHandlerBase):
OK_button = OkButton(d, _('Enter Passphrase')) OK_button = OkButton(d, _('Enter Passphrase'))
OnDevice_button = QPushButton(_('Enter Passphrase on Device')) OnDevice_button = QPushButton(_('Enter Passphrase on Device'))
new_pw = QLineEdit() new_pw = PasswordLineEdit()
new_pw.setEchoMode(2) conf_pw = PasswordLineEdit()
conf_pw = QLineEdit()
conf_pw.setEchoMode(2)
vbox = QVBoxLayout() vbox = QVBoxLayout()
label = QLabel(msg + "\n") label = QLabel(msg + "\n")