Browse Source

Qt: add name to coroutines_scheduled

patch-4
ThomasV 3 years ago
parent
commit
2e120d74b8
  1. 22
      electrum/gui/qt/main_window.py
  2. 4
      electrum/gui/qt/swap_dialog.py

22
electrum/gui/qt/main_window.py

@ -206,7 +206,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.current_request = None # request shown in the receive tab
Logger.__init__(self)
self._coroutines_scheduled = set() # type: Set[concurrent.futures.Future]
self._coroutines_scheduled = {} # type: Dict[concurrent.futures.Future, str]
self.thread = TaskThread(self, self.on_error)
self.tx_notification_queue = queue.Queue()
@ -328,7 +328,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self._update_check_thread.checked.connect(on_version_received)
self._update_check_thread.start()
def run_coroutine_from_thread(self, coro, on_result=None):
def run_coroutine_from_thread(self, coro, name, on_result=None):
if self._cleaned_up:
self.logger.warning(f"stopping or already stopped but run_coroutine_from_thread was called.")
return
@ -342,11 +342,11 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
if on_result:
on_result(res)
finally:
self._coroutines_scheduled.discard(fut)
self._coroutines_scheduled.pop(fut)
self.need_update.set()
fut = asyncio.run_coroutine_threadsafe(wrapper(), self.network.asyncio_loop)
self._coroutines_scheduled.add(fut)
self._coroutines_scheduled[fut] = name
self.need_update.set()
def on_fx_history(self):
@ -1031,7 +1031,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.status_button.setIcon(icon)
num_tasks = self.num_tasks()
self.tasks_label.setText("(%d %s)"%(num_tasks, _("tasks")))
if num_tasks == 0:
name = ''
elif num_tasks == 1:
name = list(self._coroutines_scheduled.values())[0] + '...'
else:
name = "%d"%num_tasks + _('tasks') + '...'
self.tasks_label.setText(name)
self.tasks_label.setVisible(num_tasks > 0)
def num_tasks(self):
@ -1813,7 +1819,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
return
self.save_pending_invoice()
coro = self.wallet.lnworker.pay_invoice(invoice.lightning_invoice, amount_msat=amount_msat)
self.run_coroutine_from_thread(coro)
self.run_coroutine_from_thread(coro, _('Sending payment'))
def run_swap_dialog(self, is_reverse=None, recv_amount_sat=None, channels=None):
if not self.network:
@ -3486,7 +3492,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
if self.thread:
self.thread.stop()
self.thread = None
for fut in self._coroutines_scheduled:
for fut in self._coroutines_scheduled.keys():
fut.cancel()
util.unregister_callback(self.on_network)
self.config.set_key("is_maximized", self.isMaximized())
@ -3768,5 +3774,5 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
return
amount_msat = amount_e.get_amount() * 1000
coro = self.wallet.lnworker.rebalance_channels(d.chan_from, d.chan_to, amount_msat=amount_msat)
self.run_coroutine_from_thread(coro)
self.run_coroutine_from_thread(coro, _('Rebalancing channels'))
self.update_current_request()

4
electrum/gui/qt/swap_dialog.py

@ -231,7 +231,7 @@ class SwapDialog(WindowModalDialog):
lightning_amount_sat=lightning_amount,
expected_onchain_amount_sat=onchain_amount + self.swap_manager.get_claim_fee(),
)
self.window.run_coroutine_from_thread(coro)
self.window.run_coroutine_from_thread(coro, _('Swapping funds'))
return True
else:
lightning_amount = self.recv_amount_e.get_amount()
@ -290,7 +290,7 @@ class SwapDialog(WindowModalDialog):
tx=tx,
channels=self.channels,
)
self.window.run_coroutine_from_thread(coro)
self.window.run_coroutine_from_thread(coro, _('Swapping funds'))
def get_description(self):
onchain_funds = "onchain funds"

Loading…
Cancel
Save