some further updates to the installation wizzard

This commit is contained in:
qua-non 2014-02-21 13:20:27 +05:30 committed by ThomasV
parent f185906950
commit 23fe2062a1
4 changed files with 125 additions and 73 deletions

View File

@ -117,26 +117,36 @@ class InfoBubble(Bubble):
'''Bubble to be used to display short Help Information''' '''Bubble to be used to display short Help Information'''
message = StringProperty(_('Nothing set !')) message = StringProperty(_('Nothing set !'))
'''Message to be displayed defaults to "nothing set"''' '''Message to be displayed; defaults to "nothing set"'''
icon = StringProperty('') icon = StringProperty('')
''' Icon to be displayed along with the message defaults to '' ''' Icon to be displayed along with the message defaults to ''
:attr:`icon` is a `StringProperty` defaults to `''`
''' '''
fs = BooleanProperty(False) fs = BooleanProperty(False)
''' Show Bubble in half screen mode ''' Show Bubble in half screen mode
:attr:`fs` is a `BooleanProperty` defaults to `False`
''' '''
modal = BooleanProperty(False) modal = BooleanProperty(False)
''' Allow bubble to be hidden on touch. ''' Allow bubble to be hidden on touch.
:attr:`modal` is a `BooleanProperty` defauult to `False`.
''' '''
exit = BooleanProperty(False) exit = BooleanProperty(False)
''' exit app after bubble is closes '''Indicates whether to exit app after bubble is closed.
:attr:`exit` is a `BooleanProperty` defaults to False.
''' '''
dim_background = BooleanProperty(False) dim_background = BooleanProperty(False)
''' Whether to draw a background on the windows behind the bubble ''' Indicates Whether to draw a background on the windows behind the bubble.
:attr:`dim` is a `BooleanProperty` defaults to `False`.
''' '''
def on_touch_down(self, touch): def on_touch_down(self, touch):
@ -151,7 +161,13 @@ class InfoBubble(Bubble):
self.modal, self.exit = modal, exit self.modal, self.exit = modal, exit
if width: if width:
self.width = width self.width = width
Window.add_widget(self) if self.modal:
from kivy.uix.modalview import ModalView
self._modal_view = m = ModalView()
Window.add_widget(m)
m.add_widget(self)
else:
Window.add_widget(self)
# wait for the bubble to adjust it's size according to text then animate # wait for the bubble to adjust it's size according to text then animate
Clock.schedule_once(lambda dt: self._show(pos, duration)) Clock.schedule_once(lambda dt: self._show(pos, duration))
@ -180,6 +196,10 @@ class InfoBubble(Bubble):
''' Auto fade out the Bubble ''' Auto fade out the Bubble
''' '''
def on_stop(*l): def on_stop(*l):
if self.modal:
m = self._modal_view
m.remove_widget(self)
Window.remove_widget(m)
Window.remove_widget(self) Window.remove_widget(self)
if self.exit: if self.exit:
App.get_running_app().stop() App.get_running_app().stop()
@ -470,13 +490,33 @@ class RestoreSeedDialog(CreateAccountDialog):
def on_parent(self, instance, value): def on_parent(self, instance, value):
if value: if value:
stepper = self.ids.stepper; tis = self.ids.text_input_seed
tis.focus = True
tis._keyboard.bind(on_key_down=self.on_key_down)
stepper = self.ids.stepper
stepper.opacity = 1 stepper.opacity = 1
stepper.source = 'atlas://gui/kivy/theming/light/stepper_restore_seed' stepper.source = 'atlas://gui/kivy/theming/light/stepper_restore_seed'
self._back = _back = partial(self.ids.back.dispatch, 'on_release') self._back = _back = partial(self.ids.back.dispatch, 'on_release')
app.navigation_higherarchy.append(_back) app.navigation_higherarchy.append(_back)
def on_key_down(self, keyboard, keycode, key, modifiers):
if keycode[1] == 'enter':
self.on_enter()
#super
def on_enter(self):
self._remove_keyboard()
# press next
self.ids.next.dispatch('on_release')
def _remove_keyboard(self):
tis = self.ids.text_input_seed
if tis._keyboard:
tis._keyboard.unbind(on_key_down=self.on_key_down)
tis.focus = False
def close(self): def close(self):
self._remove_keyboard()
if self._back in app.navigation_higherarchy: if self._back in app.navigation_higherarchy:
app.navigation_higherarchy.pop() app.navigation_higherarchy.pop()
self._back = None self._back = None
@ -540,6 +580,7 @@ class ChangePasswordDialog(CreateAccountDialog):
if value: if value:
stepper = self.ids.stepper stepper = self.ids.stepper
stepper.opacity = 1 stepper.opacity = 1
self.ids.ti_wallet_name.focus = True
stepper.source = 'atlas://gui/kivy/theming/light/stepper_left' stepper.source = 'atlas://gui/kivy/theming/light/stepper_left'
self._back = _back = partial(self.ids.back.dispatch, 'on_release') self._back = _back = partial(self.ids.back.dispatch, 'on_release')
app.navigation_higherarchy.append(_back) app.navigation_higherarchy.append(_back)

