commit f67011d47753a94759c5040ac211161011689140
parent 89fa9b50907891bbf82d701f6991b95c722e324f
Author: ThomasV <thomasv@electrum.org>
Date: Tue, 3 Mar 2020 12:56:44 +0100
Qt: do not filter out paid invoices/requests. let user delete multiple items
Diffstat:
3 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/electrum/gui/qt/invoice_list.py b/electrum/gui/qt/invoice_list.py
@@ -92,14 +92,9 @@ class InvoiceList(MyTreeView):
def update(self):
# not calling maybe_defer_update() as it interferes with conditional-visibility
- _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 {}
- _list = [x for x in _list
- if x and (x.get('status') != PR_PAID or x.get('rhash') in lnworker_logs)]
self.model().clear()
self.update_headers(self.__class__.headers)
- for idx, item in enumerate(_list):
+ for idx, item in enumerate(self.parent.wallet.get_invoices()):
invoice_type = item['type']
if invoice_type == PR_TYPE_LN:
key = item['rhash']
@@ -148,10 +143,11 @@ class InvoiceList(MyTreeView):
keys = [ item.data(ROLE_REQUEST_ID) for item in items]
invoices = [ self.parent.wallet.get_invoice(key) for key in keys]
invoices = [ invoice for invoice in invoices if invoice['status'] == PR_UNPAID and invoice['type'] == PR_TYPE_ONCHAIN]
+ menu = QMenu(self)
if len(invoices) > 1:
- menu = QMenu(self)
menu.addAction(_("Pay multiple invoices"), lambda: self.parent.pay_multiple_invoices(invoices))
- menu.exec_(self.viewport().mapToGlobal(position))
+ menu.addAction(_("Delete"), lambda: self.parent.delete_invoices(keys))
+ menu.exec_(self.viewport().mapToGlobal(position))
return
idx = self.indexAt(position)
item = self.model().itemFromIndex(idx)
@@ -172,7 +168,7 @@ class InvoiceList(MyTreeView):
log = self.parent.wallet.lnworker.logs.get(key)
if log:
menu.addAction(_("View log"), lambda: self.show_log(key, log))
- menu.addAction(_("Delete"), lambda: self.parent.delete_invoice(key))
+ menu.addAction(_("Delete invoices"), lambda: self.parent.delete_invoices([key]))
menu.exec_(self.viewport().mapToGlobal(position))
def show_log(self, key, log: Sequence[PaymentAttemptLog]):
diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
@@ -1103,8 +1103,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
return w
- def delete_request(self, key):
- self.wallet.delete_request(key)
+ def delete_requests(self, keys):
+ for key in keys:
+ self.wallet.delete_request(key)
self.request_list.update()
self.clear_receive_tab()
@@ -1713,8 +1714,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.payto_e.setText(_("please wait..."))
return True
- def delete_invoice(self, key):
- self.wallet.delete_invoice(key)
+ def delete_invoices(self, keys):
+ for key in keys:
+ self.wallet.delete_invoice(key)
self.invoice_list.update()
def payment_request_ok(self):
diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py
@@ -29,6 +29,7 @@ from typing import Optional
from PyQt5.QtGui import QStandardItemModel, QStandardItem
from PyQt5.QtWidgets import QMenu
from PyQt5.QtCore import Qt, QItemSelectionModel, QModelIndex
+from PyQt5.QtWidgets import QAbstractItemView
from electrum.i18n import _
from electrum.util import format_time, get_request_status
@@ -65,8 +66,9 @@ class RequestList(MyTreeView):
self.wallet = self.parent.wallet
self.setModel(QStandardItemModel(self))
self.setSortingEnabled(True)
- self.update()
self.selectionModel().currentRowChanged.connect(self.item_changed)
+ self.setSelectionMode(QAbstractItemView.ExtendedSelection)
+ self.update()
def select_key(self, key):
for i in range(self.model().rowCount()):
@@ -124,8 +126,6 @@ class RequestList(MyTreeView):
self.update_headers(self.__class__.headers)
for req in self.wallet.get_sorted_requests():
status, status_str = get_request_status(req)
- if status == PR_PAID:
- continue
request_type = req['type']
timestamp = req.get('time', 0)
amount = req.get('amount')
@@ -162,6 +162,13 @@ class RequestList(MyTreeView):
self.item_changed(None)
def create_menu(self, position):
+ items = self.selected_in_column(0)
+ if len(items)>1:
+ keys = [ item.data(ROLE_KEY) for item in items]
+ menu = QMenu(self)
+ menu.addAction(_("Delete requests"), lambda: self.parent.delete_requests(keys))
+ menu.exec_(self.viewport().mapToGlobal(position))
+ return
idx = self.indexAt(position)
item = self.model().itemFromIndex(idx)
# TODO use siblingAtColumn when min Qt version is >=5.11
@@ -183,6 +190,6 @@ class RequestList(MyTreeView):
menu.addAction(_("Copy Address"), lambda: self.parent.do_copy(req['address'], title='Bitcoin Address'))
if 'view_url' in req:
menu.addAction(_("View in web browser"), lambda: webopen(req['view_url']))
- menu.addAction(_("Delete"), lambda: self.parent.delete_request(key))
+ menu.addAction(_("Delete"), lambda: self.parent.delete_requests([key]))
run_hook('receive_list_menu', menu, key)
menu.exec_(self.viewport().mapToGlobal(position))