Browse Source

qt: consistently show tooltip when copying to clipboard

hard-fail-on-bad-server-string
SomberNight 5 years ago
parent
commit
1526bc9ccf
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 4
      electrum/gui/qt/address_list.py
  2. 2
      electrum/gui/qt/contact_list.py
  3. 6
      electrum/gui/qt/history_list.py
  4. 10
      electrum/gui/qt/main_window.py
  5. 6
      electrum/gui/qt/request_list.py
  6. 2
      electrum/gui/qt/transaction_dialog.py
  7. 8
      electrum/gui/qt/util.py

4
electrum/gui/qt/address_list.py

@ -251,11 +251,11 @@ class AddressList(MyTreeView):
run_hook('receive_menu', menu, addrs, self.wallet) run_hook('receive_menu', menu, addrs, self.wallet)
menu.exec_(self.viewport().mapToGlobal(position)) 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): if is_address(text):
try: try:
self.wallet.check_address(text) self.wallet.check_address(text)
except InternalAddressCorruption as e: except InternalAddressCorruption as e:
self.parent.show_error(str(e)) self.parent.show_error(str(e))
raise raise
self.parent.app.clipboard().setText(text) super().place_text_on_clipboard(text, title=title)

2
electrum/gui/qt/contact_list.py

@ -85,7 +85,7 @@ class ContactList(MyTreeView):
column_title = self.model().horizontalHeaderItem(column).text() column_title = self.model().horizontalHeaderItem(column).text()
column_data = '\n'.join(self.model().itemFromIndex(s_idx).text() column_data = '\n'.join(self.model().itemFromIndex(s_idx).text()
for s_idx in self.selected_in_column(column)) 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: if column in self.editable_columns:
item = self.model().itemFromIndex(idx) item = self.model().itemFromIndex(idx)
if item.isEditable(): if item.isEditable():

6
electrum/gui/qt/history_list.py

@ -597,7 +597,9 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
column_title = self.hm.headerData(column, Qt.Horizontal, Qt.DisplayRole) column_title = self.hm.headerData(column, Qt.Horizontal, Qt.DisplayRole)
idx2 = idx.sibling(idx.row(), column) idx2 = idx.sibling(idx.row(), column)
column_data = (self.hm.data(idx2, Qt.DisplayRole).value() or '').strip() 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): def create_menu(self, position: QPoint):
org_idx: QModelIndex = self.indexAt(position) org_idx: QModelIndex = self.indexAt(position)
@ -620,7 +622,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
menu = QMenu() menu = QMenu()
if height in [TX_HEIGHT_FUTURE, TX_HEIGHT_LOCAL]: if height in [TX_HEIGHT_FUTURE, TX_HEIGHT_LOCAL]:
menu.addAction(_("Remove"), lambda: self.remove_local_tx(tx_hash)) 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) self.add_copy_menu(menu, idx)
for c in self.editable_columns: for c in self.editable_columns:
if self.isColumnHidden(c): continue if self.isColumnHidden(c): continue

10
electrum/gui/qt/main_window.py

@ -45,7 +45,7 @@ from PyQt5.QtWidgets import (QMessageBox, QComboBox, QSystemTrayIcon, QTabWidget
QVBoxLayout, QGridLayout, QLineEdit, QVBoxLayout, QGridLayout, QLineEdit,
QHBoxLayout, QPushButton, QScrollArea, QTextEdit, QHBoxLayout, QPushButton, QScrollArea, QTextEdit,
QShortcut, QMainWindow, QCompleter, QInputDialog, QShortcut, QMainWindow, QCompleter, QInputDialog,
QWidget, QSizePolicy, QStatusBar) QWidget, QSizePolicy, QStatusBar, QToolTip)
import electrum import electrum
from electrum import (keystore, ecc, constants, util, bitcoin, commands, from electrum import (keystore, ecc, constants, util, bitcoin, commands,
@ -1115,9 +1115,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.sign_payment_request(addr) self.sign_payment_request(addr)
return 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.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): def export_payment_request(self, addr):
r = self.wallet.receive_requests.get(addr) r = self.wallet.receive_requests.get(addr)

6
electrum/gui/qt/request_list.py

@ -161,10 +161,10 @@ class RequestList(MyTreeView):
menu = QMenu(self) menu = QMenu(self)
self.add_copy_menu(menu, idx) self.add_copy_menu(menu, idx)
if request_type == PR_TYPE_LN: 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: else:
menu.addAction(_("Copy Request"), lambda: self.parent.do_copy('Bitcoin URI', req['URI'])) menu.addAction(_("Copy Request"), lambda: self.parent.do_copy(req['URI'], title='Bitcoin URI'))
menu.addAction(_("Copy Address"), lambda: self.parent.do_copy('Bitcoin Address', req['address'])) menu.addAction(_("Copy Address"), lambda: self.parent.do_copy(req['address'], title='Bitcoin Address'))
if 'view_url' in req: if 'view_url' in req:
menu.addAction(_("View in web browser"), lambda: webopen(req['view_url'])) 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_request(key))

2
electrum/gui/qt/transaction_dialog.py

@ -261,7 +261,7 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
def copy_to_clipboard(self, *, tx: Transaction = None): def copy_to_clipboard(self, *, tx: Transaction = None):
if tx is None: if tx is None:
tx = self.tx 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): def show_qr(self, *, tx: Transaction = None):
if tx is None: if tx is None:

8
electrum/gui/qt/util.py

@ -634,10 +634,12 @@ class MyTreeView(QTreeView):
column_title = self.model().horizontalHeaderItem(column).text() column_title = self.model().horizontalHeaderItem(column).text()
item_col = self.model().itemFromIndex(idx.sibling(idx.row(), column)) item_col = self.model().itemFromIndex(idx.sibling(idx.row(), column))
column_data = item_col.text().strip() 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): def place_text_on_clipboard(self, text: str, *, title: str = None) -> None:
self.parent.app.clipboard().setText(text) self.parent.do_copy(text, title=title)
class ButtonsWidget(QWidget): class ButtonsWidget(QWidget):

Loading…
Cancel
Save