View File

@ -20,6 +20,13 @@ app = App.get_running_app()
class InstallWizard(Widget): class InstallWizard(Widget):
'''Instalation Wizzard. Responsible for instantiating the
creation/restoration of wallets.
events::
`on_wizard_complete` Fired when the wizard is done creating/ restoring
wallet/s.
'''
__events__ = ('on_wizard_complete', ) __events__ = ('on_wizard_complete', )
@ -33,13 +40,15 @@ class InstallWizard(Widget):
msg= _("Electrum is generating your addresses," msg= _("Electrum is generating your addresses,"
" please wait."), " please wait."),
on_complete=None): on_complete=None):
'''Perform a blocking task in the background by running the passed
method in a thread.
'''
def target(): def target():
# run your threaded function # run your threaded function
task() task()
# on completion hide message # on completion hide message
Clock.schedule_once(lambda dt: Clock.schedule_once(lambda dt: app.info_bubble.hide())
app.show_info_bubble(text="Complete", arrow_pos=None))
# call completion routine # call completion routine
if on_complete: if on_complete:
Clock.schedule_once(lambda dt: on_complete()) Clock.schedule_once(lambda dt: on_complete())
@ -51,12 +60,14 @@ class InstallWizard(Widget):
t.start() t.start()
def run(self): def run(self):
'''Entry point of our Installation wizard
'''
CreateRestoreDialog(on_release=self.on_creatrestore_complete).open() CreateRestoreDialog(on_release=self.on_creatrestore_complete).open()
def on_creatrestore_complete(self, dialog, button): def on_creatrestore_complete(self, dialog, button):
if not button: if not button:
self.dispatch('on_wizard_complete', None) return self.dispatch('on_wizard_complete', None)
return
wallet = Wallet(self.storage) wallet = Wallet(self.storage)
gap = self.config.get('gap_limit', 5) gap = self.config.get('gap_limit', 5)
if gap !=5: if gap !=5:
@ -70,7 +81,7 @@ class InstallWizard(Widget):
elif button == dialog.ids.restore: elif button == dialog.ids.restore:
# restore # restore
self.restore_seed_dialog(wallet) self.restore_seed_dialog(wallet)
#elif button == dialog.ids.watching: #if button == dialog.ids.watching:
#TODO: not available in the new design #TODO: not available in the new design
# self.action = 'watching' # self.action = 'watching'
else: else:
@ -99,30 +110,15 @@ class InstallWizard(Widget):
except Exception: except Exception:
import traceback import traceback
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
app.show_error(_('No account tied to this seedphrase'), exit=True) app.show_error(_('No account tied to this seedphrase'))#, exit=True)
return return
_dlg.close() _dlg.close()
self.change_password_dialog(wallet=wallet, mode='restore') self.change_password_dialog(wallet=wallet, mode='restore')
return return
from pudb import set_trace; set_trace()
wallet = self.wallet
#is_restore = bool(_dlg.__class__ == RestoreSeedDialog)
# Restore
if len(seed) == 128:
wallet.seed = ''
wallet.init_sequence(str(seed))
else:
wallet.seed = ''
wallet.init_seed(str(seed))
wallet.save_seed()
return self.change_network_dialog()
def init_seed_dialog(self, wallet=None, instance=None, password=None, def init_seed_dialog(self, wallet=None, instance=None, password=None,
wallet_name=None): wallet_name=None, mode='create'):
# renamed from show_seed() # renamed from show_seed()
'''Can be called directly (password is None) '''Can be called directly (password is None)
or from a password-protected callback (password is not None)''' or from a password-protected callback (password is not None)'''
@ -131,7 +127,7 @@ class InstallWizard(Widget):
if instance == None: if instance == None:
wallet.init_seed(None) wallet.init_seed(None)
else: else:
return MessageBoxError(message=_('No seed')).open() return app.show_error(_('No seed'))
if password is None or not instance: if password is None or not instance:
seed = wallet.get_mnemonic(None) seed = wallet.get_mnemonic(None)
@ -139,7 +135,7 @@ class InstallWizard(Widget):
try: try:
seed = self.wallet.get_seed(password) seed = self.wallet.get_seed(password)
except Exception: except Exception:
return MessageBoxError(message=_('Incorrect Password')) return app.show_error(_('Incorrect Password'))
brainwallet = seed brainwallet = seed
@ -160,8 +156,10 @@ class InstallWizard(Widget):
def on_ok_press(_dlg, _btn): def on_ok_press(_dlg, _btn):
_dlg.close() _dlg.close()
if _btn != _dlg.ids.confirm: if _btn != _dlg.ids.confirm:
self.change_password_dialog(wallet) if not instance:
self.change_password_dialog(wallet)
return return
# confirm
if instance is None: if instance is None:
# in initial phase # in initial phase
def create(password): def create(password):
@ -173,21 +171,20 @@ class InstallWizard(Widget):
Clock.schedule_once(lambda dt: Clock.schedule_once(lambda dt:
app.show_error(err)) app.show_error(err))
wallet.synchronize() # generate first addresses offline wallet.synchronize() # generate first addresses offline
self.waiting_dialog(partial(create, password), self.waiting_dialog(
on_complete=self.load_network) partial(create, password),
on_complete=partial(self.load_network, wallet, mode=mode))
from electrum_gui.kivy.dialog import InitSeedDialog from electrum_gui.kivy.dialog import InitSeedDialog
InitSeedDialog(message=msg2, InitSeedDialog(message=msg2,
seed_msg=brainwallet, seed_msg=brainwallet, seed=seed, on_release=on_ok_press).open()
seed=seed,
on_release=on_ok_press).open()
def change_password_dialog(self, wallet=None, instance=None, mode='create'): def change_password_dialog(self, wallet=None, instance=None, mode='create'):
"""Can be called directly (instance is None) """Can be called directly (instance is None)
or from a callback (instance is not None)""" or from a callback (instance is not None)"""
if instance and not wallet.seed: if instance and not wallet.seed:
return MessageBoxExit(message=_('No seed !!')).open() return ShowError(_('No seed !!'), exit=True, modal=True)
if instance is not None: if instance is not None:
if wallet.use_encryption: if wallet.use_encryption:
@ -210,9 +207,11 @@ class InstallWizard(Widget):
ti_confirm_password = _dlg.ids.ti_confirm_password ti_confirm_password = _dlg.ids.ti_confirm_password
if _btn != _dlg.ids.next: if _btn != _dlg.ids.next:
if mode == 'restore': if mode == 'restore':
# back is disabled cause seed is already set
return return
_dlg.close() _dlg.close()
if not instance: if not instance:
# back on create
CreateRestoreDialog( CreateRestoreDialog(
on_release=self.on_creatrestore_complete).open() on_release=self.on_creatrestore_complete).open()
return return
@ -236,17 +235,20 @@ class InstallWizard(Widget):
return app.show_error(_('Passwords do not match')) return app.show_error(_('Passwords do not match'))
if mode == 'restore': if mode == 'restore':
try:
wallet.save_seed(new_password)
except Exception as err:
app.show_error(str(err))
return
_dlg.close() _dlg.close()
wallet.save_seed(new_password)
self.load_network(wallet, mode='restore') self.load_network(wallet, mode='restore')
return return
if not instance: if not instance:
# create # create
_dlg.close() _dlg.close()
self.load_network(wallet, mode='create') #self.load_network(wallet, mode='create')
return self.init_seed_dialog(password=new_password, return self.init_seed_dialog(password=new_password,
wallet=wallet, wallet=wallet, wallet_name=wallet_name, mode=mode)
wallet_name=wallet_name)
try: try:
seed = wallet.decode_seed(password) seed = wallet.decode_seed(password)
@ -275,48 +277,44 @@ class InstallWizard(Widget):
mode=mode, mode=mode,
on_release=on_release).open() on_release=on_release).open()
def load_network(self, wallet, mode=None): def load_network(self, wallet, mode='create'):
#if not self.config.get('server'): #if not self.config.get('server'):
if not self.network: if self.network:
return wallet.start_threads(self.network) if self.network.interfaces:
if mode not in ('restore', 'create'):
self.network_dialog()
else:
app.show_error(_('You are offline'))
self.network.stop()
self.network = None
if not self.network.interfaces: if mode in ('restore', 'create'):
app.show_error(_('You are offline')) # auto cycle
self.network.stop() self.config.set_key('auto_cycle', True, True)
self.network = None # start wallet threads
return wallet.start_threads(self.network)
if mode not in ('restore', 'create'):
self.network_dialog()
return wallet.start_threads(self.network)
self.config.set_key('auto_cycle', True, True)
wallet.start_threads(self.network) wallet.start_threads(self.network)
if not mode == 'restore':
return
def get_text(text): def get_text(text):
def set_text(*l): app.info_bubble.ids.lbl.text=text def set_text(*l): app.info_bubble.ids.lbl.text=text
Clock.schedule_once(set_text) Clock.schedule_once(set_text)
def on_complete(*l): def on_complete(*l):
if not self.network: if not self.network:
app.show_info_bubble( app.show_info(_("This wallet was restored offline."
text=_("This wallet was restored offline. It may contain" "It may contain more addresses than displayed."))
" more addresses than displayed."), return self.dispatch('on_wizard_complete', wallet)
width='200dp',
pos=Window.center)
return
if wallet.is_found(): if wallet.is_found():
app.show_info_bubble(_("Recovery successful"), app.show_info(_("Recovery successful"))
width='200dp',
pos=Window.center)
else: else:
app.show_info_bubble(_("No transactions found for this seed"), app.show_info(_("No transactions found for this seed"))
width='200dp', self.dispatch('on_wizard_complete', wallet)
pos=Window.center)
self.waiting_dialog(lambda: wallet.restore(get_text), self.waiting_dialog(lambda: wallet.restore(get_text),
on_complete=on_complete) on_complete=on_complete)
def on_wizard_complete(self, instance, wallet): def on_wizard_complete(self, wallet):
pass pass

