Browse Source

qt: defer refreshing tabs until they are visible

very loosely based on Electron-Cash/Electron-Cash@522e7ca59e5d31f10473064f2149b6c6f9049649
hard-fail-on-bad-server-string
SomberNight 5 years ago
parent
commit
1d0fc6665b
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/gui/qt/address_list.py
  2. 2
      electrum/gui/qt/contact_list.py
  3. 5
      electrum/gui/qt/history_list.py
  4. 2
      electrum/gui/qt/invoice_list.py
  5. 2
      electrum/gui/qt/request_list.py
  6. 19
      electrum/gui/qt/util.py
  7. 2
      electrum/gui/qt/utxo_list.py

2
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()

2
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)

5
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')

2
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 {}

2
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)

19
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):

2
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 = {}

Loading…
Cancel
Save