Merge pull request #8479 from thomasleveil/feat_copy_numbers
✨ remove thousand separator when copying numbers to clipboard
This commit is contained in:
@@ -852,11 +852,22 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
|||||||
self.send_tab.payto_e.on_timer_check_text()
|
self.send_tab.payto_e.on_timer_check_text()
|
||||||
self.notify_transactions()
|
self.notify_transactions()
|
||||||
|
|
||||||
def format_amount(self, amount_sat, is_diff=False, whitespaces=False) -> str:
|
def format_amount(
|
||||||
|
self,
|
||||||
|
amount_sat,
|
||||||
|
is_diff=False,
|
||||||
|
whitespaces=False,
|
||||||
|
ignore_thousands_sep: bool = False,
|
||||||
|
) -> str:
|
||||||
"""Formats amount as string, converting to desired unit.
|
"""Formats amount as string, converting to desired unit.
|
||||||
E.g. 500_000 -> '0.005'
|
E.g. 500_000 -> '0.005'
|
||||||
"""
|
"""
|
||||||
return self.config.format_amount(amount_sat, is_diff=is_diff, whitespaces=whitespaces)
|
return self.config.format_amount(
|
||||||
|
amount_sat,
|
||||||
|
is_diff=is_diff,
|
||||||
|
whitespaces=whitespaces,
|
||||||
|
ignore_thousands_sep=ignore_thousands_sep,
|
||||||
|
)
|
||||||
|
|
||||||
def format_amount_and_units(self, amount_sat, *, timestamp: int = None) -> str:
|
def format_amount_and_units(self, amount_sat, *, timestamp: int = None) -> str:
|
||||||
"""Returns string with both bitcoin and fiat amounts, in desired units.
|
"""Returns string with both bitcoin and fiat amounts, in desired units.
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import contextlib
|
||||||
import enum
|
import enum
|
||||||
import os.path
|
import os.path
|
||||||
import time
|
import time
|
||||||
@@ -451,6 +452,13 @@ class MyTreeView(QTreeView):
|
|||||||
return cc
|
return cc
|
||||||
|
|
||||||
def place_text_on_clipboard(self, text: str, *, title: str = None) -> None:
|
def place_text_on_clipboard(self, text: str, *, title: str = None) -> None:
|
||||||
|
if title in {
|
||||||
|
"Amount",
|
||||||
|
"Balance",
|
||||||
|
} or title.endswith(" Value") or title.endswith(" Acquisition price") or title.endswith(" Capital Gains"):
|
||||||
|
with contextlib.suppress(Exception):
|
||||||
|
# remove formatting for numbers
|
||||||
|
text = text.replace(" ", "")
|
||||||
self.main_window.do_copy(text, title=title)
|
self.main_window.do_copy(text, title=title)
|
||||||
|
|
||||||
def showEvent(self, e: 'QShowEvent'):
|
def showEvent(self, e: 'QShowEvent'):
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ class TxInOutWidget(QWidget):
|
|||||||
copy_list += [(_("Copy Address"), lambda: self.main_window.do_copy(addr))]
|
copy_list += [(_("Copy Address"), lambda: self.main_window.do_copy(addr))]
|
||||||
txin_value = self.wallet.adb.get_txin_value(txin)
|
txin_value = self.wallet.adb.get_txin_value(txin)
|
||||||
if txin_value:
|
if txin_value:
|
||||||
value_str = self.main_window.format_amount(txin_value)
|
value_str = self.main_window.format_amount(txin_value, ignore_thousands_sep=True)
|
||||||
copy_list += [(_("Copy Amount"), lambda: self.main_window.do_copy(value_str))]
|
copy_list += [(_("Copy Amount"), lambda: self.main_window.do_copy(value_str))]
|
||||||
|
|
||||||
for item in show_list:
|
for item in show_list:
|
||||||
@@ -356,7 +356,7 @@ class TxInOutWidget(QWidget):
|
|||||||
show_list += [(_("Address Details"), lambda: self.main_window.show_address(addr, parent=self))]
|
show_list += [(_("Address Details"), lambda: self.main_window.show_address(addr, parent=self))]
|
||||||
copy_list += [(_("Copy Address"), lambda: self.main_window.do_copy(addr))]
|
copy_list += [(_("Copy Address"), lambda: self.main_window.do_copy(addr))]
|
||||||
txout_value = self.tx.outputs()[txout_idx].value
|
txout_value = self.tx.outputs()[txout_idx].value
|
||||||
value_str = self.main_window.format_amount(txout_value)
|
value_str = self.main_window.format_amount(txout_value, ignore_thousands_sep=True)
|
||||||
copy_list += [(_("Copy Amount"), lambda: self.main_window.do_copy(value_str))]
|
copy_list += [(_("Copy Amount"), lambda: self.main_window.do_copy(value_str))]
|
||||||
|
|
||||||
for item in show_list:
|
for item in show_list:
|
||||||
|
|||||||
@@ -785,6 +785,7 @@ class SimpleConfig(Logger):
|
|||||||
is_diff=False,
|
is_diff=False,
|
||||||
whitespaces=False,
|
whitespaces=False,
|
||||||
precision=None,
|
precision=None,
|
||||||
|
ignore_thousands_sep: bool=False,
|
||||||
) -> str:
|
) -> str:
|
||||||
if precision is None:
|
if precision is None:
|
||||||
precision = self.amt_precision_post_satoshi
|
precision = self.amt_precision_post_satoshi
|
||||||
@@ -795,7 +796,7 @@ class SimpleConfig(Logger):
|
|||||||
is_diff=is_diff,
|
is_diff=is_diff,
|
||||||
whitespaces=whitespaces,
|
whitespaces=whitespaces,
|
||||||
precision=precision,
|
precision=precision,
|
||||||
add_thousands_sep=self.amt_add_thousands_sep,
|
add_thousands_sep=False if ignore_thousands_sep else self.amt_add_thousands_sep,
|
||||||
)
|
)
|
||||||
|
|
||||||
def format_amount_and_units(self, *args, **kwargs) -> str:
|
def format_amount_and_units(self, *args, **kwargs) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user