mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
qt: defer refreshing tabs until they are visible
very loosely based on Electron-Cash/Electron-Cash@522e7ca59e
This commit is contained in:
parent
356a0a2865
commit
1d0fc6665b
7 changed files with 33 additions and 1 deletions
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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 {}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue