Browse Source

kivy: wallets and settings menus

283
ThomasV 9 years ago
parent
commit
ff163e34d8
  1. 2
      gui/kivy/__init__.py
  2. 30
      gui/kivy/main.kv
  3. 47
      gui/kivy/main_window.py
  4. 4
      gui/kivy/uix/dialogs/create_restore.py
  5. 81
      gui/kivy/uix/dialogs/settings.py
  6. 12
      gui/kivy/uix/ui_screens/about.kv
  7. 27
      gui/kivy/uix/ui_screens/plugins.kv
  8. 47
      gui/kivy/uix/ui_screens/wallets.kv

2
gui/kivy/__init__.py

@ -29,6 +29,7 @@ except ImportError:
# minimum required version for kivy # minimum required version for kivy
kivy.require('1.8.0') kivy.require('1.8.0')
from electrum.i18n import set_language
from kivy.logger import Logger from kivy.logger import Logger
from main_window import ElectrumWindow from main_window import ElectrumWindow
@ -39,6 +40,7 @@ class ElectrumGui:
self.network = network self.network = network
self.config = config self.config = config
self.plugins = plugins self.plugins = plugins
set_language(config.get('language'))
def main(self): def main(self):
w = ElectrumWindow(config=self.config, w = ElectrumWindow(config=self.config,

30
gui/kivy/main.kv

@ -358,28 +358,8 @@
Clock.schedule_once(lambda dt: self.parent.parent.dismiss() if self.parent else None, 0.05) Clock.schedule_once(lambda dt: self.parent.parent.dismiss() if self.parent else None, 0.05)
Clock.schedule_once(lambda dt: app.popup_dialog(self.name), 0.05) Clock.schedule_once(lambda dt: app.popup_dialog(self.name), 0.05)
<SettingsItem@ButtonBehavior+BoxLayout>
orientation: 'vertical'
title: ''
description: ''
size_hint: 1, 1
Label:
id: title
text: self.parent.title
size_hint: 1, 1
bold: True
text_size: self.size
halign: 'left'
Label:
text: self.parent.description
size_hint: 1, 1
text_size: self.width, None
color: 0.8, 0.8, 0.8, 1
halign: 'left'
BoxLayout: BoxLayout:
orientation: 'vertical' orientation: 'vertical'
canvas.before: canvas.before:
@ -416,6 +396,9 @@ BoxLayout:
ActionOverflow: ActionOverflow:
id: ao id: ao
ActionOvrButton:
name: 'about'
text: _('About')
ActionOvrButton: ActionOvrButton:
name: 'network' name: 'network'
text: _('Network') text: _('Network')
@ -423,15 +406,12 @@ BoxLayout:
# when widget overflow drop down is shown, adjust the width # when widget overflow drop down is shown, adjust the width
parent = args[1] parent = args[1]
if parent: ao._dropdown.width = sp(200) if parent: ao._dropdown.width = sp(200)
ActionOvrButton:
name: 'settings'
text: _('Settings')
ActionOvrButton: ActionOvrButton:
name: 'wallets' name: 'wallets'
text: _('Wallets') text: _('Wallets')
ActionOvrButton: ActionOvrButton:
name: 'plugins' name: 'settings'
text: _('Plugins') text: _('Settings')
ScreenManager: ScreenManager:
id: manager id: manager
ScreenTabs: ScreenTabs:

47
gui/kivy/main_window.py

@ -7,7 +7,7 @@ from decimal import Decimal
import electrum import electrum
from electrum import WalletStorage, Wallet from electrum import WalletStorage, Wallet
from electrum.i18n import _, set_language from electrum.i18n import _
from electrum.contacts import Contacts from electrum.contacts import Contacts
from electrum.paymentrequest import InvoiceStore from electrum.paymentrequest import InvoiceStore
from electrum.util import profiler, InvalidPassword from electrum.util import profiler, InvalidPassword
@ -253,22 +253,6 @@ class ElectrumWindow(App):
activity.bind(on_activity_result=on_qr_result) activity.bind(on_activity_result=on_qr_result)
PythonActivity.mActivity.startActivityForResult(intent, 0) PythonActivity.mActivity.startActivityForResult(intent, 0)
def show_plugins(self, plugins_list):
def on_active(sw, value):
self.plugins.toggle_enabled(self.electrum_config, sw.name)
run_hook('init_kivy', self)
for item in self.plugins.descriptions:
if 'kivy' not in item.get('available_for', []):
continue
name = item.get('__name__')
label = Label(text=item.get('fullname'), height='48db', size_hint=(1, None))
plugins_list.add_widget(label)
sw = Switch()
sw.name = name
p = self.plugins.get(name)
sw.active = (p is not None) and p.is_enabled()
sw.bind(active=on_active)
plugins_list.add_widget(sw)
def build(self): def build(self):
return Builder.load_file('gui/kivy/main.kv') return Builder.load_file('gui/kivy/main.kv')
@ -305,6 +289,7 @@ class ElectrumWindow(App):
win.bind(keyboard_height=self.on_keyboard_height) win.bind(keyboard_height=self.on_keyboard_height)
self.on_size(win, win.size) self.on_size(win, win.size)
self.init_ui()
self.load_wallet_by_name(self.electrum_config.get_wallet_path()) self.load_wallet_by_name(self.electrum_config.get_wallet_path())
def load_wallet_by_name(self, wallet_path): def load_wallet_by_name(self, wallet_path):
@ -324,16 +309,20 @@ class ElectrumWindow(App):
# start installation wizard # start installation wizard
Logger.debug('Electrum: Wallet not found. Launching install wizard') Logger.debug('Electrum: Wallet not found. Launching install wizard')
wizard = Factory.InstallWizard(config, self.network, storage) wizard = Factory.InstallWizard(config, self.network, storage)
wizard.bind(on_wizard_complete=self.on_wizard_complete) wizard.bind(on_wizard_complete=lambda instance, wallet: self.load_wallet(wallet))
wizard.run(action) wizard.run(action)
else: else:
wallet.start_threads(self.network) wallet.start_threads(self.network)
self.on_wizard_complete(None, wallet) self.load_wallet(wallet)
self.on_resume() self.on_resume()
def create_wallet_dialog(self): def create_wallet_dialog(self, l):
from uix.dialogs.label_dialog import LabelDialog from uix.dialogs.label_dialog import LabelDialog
d = LabelDialog(_('Enter wallet name'), '', self.load_wallet_by_name) def f(text):
if text:
l.text = text
d = LabelDialog(_('Enter wallet name'), '', f)
d.open() d.open()
def settings_dialog(self): def settings_dialog(self):
@ -364,7 +353,6 @@ class ElectrumWindow(App):
active_widg = self.root.children[0] active_widg = self.root.children[0]
except IndexError: except IndexError:
return return
try: try:
fw = self._focused_widget fw = self._focused_widget
except AttributeError: except AttributeError:
@ -398,16 +386,6 @@ class ElectrumWindow(App):
self.gui.main_gui.toggle_settings(self) self.gui.main_gui.toggle_settings(self)
return True return True
def on_wizard_complete(self, instance, wallet):
if not wallet:
Logger.debug('Electrum: No Wallet set/found. Exiting...')
app = App.get_running_app()
app.show_error('Electrum: No Wallet set/found. Exiting...',
exit=True)
self.init_ui()
self.load_wallet(wallet)
def popup_dialog(self, name): def popup_dialog(self, name):
if name == 'settings': if name == 'settings':
self.settings_dialog() self.settings_dialog()
@ -415,15 +393,12 @@ class ElectrumWindow(App):
popup = Builder.load_file('gui/kivy/uix/ui_screens/'+name+'.kv') popup = Builder.load_file('gui/kivy/uix/ui_screens/'+name+'.kv')
popup.open() popup.open()
@profiler @profiler
def init_ui(self): def init_ui(self):
''' Initialize The Ux part of electrum. This function performs the basic ''' Initialize The Ux part of electrum. This function performs the basic
tasks of setting up the ui. tasks of setting up the ui.
''' '''
from weakref import ref from weakref import ref
set_language(self.electrum_config.get('language'))
self.funds_error = False self.funds_error = False
# setup UX # setup UX
@ -540,6 +515,7 @@ class ElectrumWindow(App):
@profiler @profiler
def update_wallet(self, *dt): def update_wallet(self, *dt):
print "update wallet"
self._trigger_update_status() self._trigger_update_status()
if self.wallet.up_to_date or not self.network or not self.network.is_connected(): if self.wallet.up_to_date or not self.network or not self.network.is_connected():
self.update_history_tab() self.update_history_tab()
@ -549,6 +525,7 @@ class ElectrumWindow(App):
@profiler @profiler
def update_history_tab(self, see_all=False): def update_history_tab(self, see_all=False):
if self.history_screen: if self.history_screen:
print "blah"
self.history_screen.update(see_all) self.history_screen.update(see_all)
def update_contacts_tab(self): def update_contacts_tab(self):

4
gui/kivy/uix/dialogs/create_restore.py

@ -140,11 +140,11 @@ Builder.load_string('''
height: self.minimum_height height: self.minimum_height
CreateAccountButton: CreateAccountButton:
id: create id: create
text: _('Create a Wallet') text: _('Create a new seed')
root: root root: root
CreateAccountButton: CreateAccountButton:
id: restore id: restore
text: _('I already have a wallet') text: _('I already have a seed')
root: root root: root

81
gui/kivy/uix/dialogs/settings.py

@ -8,6 +8,49 @@ from electrum.util import base_units
from electrum.i18n import languages, set_language from electrum.i18n import languages, set_language
Builder.load_string(''' Builder.load_string('''
<SettingsItem@ButtonBehavior+BoxLayout>
orientation: 'vertical'
title: ''
description: ''
size_hint: 1, 1
Label:
id: title
text: self.parent.title
size_hint: 1, 1
bold: True
text_size: self.size
halign: 'left'
Label:
text: self.parent.description
size_hint: 1, 1
text_size: self.width, None
color: 0.8, 0.8, 0.8, 1
halign: 'left'
<PluginItem@ButtonBehavior+BoxLayout>
orientation: 'vertical'
title: ''
description: ''
size_hint: 1, 1
BoxLayout:
orientation: 'horizontal'
Label:
id: title
text: self.parent.title
size_hint: 1, 1
bold: True
text_size: self.size
halign: 'left'
Switch:
id: sw
name: ''
Label:
text: self.parent.description
size_hint: 1, 1
text_size: self.width, None
color: 0.8, 0.8, 0.8, 1
halign: 'left'
<SettingsDialog@Popup> <SettingsDialog@Popup>
id: settings id: settings
title: _('Settings') title: _('Settings')
@ -15,13 +58,13 @@ Builder.load_string('''
orientation: 'vertical' orientation: 'vertical'
SettingsItem: SettingsItem:
lang: settings.get_language_name() lang: settings.get_language_name()
title: _('Language') + ' (%s)'%self.lang title: _('Language') + ': %s'%self.lang
description: _("Language") description: _("Language")
on_release: on_release:
settings.language_dialog(self) settings.language_dialog(self)
CardSeparator CardSeparator
SettingsItem: SettingsItem:
title: _('PIN Code') + ' (%s)'%('ON' if app.wallet.use_encryption else 'OFF') title: _('PIN Code') + ': %s'%('ON' if app.wallet.use_encryption else 'OFF')
description: _("Your PIN code will be required in order to spend bitcoins.") description: _("Your PIN code will be required in order to spend bitcoins.")
on_release: on_release:
app.change_password() app.change_password()
@ -29,13 +72,13 @@ Builder.load_string('''
CardSeparator CardSeparator
SettingsItem: SettingsItem:
bu: app.base_unit bu: app.base_unit
title: _('Denomination') + ' (' + self.bu + ')' title: _('Denomination') + ': ' + self.bu
description: _("Base unit for Bitcoin amounts.") description: _("Base unit for Bitcoin amounts.")
on_release: on_release:
settings.unit_dialog(self) settings.unit_dialog(self)
CardSeparator CardSeparator
SettingsItem: SettingsItem:
title: _('Fiat Currency') title: _('Fiat Currency') + ': ' + app.fiat_unit
description: "Select the local fiat currency." description: "Select the local fiat currency."
on_release: on_release:
settings.fiat_dialog(self) settings.fiat_dialog(self)
@ -71,9 +114,9 @@ class SettingsDialog(Factory.Popup):
from choice_dialog import ChoiceDialog from choice_dialog import ChoiceDialog
l = self.app.electrum_config.get('language', 'en_UK') l = self.app.electrum_config.get('language', 'en_UK')
def cb(key): def cb(key):
set_language(key)
self.app.electrum_config.set_key("language", key, True) self.app.electrum_config.set_key("language", key, True)
item.lang = self.get_language_name() item.lang = self.get_language_name()
set_language(key)
d = ChoiceDialog(_('Language'), languages, l, cb) d = ChoiceDialog(_('Language'), languages, l, cb)
d.open() d.open()
@ -98,3 +141,31 @@ class SettingsDialog(Factory.Popup):
pass pass
d = LabelDialog(_('OpenAlias'), '', callback) d = LabelDialog(_('OpenAlias'), '', callback)
d.open() d.open()
def show_plugins(self, plugins_list):
def on_active(sw, value):
self.plugins.toggle_enabled(self.electrum_config, sw.name)
run_hook('init_kivy', self)
for item in self.plugins.descriptions:
if 'kivy' not in item.get('available_for', []):
continue
name = item.get('__name__')
label = Label(text=item.get('fullname'), height='48db', size_hint=(1, None))
plugins_list.add_widget(label)
sw = Switch()
sw.name = name
p = self.plugins.get(name)
sw.active = (p is not None) and p.is_enabled()
sw.bind(active=on_active)
plugins_list.add_widget(sw)
class PluginItem():
def __init__(self, name):
p = self.plugins.get(name)
sw.active = (p is not None) and p.is_enabled()
sw.bind(active=on_active)
plugins_list.add_widget(sw)

12
gui/kivy/uix/ui_screens/about.kv

@ -0,0 +1,12 @@
Popup:
title: "About Electrum"
BoxLayout:
orientation: 'vertical'
spacing: '1dp'
Label:
text: "Lightweight Bitcoin Wallet"
Label:
text: "Author: Thomas Voegtlin"
Label:
text: "https://electrum.org"
Widget

27
gui/kivy/uix/ui_screens/plugins.kv

@ -1,27 +0,0 @@
Popup:
title: _('Plugins')
id: popup
BoxLayout:
orientation: 'vertical'
GridLayout:
cols: 2
size_hint: 1, None
height: '100dp'
id: plugins_list
on_parent:
app.show_plugins(plugins_list)
Widget:
size_hint: 1, 1
BoxLayout:
Widget:
size_hint: 0.5, None
Button:
size_hint: 0.5, None
height: '48dp'
text: _('OK')
on_release:
popup.dismiss()

47
gui/kivy/uix/ui_screens/wallets.kv

@ -3,43 +3,52 @@
Popup: Popup:
title: _('Wallets') title: _('Wallets')
id: popup id: popup
path: app.wallet.storage.path
on_path:
button.text = _('Open') if os.path.exists(popup.path) else _('Create')
BoxLayout: BoxLayout:
orientation: 'vertical' orientation: 'vertical'
Label: BoxLayout:
id: text_input height: '48dp'
height: '32dp'
size_hint_y: None size_hint_y: None
text: os.path.basename(app.wallet.storage.path) orientation: 'horizontal'
Label:
text: _('Wallet') + ': '
height: '48dp'
size_hint_y: None
Button:
id: wallet_name
height: '48dp'
size_hint_y: None
text: os.path.basename(app.wallet.storage.path)
on_release:
app.create_wallet_dialog(self)
on_text:
popup.path = os.path.join(wallet_selector.path, self.text)
Widget Widget
size_hint_y: None size_hint_y: None
FileChooserListView: FileChooserListView:
id: wallet_selector id: wallet_selector
path: os.path.dirname(app.wallet.storage.path) path: os.path.dirname(app.wallet.storage.path)
on_selection: on_selection:
text_input.text = os.path.basename(self.selection[0]) if self.selection else '' wallet_name.text = os.path.basename(self.selection[0]) if self.selection else ''
size_hint: 1, 1 size_hint_y: 0.5
Widget
size_hint_y: 0.1
GridLayout: GridLayout:
cols: 3 cols: 2
size_hint_y: None size_hint_y: None
Button: Button:
size_hint: 0.5, None size_hint: 0.5, None
height: '48dp' height: '48dp'
text: _('Create') text: _('Cancel')
on_release:
popup.dismiss()
app.create_wallet_dialog()
Button:
size_hint: 0.5, None
height: '48dp'
text: _('Open')
on_release: on_release:
popup.dismiss() popup.dismiss()
app.open_wallet(text_input.text)
Button: Button:
id: button
size_hint: 0.5, None size_hint: 0.5, None
height: '48dp' height: '48dp'
text: _('Cancel') text: _('Open') if os.path.exists(popup.path) else _('Create')
on_release: on_release:
popup.dismiss() popup.dismiss()
app.load_wallet_by_name(popup.path)

Loading…
Cancel
Save