electrum

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

commit 8bc0fcf541d79a1e615ce1003b419b7b2feecf55
parent 74b12f02b54ea237b9fe1ee25c18a6f388b06d0d
Author: ThomasV <thomasv@electrum.org>
Date:   Sun,  6 Mar 2016 11:46:09 +0100

kivy: cache dialogs

Diffstat:
Mgui/kivy/main_window.py | 43+++++++++++++++++++++++++++++--------------
Mgui/kivy/uix/dialogs/password_dialog.py | 9++++++---
Mgui/kivy/uix/dialogs/settings.py | 122+++++++++++++++++++++++++++++++++++++++++++------------------------------------
3 files changed, 102 insertions(+), 72 deletions(-)

diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py @@ -216,6 +216,9 @@ class ElectrumWindow(App): Clock.create_trigger(self.update_status, .5) self._trigger_notify_transactions = \ Clock.create_trigger(self.notify_transactions, 5) + # cached dialogs + self._settings_dialog = None + self._password_dialog = None def on_pr(self, pr): @@ -425,11 +428,15 @@ class ElectrumWindow(App): #self.gui.main_gui.toggle_settings(self) return True + def settings_dialog(self): + if self._settings_dialog is None: + from uix.dialogs.settings import SettingsDialog + self._settings_dialog = SettingsDialog(self) + self._settings_dialog.open() + def popup_dialog(self, name): if name == 'settings': - from uix.dialogs.settings import SettingsDialog - d = SettingsDialog(self) - d.open() + self.settings_dialog() elif name == 'wallets': from uix.dialogs.wallets import WalletDialog d = WalletDialog() @@ -749,7 +756,7 @@ class ElectrumWindow(App): self.protected(_("Enter your PIN code in order to decrypt your seed"), self._show_seed, (label,)) def _show_seed(self, label, password): - if not password: + if self.wallet.use_encryption and password is None: return try: seed = self.wallet.get_seed(password) @@ -758,31 +765,39 @@ class ElectrumWindow(App): return label.text = _('Seed') + ':\n' + seed - def change_password(self): - self.protected(_("Changing PIN code.") + '\n' + _("Enter your current PIN:"), self._change_password, ()) + def change_password(self, cb): + if self.wallet.use_encryption: + self.protected(_("Changing PIN code.") + '\n' + _("Enter your current PIN:"), self._change_password, (cb,)) + else: + self._change_password(cb, None) - def _change_password(self, old_password): + def _change_password(self, cb, old_password): if self.wallet.use_encryption: + if old_password is None: + return try: self.wallet.check_password(old_password) except InvalidPassword: self.show_error("Invalid PIN") return - self.password_dialog(_('Enter new PIN'), self._change_password2, (old_password,)) + self.password_dialog(_('Enter new PIN'), self._change_password2, (cb, old_password,)) - def _change_password2(self, old_password, new_password): - self.password_dialog(_('Confirm new PIN'), self._change_password3, (old_password, new_password)) + def _change_password2(self, cb, old_password, new_password): + self.password_dialog(_('Confirm new PIN'), self._change_password3, (cb, old_password, new_password)) - def _change_password3(self, old_password, new_password, confirmed_password): + def _change_password3(self, cb, old_password, new_password, confirmed_password): if new_password == confirmed_password: self.wallet.update_password(old_password, new_password) + cb() else: self.show_error("PIN numbers do not match") def password_dialog(self, msg, f, args): - from uix.dialogs.password_dialog import PasswordDialog def callback(pw): Clock.schedule_once(lambda x: apply(f, args + (pw,)), 0.1) - popup = PasswordDialog(msg, callback) - popup.open() + if self._password_dialog is None: + from uix.dialogs.password_dialog import PasswordDialog + self._password_dialog = PasswordDialog() + self._password_dialog.init(msg, callback) + self._password_dialog.open() diff --git a/gui/kivy/uix/dialogs/password_dialog.py b/gui/kivy/uix/dialogs/password_dialog.py @@ -75,11 +75,14 @@ Builder.load_string(''' class PasswordDialog(Factory.Popup): - def __init__(self, message, callback): - Factory.Popup.__init__(self) + #def __init__(self, message, callback): + # Factory.Popup.__init__(self) + + def init(self, message, callback): + self.pw = None self.message = message self.callback = callback - self.pw = None + self.ids.kb.password = '' def update_password(self, c): kb = self.ids.kb diff --git a/gui/kivy/uix/dialogs/settings.py b/gui/kivy/uix/dialogs/settings.py @@ -63,7 +63,7 @@ Builder.load_string(''' action: partial(root.language_dialog, self) CardSeparator SettingsItem: - status: 'ON' if app.wallet.use_encryption else 'OFF' + status: root.password_status() disabled: app.wallet.is_watching_only() title: _('PIN code') + ': ' + self.status description: _("Change your PIN code.") @@ -104,18 +104,10 @@ Builder.load_string(''' title: _('Coin selection') + ': ' + self.status description: "Coin selection method" action: partial(root.coinselect_dialog, self) - BoxLayout: - size_hint: 1, 0.1 - Widget: - size_hint: 0.5, None - Button: - size_hint: 0.5, None - height: '48dp' - text: _('OK') - on_release: - settings.dismiss() ''') + + class SettingsDialog(Factory.Popup): def __init__(self, app): @@ -125,54 +117,73 @@ class SettingsDialog(Factory.Popup): Factory.Popup.__init__(self) layout = self.ids.scrollviewlayout layout.bind(minimum_height=layout.setter('height')) + # cached dialogs + self._fx_dialog = None + self._fee_dialog = None + self._network_dialog = None + self._language_dialog = None + self._unit_dialog = None + self._coinselect_dialog = None def get_language_name(self): return languages.get(self.config.get('language', 'en_UK'), '') - def change_password(self, label, dt): - self.app.change_password() + def password_status(self): + if self.app.wallet.is_watching_only(): + return 'watching-only' + return 'ON' if self.app.wallet.use_encryption else 'OFF' + + def change_password(self, item, dt): + def cb(): + item.status = self.password_status() + self.app.change_password(cb) def language_dialog(self, item, dt): - l = self.config.get('language', 'en_UK') - def cb(key): - self.config.set_key("language", key, True) - item.lang = self.get_language_name() - self.app.language = key - d = ChoiceDialog(_('Language'), languages, l, cb) - d.open() + if self._language_dialog is None: + l = self.config.get('language', 'en_UK') + def cb(key): + self.config.set_key("language", key, True) + item.lang = self.get_language_name() + self.app.language = key + self._language_dialog = ChoiceDialog(_('Language'), languages, l, cb) + self._language_dialog.open() def unit_dialog(self, item, dt): - def cb(text): - self.app._set_bu(text) - item.bu = self.app.base_unit - d = ChoiceDialog(_('Denomination'), base_units.keys(), self.app.base_unit, cb) - d.open() + if self._unit_dialog is None: + def cb(text): + self._set_bu(text) + item.bu = self.app.base_unit + self._unit_dialog = ChoiceDialog(_('Denomination'), base_units.keys(), self.app.base_unit, cb) + self._unit_dialog.open() def coinselect_status(self): return self.app.wallet.coin_chooser_name(self.app.electrum_config) def coinselect_dialog(self, item, dt): - from electrum import COIN_CHOOSERS - choosers = sorted(COIN_CHOOSERS.keys()) - chooser_name = self.app.wallet.coin_chooser_name(self.config) - def cb(text): - self.config.set_key('coin_chooser', text) - item.status = text - d = ChoiceDialog(_('Coin selection'), choosers, chooser_name, cb) - d.open() + if self._coinselect_dialog is None: + from electrum import COIN_CHOOSERS + choosers = sorted(COIN_CHOOSERS.keys()) + chooser_name = self.app.wallet.coin_chooser_name(self.config) + def cb(text): + self.config.set_key('coin_chooser', text) + item.status = text + self._coinselect_dialog = ChoiceDialog(_('Coin selection'), choosers, chooser_name, cb) + self._coinselect_dialog.open() def network_dialog(self, item, dt): - server, port, protocol, proxy, auto_connect = self.app.network.get_parameters() - def cb(popup): - server = popup.ids.host.text - auto_connect = popup.ids.auto_connect.active - self.app.network.set_parameters(server, port, protocol, proxy, auto_connect) - item.status = self.network_status() - popup = Builder.load_file('gui/kivy/uix/ui_screens/network.kv') - popup.ids.host.text = server - popup.ids.auto_connect.active = auto_connect - popup.on_dismiss = lambda: cb(popup) - popup.open() + if self._network_dialog is None: + server, port, protocol, proxy, auto_connect = self.app.network.get_parameters() + def cb(popup): + server = popup.ids.host.text + auto_connect = popup.ids.auto_connect.active + self.app.network.set_parameters(server, port, protocol, proxy, auto_connect) + item.status = self.network_status() + popup = Builder.load_file('gui/kivy/uix/ui_screens/network.kv') + popup.ids.host.text = server + popup.ids.auto_connect.active = auto_connect + popup.on_dismiss = lambda: cb(popup) + self._network_dialog = popup + self._network_dialog.open() def network_status(self): server, port, protocol, proxy, auto_connect = self.app.network.get_parameters() @@ -200,11 +211,12 @@ class SettingsDialog(Factory.Popup): return self.app.format_amount_and_units(F) + '/kB' def fee_dialog(self, label, dt): - from fee_dialog import FeeDialog - def cb(): - label.status = self.fee_status() - d = FeeDialog(self.app, self.config, cb) - d.open() + if self._fee_dialog is None: + from fee_dialog import FeeDialog + def cb(): + label.status = self.fee_status() + self._fee_dialog = FeeDialog(self.app, self.config, cb) + self._fee_dialog.open() def fx_status(self): p = self.plugins.get('exchange_rate') @@ -216,9 +228,9 @@ class SettingsDialog(Factory.Popup): return 'Disabled' def fx_dialog(self, label, dt): - from fx_dialog import FxDialog - def cb(): - label.status = self.fx_status() - d = FxDialog(self.app, self.plugins, self.config, cb) - d.open() - + if self._fx_dialog is None: + from fx_dialog import FxDialog + def cb(): + label.status = self.fx_status() + self._fx_dialog = FxDialog(self.app, self.plugins, self.config, cb) + self._fx_dialog.open()