tkivy: do not use an event to call on_wizard_complete, initialize self.app in constructor - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 2923c00d384307e227391a519a914893f21b92bf DIR parent f1875874309051de1f604c7b7b0e2e2a0fe5881c HTML Author: ThomasV <thomasv@electrum.org> Date: Tue, 1 Dec 2020 13:18:04 +0100 kivy: do not use an event to call on_wizard_complete, initialize self.app in constructor Diffstat: M electrum/gui/kivy/main_window.py | 5 ++--- M electrum/gui/kivy/uix/dialogs/inst… | 48 +++++++++++--------------------- 2 files changed, 18 insertions(+), 35 deletions(-) --- DIR diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py t@@ -631,7 +631,7 @@ class ElectrumWindow(App, Logger): else: return '' - def on_wizard_complete(self, wizard, storage, db): + def on_wizard_complete(self, storage, db): if storage: wallet = Wallet(db, storage, config=self.electrum_config) wallet.start_network(self.daemon.network) t@@ -669,14 +669,13 @@ class ElectrumWindow(App, Logger): if not storage.file_exists(): wizard = Factory.InstallWizard(self.electrum_config, self.plugins) wizard.path = storage.path - wizard.bind(on_wizard_complete=self.on_wizard_complete) wizard.run('new') else: assert storage.is_past_initial_decryption() self.password = pw db = WalletDB(storage.read(), manual_upgrades=False) assert not db.requires_upgrade() - self.on_wizard_complete(None, storage, db) + self.on_wizard_complete(storage, db) def on_stop(self): self.logger.info('on_stop') DIR diff --git a/electrum/gui/kivy/uix/dialogs/installwizard.py b/electrum/gui/kivy/uix/dialogs/installwizard.py t@@ -600,12 +600,11 @@ class WizardDialog(EventsDialog): self._on_release = False def _size_dialog(self, dt): - app = App.get_running_app() - if app.ui_mode[0] == 'p': + if self.app.ui_mode[0] == 'p': self.size = Window.size else: #tablet - if app.orientation[0] == 'p': + if self.app.orientation[0] == 'p': #portrait self.size = Window.size[0]/1.67, Window.size[1]/1.4 else: t@@ -622,10 +621,9 @@ class WizardDialog(EventsDialog): if self.wizard.can_go_back(): self.wizard.go_back() else: - app = App.get_running_app() - if not app.is_exit: - app.is_exit = True - app.show_info(_('Press again to exit')) + if not self.app.is_exit: + self.app.is_exit = True + self.app.show_info(_('Press again to exit')) else: self._on_release = False self.dismiss() t@@ -635,9 +633,8 @@ class WizardDialog(EventsDialog): Window.unbind(size=self._trigger_size_dialog, rotation=self._trigger_size_dialog, on_keyboard=self.on_keyboard) - app = App.get_running_app() - if app.wallet is None and not self._on_release: - app.stop() + if self.app.wallet is None and not self._on_release: + self.app.stop() def get_params(self, button): return (None,) t@@ -646,7 +643,7 @@ class WizardDialog(EventsDialog): self._on_release = True self.close() if not button: - self.parent.dispatch('on_wizard_complete', None, None) + self.app.on_wizard_complete(None, None) return if button is self.ids.back: self.wizard.go_back() t@@ -750,8 +747,7 @@ class WizardConfirmDialog(WizardDialog): def on_parent(self, instance, value): if value: - app = App.get_running_app() - self._back = _back = partial(app.dispatch, 'on_back') + self._back = _back = partial(self.app.dispatch, 'on_back') def get_params(self, button): return (True,) t@@ -778,8 +774,7 @@ class WizardChoiceDialog(WizardDialog): def on_parent(self, instance, value): if value: - app = App.get_running_app() - self._back = _back = partial(app.dispatch, 'on_back') + self._back = _back = partial(self.app.dispatch, 'on_back') def get_params(self, button): return (button.action,) t@@ -845,7 +840,6 @@ class ShowSeedDialog(WizardDialog): def on_parent(self, instance, value): if value: - app = App.get_running_app() self._back = _back = partial(self.ids.back.dispatch, 'on_release') def options_dialog(self): t@@ -963,7 +957,6 @@ class RestoreSeedDialog(WizardDialog): #tis._keyboard.bind(on_key_down=self.on_key_down) self._back = _back = partial(self.ids.back.dispatch, 'on_release') - app = App.get_running_app() def on_key_down(self, keyboard, keycode, key, modifiers): if keycode[0] in (13, 271): t@@ -1061,22 +1054,15 @@ class AddXpubDialog(WizardDialog): class InstallWizard(BaseWizard, Widget): - ''' - events:: - `on_wizard_complete` Fired when the wizard is done creating/ restoring - wallet/s. - ''' - - __events__ = ('on_wizard_complete', ) - def on_wizard_complete(self, storage, db): - """overriden by main_window""" - pass + def __init__(self, *args, **kwargs): + BaseWizard.__init__(self, *args, **kwargs) + self.app = App.get_running_app() def terminate(self, *, storage=None, db=None, aborted=False): if storage is None and not aborted: storage, db = self.create_storage(self.path) - self.dispatch('on_wizard_complete', storage, db) + self.app.on_wizard_complete(storage, db) def choice_dialog(self, **kwargs): choices = kwargs['choices'] t@@ -1128,8 +1114,7 @@ class InstallWizard(BaseWizard, Widget): def show_message(self, msg): self.show_error(msg) def show_error(self, msg): - app = App.get_running_app() # type: ElectrumWindow - Clock.schedule_once(lambda dt: app.show_error(msg)) + Clock.schedule_once(lambda dt: self.app.show_error(msg)) def request_password(self, run_next, force_disable_encrypt_cb=False): if force_disable_encrypt_cb: t@@ -1142,9 +1127,8 @@ class InstallWizard(BaseWizard, Widget): def on_failure(): self.show_error(_('Password mismatch')) self.run('request_password', run_next) - app = App.get_running_app() popup = PasswordDialog( - app, + self.app, check_password=lambda x:True, on_success=on_success, on_failure=on_failure,