kivy: improve wizard

This commit is contained in:
ThomasV 2016-01-16 12:01:37 +01:00
parent 06809917ca
commit 5be9f03fdf
2 changed files with 86 additions and 78 deletions

View File

@ -68,7 +68,7 @@ Builder.load_string('''
id: grid_logo
cols: 1
pos_hint: {'center_y': .5}
size_hint: 1, .62
size_hint: 1, .42
#height: self.minimum_height
Image:
id: logo_img
@ -180,6 +180,13 @@ Builder.load_string('''
<ShowSeedDialog>
spacing: '12dp'
Label:
color: root.text_color
size_hint: 1, None
text_size: self.width, None
height: self.texture_size[1]
text: "[b]PLEASE WRITE DOWN YOUR SEED PHRASE[/b]"
GridLayout:
id: grid
cols: 1
@ -191,39 +198,37 @@ Builder.load_string('''
border: 4, 4, 4, 4
halign: 'justify'
valign: 'middle'
font_size: self.width/21
font_size: self.width/15
text_size: self.width - dp(24), self.height - dp(12)
#size_hint: 1, None
#height: self.texture_size[1] + dp(24)
color: .1, .1, .1, 1
background_normal: 'atlas://gui/kivy/theming/light/white_bg_round_top'
background_down: self.background_normal
text: root.message
GridLayout:
text: root.seed_text
#GridLayout:
# rows: 1
# Button:
# id: bt
# size_hint_x: .15
# background_normal: 'atlas://gui/kivy/theming/light/blue_bg_round_rb'
# background_down: self.background_normal
# Image:
# mipmap: True
# source: 'atlas://gui/kivy/theming/light/qrcode'
# size: bt.size
# center: bt.center
# #on_release:
Label:
rows: 1
size_hint: 1, .7
#size_hint_y: None
#height: but_seed.texture_size[1] + dp(24)
Button:
id: but_seed
border: 4, 4, 4, 4
halign: 'justify'
valign: 'middle'
font_size: self.width/15
text: root.seed_msg
text_size: self.width - dp(24), self.height - dp(12)
background_normal: 'atlas://gui/kivy/theming/light/lightblue_bg_round_lb'
background_down: self.background_normal
Button:
id: bt
size_hint_x: .25
background_normal: 'atlas://gui/kivy/theming/light/blue_bg_round_rb'
background_down: self.background_normal
Image:
mipmap: True
source: 'atlas://gui/kivy/theming/light/qrcode'
size: bt.size
center: bt.center
#on_release:
id: but_seed
border: 4, 4, 4, 4
halign: 'justify'
valign: 'middle'
font_size: self.width/21
text: root.message
text_size: self.width - dp(24), self.height - dp(12)
GridLayout:
rows: 1
spacing: '12dp'
@ -295,7 +300,7 @@ class CreateRestoreDialog(CreateAccountDialog):
class ShowSeedDialog(CreateAccountDialog):
seed_msg = StringProperty('')
seed_text = StringProperty('')
'''Text to be displayed in the TextInput'''
message = StringProperty('')
@ -323,12 +328,18 @@ class ShowSeedDialog(CreateAccountDialog):
class RestoreSeedDialog(CreateAccountDialog):
def __init__(self, **kwargs):
self._wizard = kwargs['wizard']
super(RestoreSeedDialog, self).__init__(**kwargs)
self._test = kwargs['test']
self._trigger_check_seed = Clock.create_trigger(self.check_seed)
def check_seed(self, dt):
self.ids.next.disabled = not bool(self._wizard.is_any(self.ids.text_input_seed))
self.ids.next.disabled = not bool(self._test(self.get_seed_text()))
def get_seed_text(self):
ti = self.ids.text_input_seed
text = unicode(ti.text.lower()).strip()
text = ' '.join(text.split())
return text
def on_parent(self, instance, value):
if value:

View File

@ -36,8 +36,9 @@ class InstallWizard(Widget):
self.network = network
self.storage = storage
self.wallet = Wallet(self.storage)
self.is_restore = False
def waiting_dialog(self, task, msg):
def waiting_dialog(self, task, msg, on_complete=None):
'''Perform a blocking task in the background by running the passed
method in a thread.
'''
@ -49,17 +50,15 @@ class InstallWizard(Widget):
Clock.schedule_once(lambda dt: app.show_error(str(err)))
# on completion hide message
Clock.schedule_once(lambda dt: app.info_bubble.hide(now=True), -1)
if on_complete:
on_complete()
app.show_info_bubble(
text=msg, icon='atlas://gui/kivy/theming/light/important',
pos=Window.center, width='200sp', arrow_pos=None, modal=True)
t = threading.Thread(target = target)
t.start()
def get_seed_text(self, ti_seed):
text = unicode(ti_seed.text.lower()).strip()
text = ' '.join(text.split())
return text
def is_any(self, seed_e):
text = self.get_seed_text(seed_e)
return Wallet.is_any(text)
@ -68,20 +67,9 @@ class InstallWizard(Widget):
'''Entry point of our Installation wizard'''
if not action:
return
if action == 'new':
self.new()
elif action == 'create':
self.create()
elif action == 'restore':
self.restore()
elif action == 'enter_pin':
self.enter_pin(*args)
elif action == 'confirm_pin':
self.confirm_pin(*args)
elif action == 'add_seed':
self.add_seed(*args)
elif action == 'terminate':
self.terminate()
if hasattr(self, action):
f = getattr(self, action)
apply(f, *args)
else:
raise BaseException("unknown action", action)
@ -102,22 +90,21 @@ class InstallWizard(Widget):
def restore(self):
from create_restore import RestoreSeedDialog
self.is_restore = True
def on_seed(_dlg, btn):
if btn is _dlg.ids.back:
_dlg.close()
self.run('new')
return
text = self.get_seed_text(_dlg.ids.text_input_seed)
text = _dlg.get_seed_text()
need_password = Wallet.should_encrypt(text)
_dlg.close()
if need_password:
self.run('enter_pin', text)
self.run('enter_pin', (text,))
else:
self.wallet = Wallet.from_text(text)
# fixme: sync
RestoreSeedDialog(
on_release=partial(on_seed),
wizard=weakref.proxy(self)).open()
RestoreSeedDialog(test=Wallet.is_any, on_release=partial(on_seed)).open()
def add_seed(self, seed, password):
def task():
@ -125,55 +112,65 @@ class InstallWizard(Widget):
self.wallet.create_master_keys(password)
self.wallet.create_main_account()
self.wallet.synchronize()
self.run('terminate')
msg= _("Electrum is generating your addresses, please wait.")
self.waiting_dialog(task, msg)
self.waiting_dialog(task, msg, self.terminate)
def create(self):
from create_restore import ShowSeedDialog
self.is_restore = False
seed = self.wallet.make_seed()
msg = _("[color=#414141]"+\
"[b]PLEASE WRITE DOWN YOUR SEED PASS[/b][/color]"+\
"[size=9]\n\n[/size]" +\
"[color=#929292]If you ever forget your pincode, your seed" +\
" phrase will be the [color=#EB984E]"+\
"[b]only way to recover[/b][/color] your wallet. Your " +\
" [color=#EB984E][b]Bitcoins[/b][/color] will otherwise be" +\
" [color=#EB984E][b]lost forever![/b][/color]")
msg = _("If you forget your PIN or lose your device, your seed phrase will be the "
"only way to recover your funds.")
def on_ok(_dlg, _btn):
_dlg.close()
if _btn == _dlg.ids.confirm:
self.run('enter_pin', seed)
self.run('confirm_seed', (seed,))
else:
self.run('new')
ShowSeedDialog(message=msg, seed_msg=seed, on_release=on_ok).open()
ShowSeedDialog(message=msg, seed_text=seed, on_release=on_ok).open()
def confirm_seed(self, seed):
from create_restore import RestoreSeedDialog
def on_seed(_dlg, btn):
if btn is _dlg.ids.back:
_dlg.close()
self.run('create')
return
_dlg.close()
if Wallet.should_encrypt(seed):
self.run('enter_pin', (seed,))
else:
self.wallet = Wallet.from_text(seed)
# fixme: sync
RestoreSeedDialog(test=lambda x: x==seed, on_release=partial(on_seed)).open()
def enter_pin(self, seed):
from password_dialog import PasswordDialog
def callback(pin):
self.run('confirm_pin', seed, pin)
popup = PasswordDialog('Enter PIN', callback)
self.run('confirm_pin', (seed, pin))
popup = PasswordDialog('Choose a PIN code', callback)
popup.open()
def confirm_pin(self, seed, pin):
from password_dialog import PasswordDialog
def callback(conf):
if conf == pin:
self.run('add_seed', seed, pin)
self.run('add_seed', (seed, pin))
else:
app = App.get_running_app()
app.show_error(_('Passwords do not match'), duration=.5)
popup = PasswordDialog('Confirm PIN', callback)
popup = PasswordDialog('Confirm your PIN code', callback)
popup.open()
def terminate(self):
self.wallet.start_threads(self.network)
app.load_wallet(self.wallet)
self.dispatch('on_wizard_complete', wallet)
#if self.is_restore:
# if self.wallet.is_found():
# app.show_info(_("Recovery successful"), duration=.5)
# else:
# app.show_info(_("No transactions found for this seed"), duration=.5)
self.dispatch('on_wizard_complete', self.wallet)
def on_wizard_complete(self, wallet):
if wallet.is_found():
app.show_info(_("Recovery successful"), duration=.5)
else:
app.show_info(_("No transactions found for this seed"),
duration=.5)
"""overriden by main_window"""
pass