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