kivy: choice_dialog and load_wallet_by_name

This commit is contained in:
ThomasV 2015-12-16 08:57:47 +01:00
parent 9d3162b1a1
commit 30ace570d3
5 changed files with 118 additions and 29 deletions

View File

@ -310,17 +310,21 @@ class ElectrumWindow(App):
win.bind(keyboard_height=self.on_keyboard_height)
self.on_size(win, win.size)
self.load_wallet_by_name(self.electrum_config.get_wallet_path())
def load_wallet_by_name(self, wallet_path):
if not wallet_path:
return
self.stop_wallet()
config = self.electrum_config
storage = WalletStorage(config.get_wallet_path())
storage = WalletStorage(wallet_path)
Logger.info('Electrum: Check for existing wallet')
if storage.file_exists:
wallet = Wallet(storage)
action = wallet.get_action()
else:
action = 'new'
if action is not None:
# start installation wizard
Logger.debug('Electrum: Wallet not found. Launching install wizard')
@ -330,10 +334,25 @@ class ElectrumWindow(App):
else:
wallet.start_threads(self.network)
self.on_wizard_complete(None, wallet)
self.on_resume()
def create_wallet_dialog(self):
from uix.dialogs.label_dialog import LabelDialog
d = LabelDialog(_('Enter wallet name'), '', self.load_wallet_by_name)
d.open()
def unit_dialog(self, item):
from uix.dialogs.choice_dialog import ChoiceDialog
def cb(text):
self._set_bu(text)
item.bu = self.base_unit
d = ChoiceDialog(_('Denomination'), sorted(base_units.keys()), self.base_unit, cb)
d.open()
def on_stop(self):
self.stop_wallet()
def stop_wallet(self):
if self.wallet:
self.wallet.stop_threads()
@ -438,7 +457,7 @@ class ElectrumWindow(App):
interests = ['updated', 'status', 'new_transaction']
self.network.register_callback(self.on_network, interests)
self.wallet = None
#self.wallet = None
self.tabs = self.root.ids['tabs']
def on_network(self, event, *args):

View File

@ -0,0 +1,62 @@
from kivy.app import App
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.uix.checkbox import CheckBox
from kivy.uix.label import Label
Builder.load_string('''
<ChoiceDialog@Popup>
id: popup
title: ''
size_hint: 0.8, 0.8
pos_hint: {'top':0.9}
BoxLayout:
orientation: 'vertical'
Widget:
size_hint: 1, 0.2
GridLayout:
orientation: 'vertical'
id: choices
cols: 2
size_hint: 1, 0.8
Widget:
size_hint: 1, 0.8
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.5
Button:
text: 'Cancel'
size_hint: 0.5, None
height: '48dp'
on_release: popup.dismiss()
Button:
text: 'OK'
size_hint: 0.5, None
height: '48dp'
on_release:
root.callback(popup.value)
popup.dismiss()
''')
class ChoiceDialog(Factory.Popup):
def __init__(self, title, choices, value, callback):
Factory.Popup.__init__(self)
for k in choices:
l = Label(text=k)
l.height = '48dp'
l.size_hint_y = 1
cb = CheckBox(group='choices')
cb.value = k
cb.size_hint_y = 1
def f(cb, x):
if x: self.value = cb.value
cb.bind(active=f)
if k == value:
cb.active = True
self.ids.choices.add_widget(l)
self.ids.choices.add_widget(cb)
self.callback = callback
self.title = title
self.value = value

View File

@ -1,7 +1,6 @@
Popup:
id: settings
title: _('Settings')
BoxLayout:
orientation: 'vertical'
SettingsItem:
@ -12,19 +11,17 @@ Popup:
self.title = _('PIN Code') + ' (%s)'%('ON' if app.wallet.use_encryption else 'OFF')
CardSeparator
SettingsItem:
title: _('Denomination') + ' (' + app.base_unit + ')'
bu: app.base_unit
title: _('Denomination') + ' (' + self.bu + ')'
description: _("Base unit for Bitcoin amounts.")
on_release:
app._rotate_bu()
self.title = _('Denomination') + ' (' + app.base_unit + ')'
app.unit_dialog(self)
CardSeparator
SettingsItem:
title: _('OpenAlias')
description: "Email-like address."
Widget:
size_hint: 1, 1
BoxLayout:
Widget:
size_hint: 0.5, None

View File

@ -5,31 +5,41 @@ Popup:
id: popup
BoxLayout:
orientation: 'vertical'
GridLayout:
Label:
id: text_input
height: '32dp'
size_hint_y: None
text: os.path.basename(app.wallet.storage.path)
Widget
size_hint_y: None
cols: 2
Label:
height: '32dp'
size_hint_y: None
text: _('Wallet file') + ':'
TextInput:
id: text_input
height: '32dp'
size_hint_y: None
text: os.path.basename(app.wallet.storage.path)
FileChooserIconView:
FileChooserListView:
id: wallet_selector
path: os.path.dirname(app.wallet.storage.path)
on_selection: text_input.text = os.path.basename(self.selection[0]) if self.selection else ''
on_selection:
text_input.text = os.path.basename(self.selection[0]) if self.selection else ''
size_hint: 1, 1
BoxLayout:
Widget:
size_hint: 0.5, None
GridLayout:
cols: 3
size_hint_y: None
Button:
size_hint: 0.5, None
height: '48dp'
text: _('OK')
text: _('Create')
on_release:
popup.dismiss()
app.create_wallet_dialog()
Button:
size_hint: 0.5, None
height: '48dp'
text: _('Open')
on_release:
popup.dismiss()
app.open_wallet(text_input.text)
Button:
size_hint: 0.5, None
height: '48dp'
text: _('Cancel')
on_release:
popup.dismiss()

View File

@ -761,6 +761,7 @@ class Transaction:
return out
def sign(self, keypairs):
print "sign"
for i, txin in enumerate(self.inputs):
num = txin['num_sig']
for x_pubkey in txin['x_pubkeys']: