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 id: grid_logo
cols: 1 cols: 1
pos_hint: {'center_y': .5} pos_hint: {'center_y': .5}
size_hint: 1, .62 size_hint: 1, .42
#height: self.minimum_height #height: self.minimum_height
Image: Image:
id: logo_img id: logo_img
@ -180,6 +180,13 @@ Builder.load_string('''
<ShowSeedDialog> <ShowSeedDialog>
spacing: '12dp' 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: GridLayout:
id: grid id: grid
cols: 1 cols: 1
@ -191,39 +198,37 @@ Builder.load_string('''
border: 4, 4, 4, 4 border: 4, 4, 4, 4
halign: 'justify' halign: 'justify'
valign: 'middle' valign: 'middle'
font_size: self.width/21 font_size: self.width/15
text_size: self.width - dp(24), self.height - dp(12) text_size: self.width - dp(24), self.height - dp(12)
#size_hint: 1, None #size_hint: 1, None
#height: self.texture_size[1] + dp(24) #height: self.texture_size[1] + dp(24)
color: .1, .1, .1, 1
background_normal: 'atlas://gui/kivy/theming/light/white_bg_round_top' background_normal: 'atlas://gui/kivy/theming/light/white_bg_round_top'
background_down: self.background_normal background_down: self.background_normal
text: root.message text: root.seed_text
GridLayout: #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 rows: 1
size_hint: 1, .7 size_hint: 1, .7
#size_hint_y: None
#height: but_seed.texture_size[1] + dp(24)
Button:
id: but_seed id: but_seed
border: 4, 4, 4, 4 border: 4, 4, 4, 4
halign: 'justify' halign: 'justify'
valign: 'middle' valign: 'middle'
font_size: self.width/15 font_size: self.width/21
text: root.seed_msg text: root.message
text_size: self.width - dp(24), self.height - dp(12) 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:
GridLayout: GridLayout:
rows: 1 rows: 1
spacing: '12dp' spacing: '12dp'
@ -295,7 +300,7 @@ class CreateRestoreDialog(CreateAccountDialog):
class ShowSeedDialog(CreateAccountDialog): class ShowSeedDialog(CreateAccountDialog):
seed_msg = StringProperty('') seed_text = StringProperty('')
'''Text to be displayed in the TextInput''' '''Text to be displayed in the TextInput'''
message = StringProperty('') message = StringProperty('')
@ -323,12 +328,18 @@ class ShowSeedDialog(CreateAccountDialog):
class RestoreSeedDialog(CreateAccountDialog): class RestoreSeedDialog(CreateAccountDialog):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self._wizard = kwargs['wizard']
super(RestoreSeedDialog, self).__init__(**kwargs) super(RestoreSeedDialog, self).__init__(**kwargs)
self._test = kwargs['test']
self._trigger_check_seed = Clock.create_trigger(self.check_seed) self._trigger_check_seed = Clock.create_trigger(self.check_seed)
def check_seed(self, dt): 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): def on_parent(self, instance, value):
if value: if value:

View File

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