tFix top level window issue on Mac - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 83cc5e2001a1413920bd3afe61211d9f7246c039 DIR parent 56bc717da1fb423b63bea716c097a9f7c8632431 HTML Author: Neil Booth <kyuupichan@gmail.com> Date: Sun, 10 Jan 2016 12:56:12 +0900 Fix top level window issue on Mac Better, more generic fix superseding prior two patches. Diffstat: M gui/qt/__init__.py | 2 +- M gui/qt/main_window.py | 16 ++++------------ M gui/qt/util.py | 24 ++++++++++++++---------- 3 files changed, 19 insertions(+), 23 deletions(-) --- DIR diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py t@@ -64,7 +64,7 @@ class OpenFileEventFilter(QObject): -class ElectrumGui(MessageBoxMixin): +class ElectrumGui: def __init__(self, config, network, daemon, plugins): set_language(config.get('language')) DIR diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py t@@ -183,13 +183,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): return "%s/%s" % (PrintError.diagnostic_name(self), self.wallet.basename() if self.wallet else "None") - def top_level_window(self, window=None): - window = window or self - for n, child in enumerate(window.children()): - if isinstance(child, WindowModalDialog): - return self.top_level_window(child) - return window - def is_hidden(self): return self.isMinimized() or self.isHidden() t@@ -2085,11 +2078,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): verified = bitcoin.verify_message(address.text(), sig, message) except: verified = False - dialog = self.top_level_window() if verified: - dialog.show_message(_("Signature verified")) + self.show_message(_("Signature verified")) else: - dialog.show_error(_("Wrong signature")) + self.show_error(_("Wrong signature")) def sign_verify_message(self, address=''): t@@ -2137,7 +2129,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): message_e.setText(decrypted) except BaseException as e: traceback.print_exc(file=sys.stdout) - self.top_level_window().show_warning(str(e)) + self.show_warning(str(e)) def do_encrypt(self, message_e, pubkey_e, encrypted_e): t@@ -2148,7 +2140,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): encrypted_e.setText(encrypted) except BaseException as e: traceback.print_exc(file=sys.stdout) - self.top_level_window().show_warning(str(e)) + self.show_warning(str(e)) def encrypt_message(self, address = ''): DIR diff --git a/gui/qt/util.py b/gui/qt/util.py t@@ -156,34 +156,38 @@ class CancelButton(QPushButton): self.clicked.connect(dialog.reject) class MessageBoxMixin(object): + def top_level_window(self, window=None): + window = window or self + for n, child in enumerate(window.children()): + if isinstance(child, WindowModalDialog): + return self.top_level_window(child) + return window + def question(self, msg, parent=None, title=None, icon=None): Yes, No = QMessageBox.Yes, QMessageBox.No return self.msg_box(icon or QMessageBox.Question, - parent or self, title or '', + parent, title or '', msg, buttons=Yes|No, defaultButton=No) == Yes def show_warning(self, msg, parent=None, title=None): - return self.msg_box(QMessageBox.Warning, parent or self, + return self.msg_box(QMessageBox.Warning, parent, title or _('Warning'), msg) def show_error(self, msg, parent=None): - return self.msg_box(QMessageBox.Warning, parent or self, + return self.msg_box(QMessageBox.Warning, parent, _('Error'), msg) def show_critical(self, msg, parent=None, title=None): - return self.msg_box(QMessageBox.Critical, parent or self, + return self.msg_box(QMessageBox.Critical, parent, title or _('Critical Error'), msg) def show_message(self, msg, parent=None, title=None): - return self.msg_box(QMessageBox.Information, parent or self, + return self.msg_box(QMessageBox.Information, parent, title or _('Information'), msg) - @staticmethod - def msg_box(icon, parent, title, text, buttons=QMessageBox.Ok, + def msg_box(self, icon, parent, title, text, buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton): - # handle e.g. ElectrumGui - if not isinstance(parent, QWidget): - parent = None + parent = parent or self.top_level_window() d = QMessageBox(icon, title, text, buttons, parent) d.setWindowModality(Qt.WindowModal) d.setDefaultButton(defaultButton)