Browse Source

qt: rm some usages of get_parent_main_window

instead, pass around the main window or config (whichever is actually needed)

fixes #6342
patch-4
SomberNight 4 years ago
parent
commit
096d853482
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/gui/qt/installwizard.py
  2. 27
      electrum/gui/qt/main_window.py
  3. 2
      electrum/gui/qt/paytoedit.py
  4. 13
      electrum/gui/qt/qrtextedit.py
  5. 9
      electrum/gui/qt/request_list.py
  6. 17
      electrum/gui/qt/seed_dialog.py
  7. 20
      electrum/gui/qt/transaction_dialog.py
  8. 14
      electrum/gui/qt/util.py
  9. 2
      electrum/plugin.py
  10. 9
      electrum/plugins/coldcard/qt.py
  11. 5
      electrum/plugins/email_requests/qt.py
  12. 4
      electrum/plugins/revealer/qt.py

2
electrum/gui/qt/installwizard.py

@ -447,7 +447,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
def text_input(self, title, message, is_valid, allow_multi=False): def text_input(self, title, message, is_valid, allow_multi=False):
slayout = KeysLayout(parent=self, header_layout=message, is_valid=is_valid, slayout = KeysLayout(parent=self, header_layout=message, is_valid=is_valid,
allow_multi=allow_multi) allow_multi=allow_multi, config=self.config)
self.exec_layout(slayout, title, next_enabled=False) self.exec_layout(slayout, title, next_enabled=False)
return slayout.get_text() return slayout.get_text()

27
electrum/gui/qt/main_window.py

@ -2715,7 +2715,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
return self.tx_from_text(file_content) return self.tx_from_text(file_content)
def do_process_from_text(self): def do_process_from_text(self):
text = text_dialog(self, _('Input raw transaction'), _("Transaction:"), _("Load transaction")) text = text_dialog(
parent=self,
title=_('Input raw transaction'),
header_layout=_("Transaction:"),
ok_label=_("Load transaction"),
config=self.config,
)
if not text: if not text:
return return
tx = self.tx_from_text(text) tx = self.tx_from_text(text)
@ -2723,7 +2729,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.show_transaction(tx) self.show_transaction(tx)
def do_process_from_text_channel_backup(self): def do_process_from_text_channel_backup(self):
text = text_dialog(self, _('Input channel backup'), _("Channel Backup:"), _("Load backup")) text = text_dialog(
parent=self,
title=_('Input channel backup'),
header_layout=_("Channel Backup:"),
ok_label=_("Load backup"),
config=self.config,
)
if not text: if not text:
return return
if text.startswith('channel_backup:'): if text.startswith('channel_backup:'):
@ -2891,7 +2903,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
hbox_top.addWidget(QLabel(_("Enter private keys:"))) hbox_top.addWidget(QLabel(_("Enter private keys:")))
hbox_top.addWidget(InfoButton(WIF_HELP_TEXT), alignment=Qt.AlignRight) hbox_top.addWidget(InfoButton(WIF_HELP_TEXT), alignment=Qt.AlignRight)
vbox.addLayout(hbox_top) vbox.addLayout(hbox_top)
keys_e = ScanQRTextEdit(allow_multi=True) keys_e = ScanQRTextEdit(allow_multi=True, config=self.config)
keys_e.setTabChangesFocus(True) keys_e.setTabChangesFocus(True)
vbox.addWidget(keys_e) vbox.addWidget(keys_e)
@ -2956,7 +2968,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
WaitingDialog(self, msg, task, on_success, on_failure) WaitingDialog(self, msg, task, on_success, on_failure)
def _do_import(self, title, header_layout, func): def _do_import(self, title, header_layout, func):
text = text_dialog(self, title, header_layout, _('Import'), allow_multi=True) text = text_dialog(
parent=self,
title=title,
header_layout=header_layout,
ok_label=_('Import'),
allow_multi=True,
config=self.config,
)
if not text: if not text:
return return
keys = str(text).split() keys = str(text).split()

