URI: 
       tqt: rm some usages of get_parent_main_window - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 096d85348218398c09915e33cabd11e34e323329
   DIR parent 08c3d2ccd0e50c2e721c8f710acf1f0f443bc1ee
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Sun, 20 Dec 2020 13:26:35 +0100
       
       qt: rm some usages of get_parent_main_window
       
       instead, pass around the main window or config (whichever is actually needed)
       
       fixes #6342
       
       Diffstat:
         M electrum/gui/qt/installwizard.py    |       2 +-
         M electrum/gui/qt/main_window.py      |      27 +++++++++++++++++++++++----
         M electrum/gui/qt/paytoedit.py        |       2 +-
         M electrum/gui/qt/qrtextedit.py       |      13 ++++++-------
         M electrum/gui/qt/request_list.py     |       9 ++++++---
         M electrum/gui/qt/seed_dialog.py      |      17 +++++++++++++++--
         M electrum/gui/qt/transaction_dialog… |      20 ++++++++++++++------
         M electrum/gui/qt/util.py             |      14 ++++++++++++--
         M electrum/plugin.py                  |       2 +-
         M electrum/plugins/coldcard/qt.py     |       9 ++++++---
         M electrum/plugins/email_requests/qt… |       5 ++---
         M electrum/plugins/revealer/qt.py     |       4 ++--
       
       12 files changed, 89 insertions(+), 35 deletions(-)
       ---
   DIR diff --git a/electrum/gui/qt/installwizard.py b/electrum/gui/qt/installwizard.py
       t@@ -447,7 +447,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
        
            def text_input(self, title, message, is_valid, allow_multi=False):
                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)
                return slayout.get_text()
        
   DIR diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
       t@@ -2715,7 +2715,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
                return self.tx_from_text(file_content)
        
            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:
                    return
                tx = self.tx_from_text(text)
       t@@ -2723,7 +2729,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
                    self.show_transaction(tx)
        
            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:
                    return
                if text.startswith('channel_backup:'):
       t@@ -2891,7 +2903,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
                hbox_top.addWidget(QLabel(_("Enter private keys:")))
                hbox_top.addWidget(InfoButton(WIF_HELP_TEXT), alignment=Qt.AlignRight)
                vbox.addLayout(hbox_top)
       -        keys_e = ScanQRTextEdit(allow_multi=True)
       +        keys_e = ScanQRTextEdit(allow_multi=True, config=self.config)
                keys_e.setTabChangesFocus(True)
                vbox.addWidget(keys_e)
        
       t@@ -2956,7 +2968,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
                WaitingDialog(self, msg, task, on_success, on_failure)
        
            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:
                    return
                keys = str(text).split()
   DIR diff --git a/electrum/gui/qt/paytoedit.py b/electrum/gui/qt/paytoedit.py
       t@@ -62,7 +62,7 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit, Logger):
        
            def __init__(self, win: 'ElectrumWindow'):
                CompletionTextEdit.__init__(self)
       -        ScanQRTextEdit.__init__(self)
       +        ScanQRTextEdit.__init__(self, config=win.config)
                Logger.__init__(self)
                self.win = win
                self.amount_edit = win.amount_e
   DIR diff --git a/electrum/gui/qt/qrtextedit.py b/electrum/gui/qt/qrtextedit.py
       t@@ -2,8 +2,9 @@ from PyQt5.QtWidgets import QFileDialog
        
        from electrum.i18n import _
        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):
       t@@ -32,10 +33,11 @@ class ShowQRTextEdit(ButtonsTextEdit):
        
        class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin):
        
       -    def __init__(self, text="", allow_multi=False):
       +    def __init__(self, text="", allow_multi=False, *, config: SimpleConfig):
                ButtonsTextEdit.__init__(self, text)
                self.allow_multi = allow_multi
       -        self.setReadOnly(0)
       +        self.config = config
       +        self.setReadOnly(False)
                self.addButton("file.png", self.file_input, _("Read file"))
                icon = "camera_white.png" if ColorScheme.dark_scheme else "camera_dark.png"
                self.addButton(icon, self.qr_input, _("Read QR code"))
       t@@ -60,11 +62,8 @@ class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin):
        
            def qr_input(self):
                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:
       -            data = qrscanner.scan_barcode(config.get_video_device())
       +            data = qrscanner.scan_barcode(self.config.get_video_device())
                except BaseException as e:
                    self.show_error(repr(e))
                    data = ''
   DIR diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py
       t@@ -24,7 +24,7 @@
        # SOFTWARE.
        
        from enum import IntEnum
       -from typing import Optional
       +from typing import Optional, TYPE_CHECKING
        
        from PyQt5.QtGui import QStandardItemModel, QStandardItem
        from PyQt5.QtWidgets import QMenu, QAbstractItemView
       t@@ -37,6 +37,9 @@ from electrum.plugin import run_hook
        
        from .util import MyTreeView, pr_icons, read_QIcon, webopen, MySortModel
        
       +if TYPE_CHECKING:
       +    from .main_window import ElectrumWindow
       +
        
        ROLE_REQUEST_TYPE = Qt.UserRole
        ROLE_KEY = Qt.UserRole + 1
       t@@ -59,7 +62,7 @@ class RequestList(MyTreeView):
            }
            filter_columns = [Columns.DATE, Columns.DESCRIPTION, Columns.AMOUNT]
        
       -    def __init__(self, parent):
       +    def __init__(self, parent: 'ElectrumWindow'):
                super().__init__(parent, self.create_menu,
                                 stretch_column=self.Columns.DESCRIPTION,
                                 editable_columns=[])
       t@@ -206,5 +209,5 @@ class RequestList(MyTreeView):
                #if 'view_url' in req:
                #    menu.addAction(_("View in web browser"), lambda: webopen(req['view_url']))
                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))
   DIR diff --git a/electrum/gui/qt/seed_dialog.py b/electrum/gui/qt/seed_dialog.py
       t@@ -23,6 +23,8 @@
        # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        # SOFTWARE.
        
       +from typing import TYPE_CHECKING
       +
        from PyQt5.QtCore import Qt
        from PyQt5.QtGui import QPixmap
        from PyQt5.QtWidgets import (QVBoxLayout, QCheckBox, QHBoxLayout, QLineEdit,
       t@@ -37,6 +39,9 @@ from .util import (Buttons, OkButton, WWLabel, ButtonsTextEdit, icon_path,
        from .qrtextedit import ShowQRTextEdit, ScanQRTextEdit
        from .completion_text_edit import CompletionTextEdit
        
       +if TYPE_CHECKING:
       +    from electrum.simple_config import SimpleConfig
       +
        
        def seed_warning_msg(seed):
            return ''.join([
       t@@ -197,11 +202,19 @@ class SeedLayout(QVBoxLayout):
                self.seed_e.enable_suggestions()
        
        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)
                self.parent = parent
                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)
                if isinstance(header_layout, str):
                    self.addWidget(WWLabel(header_layout))
   DIR diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py
       t@@ -353,9 +353,13 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
            def merge_sigs(self):
                if not isinstance(self.tx, PartialTransaction):
                    return
       -        text = text_dialog(self, _('Input raw transaction'),
       -                           _("Transaction to merge signatures from") + ":",
       -                           _("Load transaction"))
       +        text = text_dialog(
       +            parent=self,
       +            title=_('Input raw transaction'),
       +            header_layout=_("Transaction to merge signatures from") + ":",
       +            ok_label=_("Load transaction"),
       +            config=self.config,
       +        )
                if not text:
                    return
                tx = self.main_window.tx_from_text(text)
       t@@ -371,9 +375,13 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
            def join_tx_with_another(self):
                if not isinstance(self.tx, PartialTransaction):
                    return
       -        text = text_dialog(self, _('Input raw transaction'),
       -                           _("Transaction to join with") + " (" + _("add inputs and outputs") + "):",
       -                           _("Load transaction"))
       +        text = text_dialog(
       +            parent=self,
       +            title=_('Input raw transaction'),
       +            header_layout=_("Transaction to join with") + " (" + _("add inputs and outputs") + "):",
       +            ok_label=_("Load transaction"),
       +            config=self.config,
       +        )
                if not text:
                    return
                tx = self.main_window.tx_from_text(text)
   DIR diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py
       t@@ -31,6 +31,7 @@ from electrum.invoices import PR_UNPAID, PR_PAID, PR_EXPIRED, PR_INFLIGHT, PR_UN
        if TYPE_CHECKING:
            from .main_window import ElectrumWindow
            from .installwizard import InstallWizard
       +    from electrum.simple_config import SimpleConfig
        
        
        if platform.system() == 'Windows':
       t@@ -351,7 +352,16 @@ def line_dialog(parent, title, label, ok_label, default=None):
            if dialog.exec_():
                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
            dialog = WindowModalDialog(parent, title)
            dialog.setMinimumWidth(600)
       t@@ -361,7 +371,7 @@ def text_dialog(parent, title, header_layout, ok_label, default=None, allow_mult
                l.addWidget(QLabel(header_layout))
            else:
                l.addLayout(header_layout)
       -    txt = ScanQRTextEdit(allow_multi=allow_multi)
       +    txt = ScanQRTextEdit(allow_multi=allow_multi, config=config)
            if default:
                txt.setText(default)
            l.addWidget(txt)
   DIR diff --git a/electrum/plugin.py b/electrum/plugin.py
       t@@ -238,7 +238,7 @@ def run_hook(name, *args):
        
        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.name = name
                self.config = config
   DIR diff --git a/electrum/plugins/coldcard/qt.py b/electrum/plugins/coldcard/qt.py
       t@@ -5,8 +5,9 @@ import copy
        from PyQt5.QtCore import Qt, pyqtSignal
        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.main_window import ElectrumWindow
        
        from electrum.i18n import _
        from electrum.plugin import hook
       t@@ -92,7 +93,7 @@ class Coldcard_Handler(QtHandlerBase):
        
        class CKCCSettingsDialog(WindowModalDialog):
        
       -    def __init__(self, window, plugin, keystore):
       +    def __init__(self, window: ElectrumWindow, plugin, keystore):
                title = _("{} Settings").format(plugin.device)
                super(CKCCSettingsDialog, self).__init__(window, title)
                self.setMaximumWidth(540)
       t@@ -104,6 +105,8 @@ class CKCCSettingsDialog(WindowModalDialog):
                #handler = keystore.handler
                self.thread = thread = keystore.thread
                self.keystore = keystore
       +        assert isinstance(window, ElectrumWindow), f"{type(window)}"
       +        self.window = window
        
                def connect_and_doit():
                    # Attempt connection to device, or raise.
       t@@ -188,7 +191,7 @@ class CKCCSettingsDialog(WindowModalDialog):
        
            def start_upgrade(self, client):
                # ask for a filename (must have already downloaded it)
       -        mw = get_parent_main_window(self)
       +        mw = self.window
                dev = client.dev
        
                fileName = mw.getOpenFileName("Select upgraded firmware file", "*.dfu")
   DIR diff --git a/electrum/plugins/email_requests/qt.py b/electrum/plugins/email_requests/qt.py
       t@@ -43,7 +43,7 @@ from PyQt5.QtWidgets import (QVBoxLayout, QLabel, QGridLayout, QLineEdit,
                                     QInputDialog)
        
        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.plugin import BasePlugin, hook
       t@@ -176,8 +176,7 @@ class Plugin(BasePlugin):
                #main_window.invoice_list.update()
        
            @hook
       -    def receive_list_menu(self, menu, addr):
       -        window = get_parent_main_window(menu)
       +    def receive_list_menu(self, window: ElectrumWindow, menu, addr):
                menu.addAction(_("Send via e-mail"), lambda: self.send(window, addr))
        
            def send(self, window: ElectrumWindow, addr):
   DIR diff --git a/electrum/plugins/revealer/qt.py b/electrum/plugins/revealer/qt.py
       t@@ -116,7 +116,7 @@ class Plugin(RevealerPlugin):
                bcreate.setMaximumWidth(181)
                bcreate.setDefault(True)
                vbox.addWidget(bcreate, Qt.AlignCenter)
       -        self.load_noise = ScanQRTextEdit()
       +        self.load_noise = ScanQRTextEdit(config=self.config)
                self.load_noise.setTabChangesFocus(True)
                self.load_noise.textChanged.connect(self.on_edit)
                self.load_noise.setMaximumHeight(33)
       t@@ -253,7 +253,7 @@ class Plugin(RevealerPlugin):
                self.vbox.addWidget(cprint)
                self.vbox.addSpacing(1)
                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.setMaximumHeight(70)
                self.text.textChanged.connect(self.customtxt_limits)