electrum

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

commit c313c702fda3d6859d3b1a94a7e2cbccf5289df7
parent 5215582b83a7709ca6baadd1e1c5fd5fd1e449e9
Author: SomberNight <somber.night@protonmail.com>
Date:   Fri, 28 Aug 2020 20:10:58 +0200

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.

Diffstat:
Melectrum/gui/qt/main_window.py | 55+++++++++++++++++++++++++++++++------------------------
Melectrum/gui/qt/util.py | 2+-
Melectrum/plugins/bitbox02/qt.py | 25+++++++------------------
3 files changed, 39 insertions(+), 43 deletions(-)

diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -46,7 +46,7 @@ from PyQt5.QtWidgets import (QMessageBox, QComboBox, QSystemTrayIcon, QTabWidget QHBoxLayout, QPushButton, QScrollArea, QTextEdit, QShortcut, QMainWindow, QCompleter, QInputDialog, QWidget, QSizePolicy, QStatusBar, QToolTip, QDialog, - QMenu, QAction) + QMenu, QAction, QStackedWidget) import electrum from electrum import (keystore, ecc, constants, util, bitcoin, commands, @@ -2354,25 +2354,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): if self.wallet.is_deterministic(): keystores = self.wallet.get_keystores() - mpk_text = ShowQRTextEdit() - 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() + ks_stack = QStackedWidget() def select_ks(index): - ks = keystores[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 + ks_stack.setCurrentIndex(index) # only show the combobox in case multiple accounts are available if len(keystores) > 1: @@ -2387,18 +2372,40 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): on_click = lambda clayout: select_ks(clayout.selected_index()) labels_clayout = ChoicesLayout(_("Select keystore"), labels, on_click) 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) - vbox.addWidget(QLabel(_("Master Public Key"))) - vbox.addWidget(mpk_text) - vbox.addLayout(der_path_hbox) + vbox.addWidget(ks_stack) vbox.addStretch(1) 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) - btns = Buttons(btn_export_info, btn_show_xpub, btn_close) + btns = Buttons(btn_export_info, btn_close) vbox.addLayout(btns) dialog.setLayout(vbox) dialog.exec_() diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py @@ -735,7 +735,7 @@ class ButtonsWidget(QWidget): def __init__(self): super(QWidget, self).__init__() - self.buttons = [] + self.buttons = [] # type: List[QToolButton] def resizeButtons(self): frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth) diff --git a/electrum/plugins/bitbox02/qt.py b/electrum/plugins/bitbox02/qt.py @@ -13,6 +13,7 @@ from PyQt5.QtCore import Qt, QMetaObject, Q_RETURN_ARG, pyqtSlot from electrum.gui.qt.util import ( WindowModalDialog, OkButton, + ButtonsTextEdit, ) from electrum.i18n import _ @@ -49,31 +50,19 @@ class Plugin(BitBox02Plugin, QtPluginBase): @only_hook_if_libraries_available @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 # - add a button to show the xpub on the BitBox02 device - wallet = main_window.wallet - if not any(type(ks) == self.keystore_class for ks in wallet.get_keystores()): - # doesn't involve a BitBox02 wallet, hide feature + if type(keystore) != self.keystore_class: return - btn = QPushButton(_("Show on BitBox02")) - def on_button_click(): - selected_keystore_index = 0 - if labels_clayout is not None: - 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) + keystore.thread.add( + partial(self.show_xpub, keystore=keystore) ) - btn.clicked.connect(lambda unused: on_button_click()) - return btn + device_name = "{} ({})".format(self.device, keystore.label) + mpk_text.addButton("eye1.png", on_button_click, _("Show on {}").format(device_name)) class BitBox02_Handler(QtHandlerBase):