2
electrum/gui/qt/paytoedit.py

@ -62,7 +62,7 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit, Logger):
def __init__(self, win: 'ElectrumWindow'): def __init__(self, win: 'ElectrumWindow'):
CompletionTextEdit.__init__(self) CompletionTextEdit.__init__(self)
ScanQRTextEdit.__init__(self) ScanQRTextEdit.__init__(self, config=win.config)
Logger.__init__(self) Logger.__init__(self)
self.win = win self.win = win
self.amount_edit = win.amount_e self.amount_edit = win.amount_e

13
electrum/gui/qt/qrtextedit.py

@ -2,8 +2,9 @@ from PyQt5.QtWidgets import QFileDialog
from electrum.i18n import _ from electrum.i18n import _
from electrum.plugin import run_hook from electrum.plugin import run_hook
from electrum.simple_config import SimpleConfig
from .util import ButtonsTextEdit, MessageBoxMixin, ColorScheme, get_parent_main_window from .util import ButtonsTextEdit, MessageBoxMixin, ColorScheme
class ShowQRTextEdit(ButtonsTextEdit): class ShowQRTextEdit(ButtonsTextEdit):
@ -32,10 +33,11 @@ class ShowQRTextEdit(ButtonsTextEdit):
class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin): class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin):
def __init__(self, text="", allow_multi=False): def __init__(self, text="", allow_multi=False, *, config: SimpleConfig):
ButtonsTextEdit.__init__(self, text) ButtonsTextEdit.__init__(self, text)
self.allow_multi = allow_multi self.allow_multi = allow_multi
self.setReadOnly(0) self.config = config
self.setReadOnly(False)
self.addButton("file.png", self.file_input, _("Read file")) self.addButton("file.png", self.file_input, _("Read file"))
icon = "camera_white.png" if ColorScheme.dark_scheme else "camera_dark.png" icon = "camera_white.png" if ColorScheme.dark_scheme else "camera_dark.png"
self.addButton(icon, self.qr_input, _("Read QR code")) self.addButton(icon, self.qr_input, _("Read QR code"))
@ -60,11 +62,8 @@ class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin):
def qr_input(self): def qr_input(self):
from electrum import qrscanner from electrum import qrscanner
window_or_wizard = get_parent_main_window(self, allow_wizard=True)
assert window_or_wizard
config = window_or_wizard.config
try: try:
data = qrscanner.scan_barcode(config.get_video_device()) data = qrscanner.scan_barcode(self.config.get_video_device())
except BaseException as e: except BaseException as e:
self.show_error(repr(e)) self.show_error(repr(e))
data = '' data = ''

9
electrum/gui/qt/request_list.py

@ -24,7 +24,7 @@
# SOFTWARE. # SOFTWARE.
from enum import IntEnum from enum import IntEnum
from typing import Optional from typing import Optional, TYPE_CHECKING
from PyQt5.QtGui import QStandardItemModel, QStandardItem from PyQt5.QtGui import QStandardItemModel, QStandardItem
from PyQt5.QtWidgets import QMenu, QAbstractItemView from PyQt5.QtWidgets import QMenu, QAbstractItemView
@ -37,6 +37,9 @@ from electrum.plugin import run_hook
from .util import MyTreeView, pr_icons, read_QIcon, webopen, MySortModel from .util import MyTreeView, pr_icons, read_QIcon, webopen, MySortModel
if TYPE_CHECKING:
from .main_window import ElectrumWindow
ROLE_REQUEST_TYPE = Qt.UserRole ROLE_REQUEST_TYPE = Qt.UserRole
ROLE_KEY = Qt.UserRole + 1 ROLE_KEY = Qt.UserRole + 1
@ -59,7 +62,7 @@ class RequestList(MyTreeView):
} }
filter_columns = [Columns.DATE, Columns.DESCRIPTION, Columns.AMOUNT] filter_columns = [Columns.DATE, Columns.DESCRIPTION, Columns.AMOUNT]
def __init__(self, parent): def __init__(self, parent: 'ElectrumWindow'):
super().__init__(parent, self.create_menu, super().__init__(parent, self.create_menu,
stretch_column=self.Columns.DESCRIPTION, stretch_column=self.Columns.DESCRIPTION,
editable_columns=[]) editable_columns=[])
@ -206,5 +209,5 @@ class RequestList(MyTreeView):
#if 'view_url' in req: #if 'view_url' in req:
# menu.addAction(_("View in web browser"), lambda: webopen(req['view_url'])) # menu.addAction(_("View in web browser"), lambda: webopen(req['view_url']))
menu.addAction(_("Delete"), lambda: self.parent.delete_requests([key])) menu.addAction(_("Delete"), lambda: self.parent.delete_requests([key]))
run_hook('receive_list_menu', menu, key) run_hook('receive_list_menu', self.parent, menu, key)
menu.exec_(self.viewport().mapToGlobal(position)) menu.exec_(self.viewport().mapToGlobal(position))

