commit 1d0fc6665bbd4d2310c20d54e0c8d9fd224c4ca8
parent 356a0a2865a4ee319e7cc03dabd0ffd1c34e3077
Author: SomberNight <somber.night@protonmail.com>
Date: Sun, 19 Jan 2020 07:31:50 +0100
qt: defer refreshing tabs until they are visible
very loosely based on Electron-Cash/Electron-Cash@522e7ca59e5d31f10473064f2149b6c6f9049649
Diffstat:
7 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/electrum/gui/qt/address_list.py b/electrum/gui/qt/address_list.py
@@ -137,6 +137,8 @@ class AddressList(MyTreeView):
@profiler
def update(self):
+ if self.maybe_defer_update():
+ return
current_address = self.current_item_user_role(col=self.Columns.LABEL)
if self.show_change == AddressTypeFilter.RECEIVING:
addr_list = self.wallet.get_receiving_addresses()
diff --git a/electrum/gui/qt/contact_list.py b/electrum/gui/qt/contact_list.py
@@ -102,6 +102,8 @@ class ContactList(MyTreeView):
menu.exec_(self.viewport().mapToGlobal(position))
def update(self):
+ if self.maybe_defer_update():
+ return
current_key = self.current_item_user_role(col=self.Columns.NAME)
self.model().clear()
self.update_headers(self.__class__.headers)
diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py
@@ -264,6 +264,8 @@ class HistoryModel(QAbstractItemModel, Logger):
self.logger.info(f"refreshing... reason: {reason}")
assert self.parent.gui_thread == threading.current_thread(), 'must be called from GUI thread'
assert self.view, 'view not set'
+ if self.view.maybe_defer_update():
+ return
selected = self.view.selectionModel().currentIndex()
selected_row = None
if selected:
@@ -430,6 +432,9 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
sm = QHeaderView.Stretch if col == self.stretch_column else QHeaderView.ResizeToContents
self.header().setSectionResizeMode(col, sm)
+ def update(self):
+ self.hm.refresh('HistoryList.update()')
+
def format_date(self, d):
return str(datetime.date(d.year, d.month, d.day)) if d else _('None')
diff --git a/electrum/gui/qt/invoice_list.py b/electrum/gui/qt/invoice_list.py
@@ -94,6 +94,8 @@ class InvoiceList(MyTreeView):
status_item.setIcon(read_QIcon(pr_icons.get(status)))
def update(self):
+ if self.maybe_defer_update():
+ return
_list = self.parent.wallet.get_invoices()
# filter out paid invoices unless we have the log
lnworker_logs = self.parent.wallet.lnworker.logs if self.parent.wallet.lnworker else {}
diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py
@@ -107,6 +107,8 @@ class RequestList(MyTreeView):
status_item.setIcon(read_QIcon(pr_icons.get(status)))
def update(self):
+ if self.maybe_defer_update():
+ return
self.parent.update_receive_address_styling()
self.model().clear()
self.update_headers(self.__class__.headers)
diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py
@@ -12,7 +12,7 @@ from functools import partial, lru_cache
from typing import NamedTuple, Callable, Optional, TYPE_CHECKING, Union, List, Dict, Any
from PyQt5.QtGui import (QFont, QColor, QCursor, QPixmap, QStandardItem,
- QPalette, QIcon, QFontMetrics)
+ QPalette, QIcon, QFontMetrics, QShowEvent)
from PyQt5.QtCore import (Qt, QPersistentModelIndex, QModelIndex, pyqtSignal,
QCoreApplication, QItemSelectionModel, QThread,
QSortFilterProxyModel, QSize, QLocale)
@@ -513,6 +513,9 @@ class MyTreeView(QTreeView):
# only look at as many rows as currently visible.
self.header().setResizeContentsPrecision(0)
+ self._pending_update = False
+ self._forced_update = False
+
def set_editability(self, items):
for idx, i in enumerate(items):
i.setEditable(idx in self.editable_columns)
@@ -664,6 +667,20 @@ class MyTreeView(QTreeView):
def place_text_on_clipboard(self, text: str, *, title: str = None) -> None:
self.parent.do_copy(text, title=title)
+ def showEvent(self, e: 'QShowEvent'):
+ super().showEvent(e)
+ if e.isAccepted() and self._pending_update:
+ self._forced_update = True
+ self.update()
+ self._forced_update = False
+
+ def maybe_defer_update(self) -> bool:
+ """Returns whether we should defer an update/refresh."""
+ defer = not self.isVisible() and not self._forced_update
+ # side-effect: if we decide to defer update, the state will become stale:
+ self._pending_update = defer
+ return defer
+
class ButtonsWidget(QWidget):
diff --git a/electrum/gui/qt/utxo_list.py b/electrum/gui/qt/utxo_list.py
@@ -71,6 +71,8 @@ class UTXOList(MyTreeView):
self.update()
def update(self):
+ if self.maybe_defer_update():
+ return
utxos = self.wallet.get_utxos()
self._maybe_reset_spend_list(utxos)
self._utxo_dict = {}