commit 1526bc9ccf1125cd2c8c650748116050da95d778
parent 9fe79171186e9e98aab266282c055a90dac9de18
Author: SomberNight <somber.night@protonmail.com>
Date: Thu, 21 Nov 2019 03:01:55 +0100
qt: consistently show tooltip when copying to clipboard
Diffstat:
7 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/electrum/gui/qt/address_list.py b/electrum/gui/qt/address_list.py
@@ -251,11 +251,11 @@ class AddressList(MyTreeView):
run_hook('receive_menu', menu, addrs, self.wallet)
menu.exec_(self.viewport().mapToGlobal(position))
- def place_text_on_clipboard(self, text):
+ def place_text_on_clipboard(self, text: str, *, title: str = None) -> None:
if is_address(text):
try:
self.wallet.check_address(text)
except InternalAddressCorruption as e:
self.parent.show_error(str(e))
raise
- self.parent.app.clipboard().setText(text)
+ super().place_text_on_clipboard(text, title=title)
diff --git a/electrum/gui/qt/contact_list.py b/electrum/gui/qt/contact_list.py
@@ -85,7 +85,7 @@ class ContactList(MyTreeView):
column_title = self.model().horizontalHeaderItem(column).text()
column_data = '\n'.join(self.model().itemFromIndex(s_idx).text()
for s_idx in self.selected_in_column(column))
- menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data))
+ menu.addAction(_("Copy {}").format(column_title), lambda: self.place_text_on_clipboard(column_data, title=column_title))
if column in self.editable_columns:
item = self.model().itemFromIndex(idx)
if item.isEditable():
diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py
@@ -597,7 +597,9 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
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))
+ cc.addAction(column_title,
+ lambda text=column_data, title=column_title:
+ self.place_text_on_clipboard(text, title=title))
def create_menu(self, position: QPoint):
org_idx: QModelIndex = self.indexAt(position)
@@ -620,7 +622,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
menu = QMenu()
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))
+ menu.addAction(_("Copy Transaction ID"), lambda: self.place_text_on_clipboard(tx_hash, title="TXID"))
self.add_copy_menu(menu, idx)
for c in self.editable_columns:
if self.isColumnHidden(c): continue
diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
@@ -45,7 +45,7 @@ from PyQt5.QtWidgets import (QMessageBox, QComboBox, QSystemTrayIcon, QTabWidget
QVBoxLayout, QGridLayout, QLineEdit,
QHBoxLayout, QPushButton, QScrollArea, QTextEdit,
QShortcut, QMainWindow, QCompleter, QInputDialog,
- QWidget, QSizePolicy, QStatusBar)
+ QWidget, QSizePolicy, QStatusBar, QToolTip)
import electrum
from electrum import (keystore, ecc, constants, util, bitcoin, commands,
@@ -1115,9 +1115,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.sign_payment_request(addr)
return addr
- def do_copy(self, title, content):
+ def do_copy(self, content: str, *, title: str = None) -> None:
self.app.clipboard().setText(content)
- self.show_message(_(f"{title} copied to clipboard:\n\n{content}"))
+ if title is None:
+ tooltip_text = _("Text copied to clipboard").format(title)
+ else:
+ tooltip_text = _("{} copied to clipboard").format(title)
+ QToolTip.showText(QCursor.pos(), tooltip_text, self)
def export_payment_request(self, addr):
r = self.wallet.receive_requests.get(addr)
diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py
@@ -161,10 +161,10 @@ class RequestList(MyTreeView):
menu = QMenu(self)
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']))
+ menu.addAction(_("Copy Request"), lambda: self.parent.do_copy(req['invoice'], title='Lightning Request'))
else:
- menu.addAction(_("Copy Request"), lambda: self.parent.do_copy('Bitcoin URI', req['URI']))
- menu.addAction(_("Copy Address"), lambda: self.parent.do_copy('Bitcoin Address', req['address']))
+ menu.addAction(_("Copy Request"), lambda: self.parent.do_copy(req['URI'], title='Bitcoin URI'))
+ 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))
diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py
@@ -261,7 +261,7 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
def copy_to_clipboard(self, *, tx: Transaction = None):
if tx is None:
tx = self.tx
- self.main_window.app.clipboard().setText(str(tx))
+ self.main_window.do_copy(str(tx), title=_("Transaction"))
def show_qr(self, *, tx: Transaction = None):
if tx is None:
diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py
@@ -634,10 +634,12 @@ class MyTreeView(QTreeView):
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.place_text_on_clipboard(t))
+ cc.addAction(column_title,
+ lambda text=column_data, title=column_title:
+ self.place_text_on_clipboard(text, title=title))
- def place_text_on_clipboard(self, text):
- self.parent.app.clipboard().setText(text)
+ def place_text_on_clipboard(self, text: str, *, title: str = None) -> None:
+ self.parent.do_copy(text, title=title)
class ButtonsWidget(QWidget):