electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 4d62963efe79d2224a5a273b3eaac207def68a7b
parent f767d41409ad20e60bf535fb78468f276679b6fb
Author: ghost43 <somber.night@protonmail.com>
Date:   Wed, 14 Nov 2018 22:39:49 +0100

qt: count wizards in progress (#4349)

fixes #4348
Diffstat:
Melectrum/gui/qt/__init__.py | 32++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/electrum/gui/qt/__init__.py b/electrum/gui/qt/__init__.py @@ -26,6 +26,7 @@ import signal import sys import traceback +import threading try: @@ -105,6 +106,8 @@ class ElectrumGui(PrintError): self.timer = Timer() self.nd = None self.network_updated_signal_obj = QNetworkUpdatedSignalObject() + self._num_wizards_in_progress = 0 + self._num_wizards_lock = threading.Lock() # init tray self.dark_icon = self.config.get("dark_icon", False) self.tray = QSystemTrayIcon(self.tray_icon(), None) @@ -195,6 +198,18 @@ class ElectrumGui(PrintError): run_hook('on_new_window', w) return w + def count_wizards_in_progress(func): + def wrapper(self: 'ElectrumGui', *args, **kwargs): + with self._num_wizards_lock: + self._num_wizards_in_progress += 1 + try: + return func(self, *args, **kwargs) + finally: + with self._num_wizards_lock: + self._num_wizards_in_progress -= 1 + return wrapper + + @count_wizards_in_progress def start_new_window(self, path, uri, app_is_starting=False): '''Raises the window for the wallet if it is open. Otherwise opens the wallet and creates a new window for it''' @@ -291,10 +306,15 @@ class ElectrumGui(PrintError): signal.signal(signal.SIGINT, lambda *args: self.app.quit()) def quit_after_last_window(): - # on some platforms, not only does exec_ not return but not even - # aboutToQuit is emitted (but following this, it should be emitted) - if self.app.quitOnLastWindowClosed(): - self.app.quit() + # keep daemon running after close + if self.config.get('daemon'): + return + # check if a wizard is in progress + with self._num_wizards_lock: + if self._num_wizards_in_progress > 0 or len(self.windows) > 0: + return + self.app.quit() + self.app.setQuitOnLastWindowClosed(False) # so _we_ can decide whether to quit self.app.lastWindowClosed.connect(quit_after_last_window) def clean_up(): @@ -306,10 +326,6 @@ class ElectrumGui(PrintError): self.tray.hide() self.app.aboutToQuit.connect(clean_up) - # keep daemon running after close - if self.config.get('daemon'): - self.app.setQuitOnLastWindowClosed(False) - # main loop self.app.exec_() # on some platforms the exec_ call may not return, so use clean_up()