mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
qt wallet>info: use QStackedWidget, one stack item for each keystore
Instead of single mpk_text widget for each ks and changing the contents when switching, create an mpk_text widget for each ks and switch between those. This allows putting the "show xpub on device" button inside mpk_text.
This commit is contained in:
parent
5215582b83
commit
c313c702fd
3 changed files with 39 additions and 43 deletions
|
@ -46,7 +46,7 @@ from PyQt5.QtWidgets import (QMessageBox, QComboBox, QSystemTrayIcon, QTabWidget
|
||||||
QHBoxLayout, QPushButton, QScrollArea, QTextEdit,
|
QHBoxLayout, QPushButton, QScrollArea, QTextEdit,
|
||||||
QShortcut, QMainWindow, QCompleter, QInputDialog,
|
QShortcut, QMainWindow, QCompleter, QInputDialog,
|
||||||
QWidget, QSizePolicy, QStatusBar, QToolTip, QDialog,
|
QWidget, QSizePolicy, QStatusBar, QToolTip, QDialog,
|
||||||
QMenu, QAction)
|
QMenu, QAction, QStackedWidget)
|
||||||
|
|
||||||
import electrum
|
import electrum
|
||||||
from electrum import (keystore, ecc, constants, util, bitcoin, commands,
|
from electrum import (keystore, ecc, constants, util, bitcoin, commands,
|
||||||
|
@ -2354,25 +2354,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
||||||
if self.wallet.is_deterministic():
|
if self.wallet.is_deterministic():
|
||||||
keystores = self.wallet.get_keystores()
|
keystores = self.wallet.get_keystores()
|
||||||
|
|
||||||
mpk_text = ShowQRTextEdit()
|
ks_stack = QStackedWidget()
|
||||||
mpk_text.setMaximumHeight(150)
|
|
||||||
mpk_text.addCopyButton(self.app)
|
|
||||||
|
|
||||||
der_path_hbox = QHBoxLayout()
|
|
||||||
der_path_hbox.setContentsMargins(0, 0, 0, 0)
|
|
||||||
|
|
||||||
der_path_hbox.addWidget(QLabel(_("Derivation path") + ':'))
|
|
||||||
der_path_text = QLabel()
|
|
||||||
der_path_text.setTextInteractionFlags(Qt.TextSelectableByMouse)
|
|
||||||
der_path_hbox.addWidget(der_path_text)
|
|
||||||
der_path_hbox.addStretch()
|
|
||||||
|
|
||||||
def select_ks(index):
|
def select_ks(index):
|
||||||
ks = keystores[index]
|
ks_stack.setCurrentIndex(index)
|
||||||
mpk_text.setText(ks.get_master_public_key())
|
|
||||||
mpk_text.repaint() # macOS hack for #4777
|
|
||||||
der_path_text.setText(ks.get_derivation_prefix() or _("unknown"))
|
|
||||||
der_path_text.repaint() # macOS hack for #4777
|
|
||||||
|
|
||||||
# only show the combobox in case multiple accounts are available
|
# only show the combobox in case multiple accounts are available
|
||||||
if len(keystores) > 1:
|
if len(keystores) > 1:
|
||||||
|
@ -2387,18 +2372,40 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
||||||
on_click = lambda clayout: select_ks(clayout.selected_index())
|
on_click = lambda clayout: select_ks(clayout.selected_index())
|
||||||
labels_clayout = ChoicesLayout(_("Select keystore"), labels, on_click)
|
labels_clayout = ChoicesLayout(_("Select keystore"), labels, on_click)
|
||||||
vbox.addLayout(labels_clayout.layout())
|
vbox.addLayout(labels_clayout.layout())
|
||||||
labels_clayout.selected_index()
|
|
||||||
|
for ks in keystores:
|
||||||
|
ks_w = QWidget()
|
||||||
|
ks_vbox = QVBoxLayout()
|
||||||
|
ks_vbox.setContentsMargins(0, 0, 0, 0)
|
||||||
|
ks_w.setLayout(ks_vbox)
|
||||||
|
|
||||||
|
mpk_text = ShowQRTextEdit(ks.get_master_public_key())
|
||||||
|
mpk_text.setMaximumHeight(150)
|
||||||
|
mpk_text.addCopyButton(self.app)
|
||||||
|
run_hook('show_xpub_button', mpk_text, ks)
|
||||||
|
|
||||||
|
der_path_hbox = QHBoxLayout()
|
||||||
|
der_path_hbox.setContentsMargins(0, 0, 0, 0)
|
||||||
|
|
||||||
|
der_path_hbox.addWidget(QLabel(_("Derivation path") + ':'))
|
||||||
|
der_path_text = QLabel(ks.get_derivation_prefix() or _("unknown"))
|
||||||
|
der_path_text.setTextInteractionFlags(Qt.TextSelectableByMouse)
|
||||||
|
der_path_hbox.addWidget(der_path_text)
|
||||||
|
der_path_hbox.addStretch()
|
||||||
|
|
||||||
|
ks_vbox.addWidget(QLabel(_("Master Public Key")))
|
||||||
|
ks_vbox.addWidget(mpk_text)
|
||||||
|
ks_vbox.addLayout(der_path_hbox)
|
||||||
|
|
||||||
|
ks_stack.addWidget(ks_w)
|
||||||
|
|
||||||
select_ks(0)
|
select_ks(0)
|
||||||
vbox.addWidget(QLabel(_("Master Public Key")))
|
vbox.addWidget(ks_stack)
|
||||||
vbox.addWidget(mpk_text)
|
|
||||||
vbox.addLayout(der_path_hbox)
|
|
||||||
|
|
||||||
vbox.addStretch(1)
|
vbox.addStretch(1)
|
||||||
btn_export_info = run_hook('wallet_info_buttons', self, dialog)
|
btn_export_info = run_hook('wallet_info_buttons', self, dialog)
|
||||||
btn_show_xpub = run_hook('show_xpub_button', self, dialog, labels_clayout)
|
|
||||||
btn_close = CloseButton(dialog)
|
btn_close = CloseButton(dialog)
|
||||||
btns = Buttons(btn_export_info, btn_show_xpub, btn_close)
|
btns = Buttons(btn_export_info, btn_close)
|
||||||
vbox.addLayout(btns)
|
vbox.addLayout(btns)
|
||||||
dialog.setLayout(vbox)
|
dialog.setLayout(vbox)
|
||||||
dialog.exec_()
|
dialog.exec_()
|
||||||
|
|
|
@ -735,7 +735,7 @@ class ButtonsWidget(QWidget):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(QWidget, self).__init__()
|
super(QWidget, self).__init__()
|
||||||
self.buttons = []
|
self.buttons = [] # type: List[QToolButton]
|
||||||
|
|
||||||
def resizeButtons(self):
|
def resizeButtons(self):
|
||||||
frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
|
frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
|
||||||
|
|
|
@ -13,6 +13,7 @@ from PyQt5.QtCore import Qt, QMetaObject, Q_RETURN_ARG, pyqtSlot
|
||||||
from electrum.gui.qt.util import (
|
from electrum.gui.qt.util import (
|
||||||
WindowModalDialog,
|
WindowModalDialog,
|
||||||
OkButton,
|
OkButton,
|
||||||
|
ButtonsTextEdit,
|
||||||
)
|
)
|
||||||
|
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
|
@ -49,31 +50,19 @@ class Plugin(BitBox02Plugin, QtPluginBase):
|
||||||
|
|
||||||
@only_hook_if_libraries_available
|
@only_hook_if_libraries_available
|
||||||
@hook
|
@hook
|
||||||
def show_xpub_button(self, main_window, dialog, labels_clayout):
|
def show_xpub_button(self, mpk_text: ButtonsTextEdit, keystore):
|
||||||
# user is about to see the "Wallet Information" dialog
|
# user is about to see the "Wallet Information" dialog
|
||||||
# - add a button to show the xpub on the BitBox02 device
|
# - add a button to show the xpub on the BitBox02 device
|
||||||
wallet = main_window.wallet
|
if type(keystore) != self.keystore_class:
|
||||||
if not any(type(ks) == self.keystore_class for ks in wallet.get_keystores()):
|
|
||||||
# doesn't involve a BitBox02 wallet, hide feature
|
|
||||||
return
|
return
|
||||||
|
|
||||||
btn = QPushButton(_("Show on BitBox02"))
|
|
||||||
|
|
||||||
def on_button_click():
|
def on_button_click():
|
||||||
selected_keystore_index = 0
|
keystore.thread.add(
|
||||||
if labels_clayout is not None:
|
partial(self.show_xpub, keystore=keystore)
|
||||||
selected_keystore_index = labels_clayout.selected_index()
|
|
||||||
keystores = wallet.get_keystores()
|
|
||||||
selected_keystore = keystores[selected_keystore_index]
|
|
||||||
if type(selected_keystore) != self.keystore_class:
|
|
||||||
main_window.show_error("Select a BitBox02 xpub")
|
|
||||||
return
|
|
||||||
selected_keystore.thread.add(
|
|
||||||
partial(self.show_xpub, keystore=selected_keystore)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
btn.clicked.connect(lambda unused: on_button_click())
|
device_name = "{} ({})".format(self.device, keystore.label)
|
||||||
return btn
|
mpk_text.addButton("eye1.png", on_button_click, _("Show on {}").format(device_name))
|
||||||
|
|
||||||
|
|
||||||
class BitBox02_Handler(QtHandlerBase):
|
class BitBox02_Handler(QtHandlerBase):
|
||||||
|
|
Loading…
Add table
Reference in a new issue