View File

@ -94,7 +94,6 @@
height: self.width if self.fs else (lbl.texture_size[1] + dp(27)) height: self.width if self.fs else (lbl.texture_size[1] + dp(27))
BoxLayout: BoxLayout:
padding: '5dp' padding: '5dp'
spacing: '5dp'
Widget: Widget:
size_hint: None, 1 size_hint: None, 1
width: '4dp' if root.fs else '2dp' width: '4dp' if root.fs else '2dp'
@ -104,6 +103,9 @@
mipmap: True mipmap: True
size_hint: None, 1 size_hint: None, 1
width: (root.width - dp(20)) if root.fs else (0 if not root.icon else '32dp') width: (root.width - dp(20)) if root.fs else (0 if not root.icon else '32dp')
Widget:
size_hint_y: None
width: '5dp'
Label: Label:
id: lbl id: lbl
markup: True markup: True

View File

@ -106,7 +106,7 @@ class ElectrumWindow(App):
def on_start(self): def on_start(self):
Window.bind(size=self.on_size, Window.bind(size=self.on_size,
on_keyboard=self.on_keyboard) on_keyboard=self.on_keyboard)
#Window.bind(keyboard_height=self.on_keyboard_height) Window.bind(keyboard_height=self.on_keyboard_height)
self.on_size(Window, Window.size) self.on_size(Window, Window.size)
config = self.electrum_config config = self.electrum_config
storage = WalletStorage(config) storage = WalletStorage(config)
@ -230,17 +230,27 @@ class ElectrumWindow(App):
width='200dp', width='200dp',
pos=None, pos=None,
arrow_pos=None, arrow_pos=None,
exit=False): exit=False,
icon='atlas://gui/kivy/theming/light/error',):
''' Show a error Message Bubble. ''' Show a error Message Bubble.
''' '''
self.show_info_bubble( self.show_info_bubble(
text=error, text=error,
icon='atlas://gui/kivy/theming/light/error', icon=icon,
width=width, width=width,
pos=pos or Window.center, pos=pos or Window.center,
arrow_pos=arrow_pos, arrow_pos=arrow_pos,
exit=exit) exit=exit)
def show_info(self, error,
width='200dp',
pos=None,
arrow_pos=None,
exit=False):
''' Show a Info Message Bubble.
'''
self.show_error(error, icon='atlas://gui/kivy/theming/light/error')
def show_info_bubble(self, def show_info_bubble(self,
text=_('Hello World'), text=_('Hello World'),
pos=(0, 0), pos=(0, 0),
@ -265,8 +275,9 @@ class ElectrumWindow(App):
info_bubble = self.info_bubble = InfoBubble() info_bubble = self.info_bubble = InfoBubble()
if info_bubble.parent: if info_bubble.parent:
info_bubble.hide() Window.remove_widget(info_bubble
return if not info_bubble.modal else
info_bubble._modal_view)
if not arrow_pos: if not arrow_pos:
info_bubble.show_arrow = False info_bubble.show_arrow = False