@ -90,7 +90,7 @@ from .util import (read_QIcon, ColorScheme, text_dialog, icon_path, WaitingDialo
import_meta_gui , export_meta_gui ,
import_meta_gui , export_meta_gui ,
filename_field , address_field , char_width_in_lineedit , webopen ,
filename_field , address_field , char_width_in_lineedit , webopen ,
TRANSACTION_FILE_EXTENSION_FILTER_ANY , MONOSPACE_FONT ,
TRANSACTION_FILE_EXTENSION_FILTER_ANY , MONOSPACE_FONT ,
getOpenFileName , getSaveFileName , BlockingWaitingDialog , font_height )
getOpenFileName , getSaveFileName , font_height )
from . util import ButtonsLineEdit , ShowQRLineEdit
from . util import ButtonsLineEdit , ShowQRLineEdit
from . util import QtEventListener , qt_event_listener , event_listener
from . util import QtEventListener , qt_event_listener , event_listener
from . wizard . wallet import WIF_HELP_TEXT
from . wizard . wallet import WIF_HELP_TEXT
@ -301,26 +301,11 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
self . _update_check_thread . checked . connect ( on_version_received )
self . _update_check_thread . checked . connect ( on_version_received )
self . _update_check_thread . start ( )
self . _update_check_thread . start ( )
def run_coroutine_dialog ( self , coro , text , on_result , on_cancelled ) :
def run_coroutine_dialog ( self , coro , text ) :
""" run coroutine in a waiting dialog, with a Cancel button that cancels the coroutine """
""" run coroutine in a waiting dialog, with a Cancel button that cancels the coroutine """
from electrum import util
from . util import RunCoroutineDialog
loop = util . get_asyncio_loop ( )
d = RunCoroutineDialog ( self , text , coro )
assert util . get_running_loop ( ) != loop , ' must not be called from asyncio thread '
return d . run ( )
future = asyncio . run_coroutine_threadsafe ( coro , loop )
def task ( ) :
try :
return future . result ( )
except concurrent . futures . CancelledError :
on_cancelled ( )
try :
WaitingDialog (
self , text , task ,
on_success = on_result ,
on_error = self . on_error ,
on_cancel = future . cancel )
except Exception as e :
self . show_error ( str ( e ) )
raise
def run_coroutine_from_thread ( self , coro , name , on_result = None ) :
def run_coroutine_from_thread ( self , coro , name , on_result = None ) :
if self . _cleaned_up :
if self . _cleaned_up :
@ -1180,10 +1165,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
if not self . wallet . lnworker . num_sats_can_send ( ) and not self . wallet . lnworker . num_sats_can_receive ( ) :
if not self . wallet . lnworker . num_sats_can_send ( ) and not self . wallet . lnworker . num_sats_can_receive ( ) :
self . show_error ( _ ( " You do not have liquidity in your active channels. " ) )
self . show_error ( _ ( " You do not have liquidity in your active channels. " ) )
return
return
def get_pairs_thread ( ) :
self . network . run_from_another_thread ( self . wallet . lnworker . swap_manager . get_pairs ( ) )
try :
try :
BlockingWaitingDialog ( self , _ ( ' Please wait... ' ) , get_pairs_thread )
self . run_coroutine_dialog (
self . wallet . lnworker . swap_manager . get_pairs ( ) , _ ( ' Please wait... ' ) )
except SwapServerError as e :
except SwapServerError as e :
self . show_error ( str ( e ) )
self . show_error ( str ( e ) )
return
return