diff --git a/gui/qt/history_list.py b/gui/qt/history_list.py index 1af2ff97c..8b4baf575 100644 --- a/gui/qt/history_list.py +++ b/gui/qt/history_list.py @@ -235,7 +235,7 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop): label = tx_item['label'] status, status_str = self.wallet.get_tx_status(tx_hash, height, conf, timestamp) has_invoice = self.wallet.invoices.paid.get(tx_hash) - icon = QIcon(":icons/" + TX_ICONS[status]) + icon = self.icon_cache.get(":icons/" + TX_ICONS[status]) v_str = self.parent.format_amount(value, True, whitespaces=True) balance_str = self.parent.format_amount(balance, whitespaces=True) entry = ['', tx_hash, status_str, label, v_str, balance_str] @@ -253,7 +253,7 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop): item.setToolTip(0, str(conf) + " confirmation" + ("s" if conf != 1 else "")) item.setData(0, SortableTreeWidgetItem.DataRole, (status, conf)) if has_invoice: - item.setIcon(3, QIcon(":icons/seal")) + item.setIcon(3, self.icon_cache.get(":icons/seal")) for i in range(len(entry)): if i>3: item.setTextAlignment(i, Qt.AlignRight | Qt.AlignVCenter) @@ -302,7 +302,7 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop): def update_item(self, tx_hash, height, conf, timestamp): status, status_str = self.wallet.get_tx_status(tx_hash, height, conf, timestamp) - icon = QIcon(":icons/" + TX_ICONS[status]) + icon = self.icon_cache.get(":icons/" + TX_ICONS[status]) items = self.findItems(tx_hash, Qt.UserRole|Qt.MatchContains|Qt.MatchRecursive, column=1) if items: item = items[0] @@ -347,7 +347,7 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop): if child_tx: menu.addAction(_("Child pays for parent"), lambda: self.parent.cpfp(tx, child_tx)) if pr_key: - menu.addAction(QIcon(":icons/seal"), _("View invoice"), lambda: self.parent.show_invoice(pr_key)) + menu.addAction(self.icon_cache.get(":icons/seal"), _("View invoice"), lambda: self.parent.show_invoice(pr_key)) if tx_URL: menu.addAction(_("View on block explorer"), lambda: webbrowser.open(tx_URL)) menu.exec_(self.viewport().mapToGlobal(position)) diff --git a/gui/qt/invoice_list.py b/gui/qt/invoice_list.py index 586dd71c5..462aadd85 100644 --- a/gui/qt/invoice_list.py +++ b/gui/qt/invoice_list.py @@ -48,7 +48,7 @@ class InvoiceList(MyTreeWidget): exp = pr.get_expiration_date() date_str = format_time(exp) if exp else _('Never') item = QTreeWidgetItem([date_str, requestor, pr.memo, self.parent.format_amount(pr.get_amount(), whitespaces=True), pr_tooltips.get(status,'')]) - item.setIcon(4, QIcon(pr_icons.get(status))) + item.setIcon(4, self.icon_cache.get(pr_icons.get(status))) item.setData(0, Qt.UserRole, key) item.setFont(1, QFont(MONOSPACE_FONT)) item.setFont(3, QFont(MONOSPACE_FONT)) diff --git a/gui/qt/request_list.py b/gui/qt/request_list.py index 59b084ff9..dacae503e 100644 --- a/gui/qt/request_list.py +++ b/gui/qt/request_list.py @@ -98,10 +98,10 @@ class RequestList(MyTreeWidget): amount_str = self.parent.format_amount(amount) if amount else "" item = QTreeWidgetItem([date, address, '', message, amount_str, pr_tooltips.get(status,'')]) if signature is not None: - item.setIcon(2, QIcon(":icons/seal.png")) + item.setIcon(2, self.icon_cache.get(":icons/seal.png")) item.setToolTip(2, 'signed by '+ requestor) if status is not PR_UNKNOWN: - item.setIcon(6, QIcon(pr_icons.get(status))) + item.setIcon(6, self.icon_cache.get(pr_icons.get(status))) self.addTopLevelItem(item) diff --git a/gui/qt/util.py b/gui/qt/util.py index 306c64a55..b8fc1cdae 100644 --- a/gui/qt/util.py +++ b/gui/qt/util.py @@ -393,6 +393,8 @@ class MyTreeWidget(QTreeWidget): self.addChild = self.addTopLevelItem self.insertChild = self.insertTopLevelItem + self.icon_cache = IconCache() + # Control which columns are editable self.editor = None self.pending_update = False @@ -779,6 +781,17 @@ class SortableTreeWidgetItem(QTreeWidgetItem): return self.text(column) < other.text(column) +class IconCache: + + def __init__(self): + self.__cache = {} + + def get(self, file_name): + if file_name not in self.__cache: + self.__cache[file_name] = QIcon(file_name) + return self.__cache[file_name] + + if __name__ == "__main__": app = QApplication([]) t = WaitingDialog(None, 'testing ...', lambda: [time.sleep(1)], lambda x: QMessageBox.information(None, 'done', "done"))