commit c721e880d0e203c770328d0830a37bd78eeae0e2
parent 0a6ac7c61a8a1026fa4cda72f11d17b61629f9c1
Author: ThomasV <thomasv@electrum.org>
Date: Wed, 16 Oct 2019 15:50:18 +0200
Qt: generic add_copy_menu method for MyTreeView lists
Diffstat:
7 files changed, 21 insertions(+), 36 deletions(-)
diff --git a/electrum/gui/qt/address_list.py b/electrum/gui/qt/address_list.py
@@ -217,20 +217,13 @@ class AddressList(MyTreeView):
idx = self.indexAt(position)
if not idx.isValid():
return
- col = idx.column()
item = self.model().itemFromIndex(idx)
if not item:
return
addr = addrs[0]
-
addr_column_title = self.model().horizontalHeaderItem(self.Columns.LABEL).text()
addr_idx = idx.sibling(idx.row(), self.Columns.LABEL)
-
- column_title = self.model().horizontalHeaderItem(col).text()
- copy_text = self.model().itemFromIndex(idx).text()
- if col == self.Columns.COIN_BALANCE or col == self.Columns.FIAT_BALANCE:
- copy_text = copy_text.strip()
- menu.addAction(_("Copy {}").format(column_title), lambda: self.place_text_on_clipboard(copy_text))
+ self.add_copy_menu(menu, idx)
menu.addAction(_('Details'), lambda: self.parent.show_address(addr))
persistent = QPersistentModelIndex(addr_idx)
menu.addAction(_("Edit {}").format(addr_column_title), lambda p=persistent: self.edit(QModelIndex(p)))
diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py
@@ -103,6 +103,7 @@ class ChannelsList(MyTreeView):
channel_id = idx.sibling(idx.row(), self.Columns.NODE_ID).data(ROLE_CHANNEL_ID)
chan = self.lnworker.channels[channel_id]
menu.addAction(_("Details..."), lambda: self.details(channel_id))
+ self.add_copy_menu(menu, idx)
if not chan.is_closed():
menu.addAction(_("Close channel"), lambda: self.close_channel(channel_id))
menu.addAction(_("Force-close channel"), lambda: self.force_close(channel_id))
diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py
@@ -589,6 +589,14 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
label = self.wallet.get_label(tx_hash) or None # prefer 'None' if not defined (force tx dialog to hide Description field if missing)
self.parent.show_transaction(tx, label)
+ def add_copy_menu(self, menu, idx):
+ cc = menu.addMenu(_("Copy column"))
+ for column in HistoryColumns:
+ column_title = self.hm.headerData(column, Qt.Horizontal, Qt.DisplayRole)
+ idx2 = idx.sibling(idx.row(), column)
+ column_data = (self.hm.data(idx2, Qt.DisplayRole).value() or '').strip()
+ cc.addAction(column_title, lambda t=column_data: self.parent.app.clipboard().setText(t))
+
def create_menu(self, position: QPoint):
org_idx: QModelIndex = self.indexAt(position)
idx = self.proxy.mapToSource(org_idx)
@@ -596,9 +604,6 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
# can happen e.g. before list is populated for the first time
return
tx_item = self.hm.transactions.value_from_pos(idx.row())
- column = idx.column()
- column_title = self.hm.headerData(column, Qt.Horizontal, Qt.DisplayRole)
- column_data = self.hm.data(idx, Qt.DisplayRole).value()
if tx_item.get('lightning'):
return
tx_hash = tx_item['txid']
@@ -614,12 +619,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
if height in [TX_HEIGHT_FUTURE, TX_HEIGHT_LOCAL]:
menu.addAction(_("Remove"), lambda: self.remove_local_tx(tx_hash))
menu.addAction(_("Copy Transaction ID"), lambda: self.parent.app.clipboard().setText(tx_hash))
-
- amount_columns = [HistoryColumns.AMOUNT, HistoryColumns.BALANCE,
- HistoryColumns.FIAT_VALUE, HistoryColumns.FIAT_ACQ_PRICE, HistoryColumns.FIAT_CAP_GAINS]
- if column in amount_columns:
- column_data = column_data.strip()
- menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data))
+ self.add_copy_menu(menu, idx)
for c in self.editable_columns:
if self.isColumnHidden(c): continue
label = self.hm.headerData(c, Qt.Horizontal, Qt.DisplayRole)
diff --git a/electrum/gui/qt/invoice_list.py b/electrum/gui/qt/invoice_list.py
@@ -151,14 +151,8 @@ class InvoiceList(MyTreeView):
return
key = item_col0.data(ROLE_REQUEST_ID)
request_type = item_col0.data(ROLE_REQUEST_TYPE)
- column = idx.column()
- column_title = self.model().horizontalHeaderItem(column).text()
- column_data = item.text()
menu = QMenu(self)
- if column_data:
- if column == self.Columns.AMOUNT:
- column_data = column_data.strip()
- menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data))
+ self.add_copy_menu(menu, idx)
invoice = self.parent.wallet.get_invoice(key)
menu.addAction(_("Details"), lambda: self.parent.show_invoice(key))
if invoice['status'] == PR_UNPAID:
diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py
@@ -165,13 +165,8 @@ class RequestList(MyTreeView):
if req is None:
self.update()
return
- column = idx.column()
- column_title = self.model().horizontalHeaderItem(column).text()
- column_data = self.model().itemFromIndex(idx).text()
menu = QMenu(self)
- if column == self.Columns.AMOUNT:
- column_data = column_data.strip()
- menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.do_copy(column_title, column_data))
+ self.add_copy_menu(menu, idx)
if request_type == PR_TYPE_LN:
menu.addAction(_("Copy Request"), lambda: self.parent.do_copy('Lightning Request', req['invoice']))
else:
diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py
@@ -626,6 +626,13 @@ class MyTreeView(QTreeView):
def toggle_toolbar(self, config=None):
self.show_toolbar(not self.toolbar_shown, config)
+ def add_copy_menu(self, menu, idx):
+ cc = menu.addMenu(_("Copy column"))
+ for column in self.Columns:
+ column_title = self.model().horizontalHeaderItem(column).text()
+ item_col = self.model().itemFromIndex(idx.sibling(idx.row(), column))
+ column_data = item_col.text().strip()
+ cc.addAction(column_title, lambda t=column_data: self.parent.app.clipboard().setText(t))
class ButtonsWidget(QWidget):
diff --git a/electrum/gui/qt/utxo_list.py b/electrum/gui/qt/utxo_list.py
@@ -126,12 +126,7 @@ class UTXOList(MyTreeView):
idx = self.indexAt(position)
if not idx.isValid():
return
- col = idx.column()
- column_title = self.model().horizontalHeaderItem(col).text()
- copy_text = self.model().itemFromIndex(idx).text() if col != self.Columns.OUTPOINT else selected[0]
- if col == self.Columns.AMOUNT:
- copy_text = copy_text.strip()
- menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(copy_text))
+ self.add_copy_menu(menu, idx)
# "Freeze coin"
if not self.wallet.is_frozen_coin(utxo_dict):
menu.addAction(_("Freeze Coin"), lambda: self.parent.set_frozen_state_of_coins([utxo_dict], True))