17
electrum/gui/qt/seed_dialog.py

@ -23,6 +23,8 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
from typing import TYPE_CHECKING
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import (QVBoxLayout, QCheckBox, QHBoxLayout, QLineEdit, from PyQt5.QtWidgets import (QVBoxLayout, QCheckBox, QHBoxLayout, QLineEdit,
@ -37,6 +39,9 @@ from .util import (Buttons, OkButton, WWLabel, ButtonsTextEdit, icon_path,
from .qrtextedit import ShowQRTextEdit, ScanQRTextEdit from .qrtextedit import ShowQRTextEdit, ScanQRTextEdit
from .completion_text_edit import CompletionTextEdit from .completion_text_edit import CompletionTextEdit
if TYPE_CHECKING:
from electrum.simple_config import SimpleConfig
def seed_warning_msg(seed): def seed_warning_msg(seed):
return ''.join([ return ''.join([
@ -197,11 +202,19 @@ class SeedLayout(QVBoxLayout):
self.seed_e.enable_suggestions() self.seed_e.enable_suggestions()
class KeysLayout(QVBoxLayout): class KeysLayout(QVBoxLayout):
def __init__(self, parent=None, header_layout=None, is_valid=None, allow_multi=False): def __init__(
self,
parent=None,
header_layout=None,
is_valid=None,
allow_multi=False,
*,
config: 'SimpleConfig',
):
QVBoxLayout.__init__(self) QVBoxLayout.__init__(self)
self.parent = parent self.parent = parent
self.is_valid = is_valid self.is_valid = is_valid
self.text_e = ScanQRTextEdit(allow_multi=allow_multi) self.text_e = ScanQRTextEdit(allow_multi=allow_multi, config=config)
self.text_e.textChanged.connect(self.on_edit) self.text_e.textChanged.connect(self.on_edit)
if isinstance(header_layout, str): if isinstance(header_layout, str):
self.addWidget(WWLabel(header_layout)) self.addWidget(WWLabel(header_layout))

20
electrum/gui/qt/transaction_dialog.py

@ -353,9 +353,13 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
def merge_sigs(self): def merge_sigs(self):
if not isinstance(self.tx, PartialTransaction): if not isinstance(self.tx, PartialTransaction):
return return
text = text_dialog(self, _('Input raw transaction'), text = text_dialog(
_("Transaction to merge signatures from") + ":", parent=self,
_("Load transaction")) title=_('Input raw transaction'),
header_layout=_("Transaction to merge signatures from") + ":",
ok_label=_("Load transaction"),
config=self.config,
)
if not text: if not text:
return return
tx = self.main_window.tx_from_text(text) tx = self.main_window.tx_from_text(text)
@ -371,9 +375,13 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
def join_tx_with_another(self): def join_tx_with_another(self):
if not isinstance(self.tx, PartialTransaction): if not isinstance(self.tx, PartialTransaction):
return return
text = text_dialog(self, _('Input raw transaction'), text = text_dialog(
_("Transaction to join with") + " (" + _("add inputs and outputs") + "):", parent=self,
_("Load transaction")) title=_('Input raw transaction'),
header_layout=_("Transaction to join with") + " (" + _("add inputs and outputs") + "):",
ok_label=_("Load transaction"),
config=self.config,
)
if not text: if not text:
return return
tx = self.main_window.tx_from_text(text) tx = self.main_window.tx_from_text(text)

14
electrum/gui/qt/util.py

@ -31,6 +31,7 @@ from electrum.invoices import PR_UNPAID, PR_PAID, PR_EXPIRED, PR_INFLIGHT, PR_UN
if TYPE_CHECKING: if TYPE_CHECKING:
from .main_window import ElectrumWindow from .main_window import ElectrumWindow
from .installwizard import InstallWizard from .installwizard import InstallWizard
from electrum.simple_config import SimpleConfig
if platform.system() == 'Windows': if platform.system() == 'Windows':
@ -351,7 +352,16 @@ def line_dialog(parent, title, label, ok_label, default=None):
if dialog.exec_(): if dialog.exec_():
return txt.text() return txt.text()
def text_dialog(parent, title, header_layout, ok_label, default=None, allow_multi=False): def text_dialog(
*,
parent,
title,
header_layout,
ok_label,
default=None,
allow_multi=False,
config: 'SimpleConfig',
):
from .qrtextedit import ScanQRTextEdit from .qrtextedit import ScanQRTextEdit
dialog = WindowModalDialog(parent, title) dialog = WindowModalDialog(parent, title)
dialog.setMinimumWidth(600) dialog.setMinimumWidth(600)
@ -361,7 +371,7 @@ def text_dialog(parent, title, header_layout, ok_label, default=None, allow_mult
l.addWidget(QLabel(header_layout)) l.addWidget(QLabel(header_layout))
else: else:
l.addLayout(header_layout) l.addLayout(header_layout)
txt = ScanQRTextEdit(allow_multi=allow_multi) txt = ScanQRTextEdit(allow_multi=allow_multi, config=config)
if default: if default:
txt.setText(default) txt.setText(default)
l.addWidget(txt) l.addWidget(txt)

2
electrum/plugin.py

@ -238,7 +238,7 @@ def run_hook(name, *args):
class BasePlugin(Logger): class BasePlugin(Logger):
def __init__(self, parent, config, name): def __init__(self, parent, config: 'SimpleConfig', name):
self.parent = parent # type: Plugins # The plugins object self.parent = parent # type: Plugins # The plugins object
self.name = name self.name = name
self.config = config self.config = config

9
electrum/plugins/coldcard/qt.py

@ -5,8 +5,9 @@ import copy
from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtWidgets import QPushButton, QLabel, QVBoxLayout, QWidget, QGridLayout from PyQt5.QtWidgets import QPushButton, QLabel, QVBoxLayout, QWidget, QGridLayout
from electrum.gui.qt.util import WindowModalDialog, CloseButton, get_parent_main_window, Buttons from electrum.gui.qt.util import WindowModalDialog, CloseButton, Buttons
from electrum.gui.qt.transaction_dialog import TxDialog from electrum.gui.qt.transaction_dialog import TxDialog
from electrum.gui.qt.main_window import ElectrumWindow
from electrum.i18n import _ from electrum.i18n import _
from electrum.plugin import hook from electrum.plugin import hook
@ -92,7 +93,7 @@ class Coldcard_Handler(QtHandlerBase):
class CKCCSettingsDialog(WindowModalDialog): class CKCCSettingsDialog(WindowModalDialog):
def __init__(self, window, plugin, keystore): def __init__(self, window: ElectrumWindow, plugin, keystore):
title = _("{} Settings").format(plugin.device) title = _("{} Settings").format(plugin.device)
super(CKCCSettingsDialog, self).__init__(window, title) super(CKCCSettingsDialog, self).__init__(window, title)
self.setMaximumWidth(540) self.setMaximumWidth(540)
@ -104,6 +105,8 @@ class CKCCSettingsDialog(WindowModalDialog):
#handler = keystore.handler #handler = keystore.handler
self.thread = thread = keystore.thread self.thread = thread = keystore.thread
self.keystore = keystore self.keystore = keystore
assert isinstance(window, ElectrumWindow), f"{type(window)}"
self.window = window
def connect_and_doit(): def connect_and_doit():
# Attempt connection to device, or raise. # Attempt connection to device, or raise.
@ -188,7 +191,7 @@ class CKCCSettingsDialog(WindowModalDialog):
def start_upgrade(self, client): def start_upgrade(self, client):
# ask for a filename (must have already downloaded it) # ask for a filename (must have already downloaded it)
mw = get_parent_main_window(self) mw = self.window
dev = client.dev dev = client.dev
fileName = mw.getOpenFileName("Select upgraded firmware file", "*.dfu") fileName = mw.getOpenFileName("Select upgraded firmware file", "*.dfu")

5
electrum/plugins/email_requests/qt.py

@ -43,7 +43,7 @@ from PyQt5.QtWidgets import (QVBoxLayout, QLabel, QGridLayout, QLineEdit,
QInputDialog) QInputDialog)
from electrum.gui.qt.util import (EnterButton, Buttons, CloseButton, OkButton, from electrum.gui.qt.util import (EnterButton, Buttons, CloseButton, OkButton,
WindowModalDialog, get_parent_main_window) WindowModalDialog)
from electrum.gui.qt.main_window import ElectrumWindow from electrum.gui.qt.main_window import ElectrumWindow
from electrum.plugin import BasePlugin, hook from electrum.plugin import BasePlugin, hook
@ -176,8 +176,7 @@ class Plugin(BasePlugin):
#main_window.invoice_list.update() #main_window.invoice_list.update()
@hook @hook
def receive_list_menu(self, menu, addr): def receive_list_menu(self, window: ElectrumWindow, menu, addr):
window = get_parent_main_window(menu)
menu.addAction(_("Send via e-mail"), lambda: self.send(window, addr)) menu.addAction(_("Send via e-mail"), lambda: self.send(window, addr))
def send(self, window: ElectrumWindow, addr): def send(self, window: ElectrumWindow, addr):

4
electrum/plugins/revealer/qt.py

@ -116,7 +116,7 @@ class Plugin(RevealerPlugin):
bcreate.setMaximumWidth(181) bcreate.setMaximumWidth(181)
bcreate.setDefault(True) bcreate.setDefault(True)
vbox.addWidget(bcreate, Qt.AlignCenter) vbox.addWidget(bcreate, Qt.AlignCenter)
self.load_noise = ScanQRTextEdit() self.load_noise = ScanQRTextEdit(config=self.config)
self.load_noise.setTabChangesFocus(True) self.load_noise.setTabChangesFocus(True)
self.load_noise.textChanged.connect(self.on_edit) self.load_noise.textChanged.connect(self.on_edit)
self.load_noise.setMaximumHeight(33) self.load_noise.setMaximumHeight(33)
@ -253,7 +253,7 @@ class Plugin(RevealerPlugin):
self.vbox.addWidget(cprint) self.vbox.addWidget(cprint)
self.vbox.addSpacing(1) self.vbox.addSpacing(1)
self.vbox.addWidget(WWLabel("<b>"+_("OR")+"</b> "+_("type a custom alphanumerical secret below:"))) self.vbox.addWidget(WWLabel("<b>"+_("OR")+"</b> "+_("type a custom alphanumerical secret below:")))
self.text = ScanQRTextEdit() self.text = ScanQRTextEdit(config=self.config)
self.text.setTabChangesFocus(True) self.text.setTabChangesFocus(True)
self.text.setMaximumHeight(70) self.text.setMaximumHeight(70)
self.text.textChanged.connect(self.customtxt_limits) self.text.textChanged.connect(self.customtxt_limits)

Loading…
Cancel
Save