commit b3ef2249b55d945868706d75baa426d3a1661da2
parent 30ace570d37097cf532910e9fa9b3f42cc488c5a
Author: ThomasV <thomasv@electrum.org>
Date: Wed, 16 Dec 2015 11:53:37 +0100
add more features to settings dialog
Diffstat:
6 files changed, 128 insertions(+), 62 deletions(-)
diff --git a/gui/kivy/main.kv b/gui/kivy/main.kv
@@ -355,7 +355,6 @@
<ActionOvrButton@ActionButton>
on_release:
if self.parent: self.parent.parent.dismiss()
- app.popup_dialog(self.name)
<SettingsItem@ButtonBehavior+BoxLayout>
@@ -417,21 +416,25 @@ BoxLayout:
ActionOverflow:
id: ao
ActionOvrButton:
- text: _('Network')
name: 'network'
+ text: _('Network')
on_parent:
# when widget overflow drop down is shown, adjust the width
parent = args[1]
if parent: ao._dropdown.width = sp(200)
+ on_release: app.popup_dialog(self.name)
ActionOvrButton:
name: 'settings'
text: _('Settings')
+ on_release: app.settings_dialog()
ActionOvrButton:
name: 'wallets'
text: _('Wallets')
+ on_release: app.popup_dialog(self.name)
ActionOvrButton:
name: 'plugins'
text: _('Plugins')
+ on_release: app.popup_dialog(self.name)
ScreenManager:
id: manager
diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py
@@ -57,8 +57,8 @@ from kivy.core.clipboard import Clipboard
Factory.register('TabbedCarousel', module='electrum_gui.kivy.uix.screens')
+from electrum.util import base_units
-base_units = {'BTC':8, 'mBTC':5, 'uBTC':2}
class ElectrumWindow(App):
@@ -75,11 +75,6 @@ class ElectrumWindow(App):
self.history_screen.update()
base_unit = AliasProperty(_get_bu, _set_bu)
-
- def _rotate_bu(self):
- keys = sorted(base_units.keys())
- self.base_unit = keys[ (keys.index(self.base_unit) + 1) % len(keys)]
-
status = StringProperty('')
fiat_unit = StringProperty('')
@@ -341,12 +336,9 @@ class ElectrumWindow(App):
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)
+ def settings_dialog(self):
+ from uix.dialogs.settings import SettingsDialog
+ d = SettingsDialog(self)
d.open()
def on_stop(self):
diff --git a/gui/kivy/uix/dialogs/choice_dialog.py b/gui/kivy/uix/dialogs/choice_dialog.py
@@ -4,6 +4,7 @@ from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.uix.checkbox import CheckBox
from kivy.uix.label import Label
+from kivy.uix.widget import Widget
Builder.load_string('''
<ChoiceDialog@Popup>
@@ -14,17 +15,19 @@ Builder.load_string('''
BoxLayout:
orientation: 'vertical'
Widget:
- size_hint: 1, 0.2
- GridLayout:
+ size_hint: 1, 0.1
+ ScrollView:
orientation: 'vertical'
- id: choices
- cols: 2
- size_hint: 1, 0.8
- Widget:
size_hint: 1, 0.8
+ GridLayout:
+ row_default_height: '48dp'
+ orientation: 'vertical'
+ id: choices
+ cols: 2
+ size_hint: 1, 1
BoxLayout:
orientation: 'horizontal'
- size_hint: 1, 0.5
+ size_hint: 1, 0.2
Button:
text: 'Cancel'
size_hint: 0.5, None
@@ -41,22 +44,22 @@ Builder.load_string('''
class ChoiceDialog(Factory.Popup):
- def __init__(self, title, choices, value, callback):
+ def __init__(self, title, choices, key, callback):
Factory.Popup.__init__(self)
- for k in choices:
- l = Label(text=k)
+ for k, v in choices.items():
+ l = Label(text=v)
l.height = '48dp'
- l.size_hint_y = 1
cb = CheckBox(group='choices')
cb.value = k
- cb.size_hint_y = 1
+ cb.height = '48dp'
def f(cb, x):
if x: self.value = cb.value
cb.bind(active=f)
- if k == value:
+ if k == key:
cb.active = True
self.ids.choices.add_widget(l)
self.ids.choices.add_widget(cb)
+ self.ids.choices.add_widget(Widget(size_hint_y=1))
self.callback = callback
self.title = title
- self.value = value
+ self.value = key
diff --git a/gui/kivy/uix/dialogs/settings.py b/gui/kivy/uix/dialogs/settings.py
@@ -0,0 +1,100 @@
+from kivy.app import App
+from kivy.factory import Factory
+from kivy.properties import ObjectProperty
+from kivy.lang import Builder
+
+from electrum.i18n import _
+from electrum.util import base_units
+from electrum.i18n import languages, set_language
+
+Builder.load_string('''
+<SettingsDialog@Popup>
+ id: settings
+ title: _('Settings')
+ BoxLayout:
+ orientation: 'vertical'
+ SettingsItem:
+ lang: settings.get_language_name()
+ title: _('Language') + ' (%s)'%self.lang
+ description: _("Language")
+ on_release:
+ settings.language_dialog(self)
+ CardSeparator
+ SettingsItem:
+ title: _('PIN Code') + ' (%s)'%('ON' if app.wallet.use_encryption else 'OFF')
+ description: _("Your PIN code will be required in order to spend bitcoins.")
+ on_release:
+ app.change_password()
+ self.title = _('PIN Code') + ' (%s)'%('ON' if app.wallet.use_encryption else 'OFF')
+ CardSeparator
+ SettingsItem:
+ bu: app.base_unit
+ title: _('Denomination') + ' (' + self.bu + ')'
+ description: _("Base unit for Bitcoin amounts.")
+ on_release:
+ settings.unit_dialog(self)
+ CardSeparator
+ SettingsItem:
+ title: _('Fiat Currency')
+ description: "Select the local fiat currency."
+ on_release:
+ settings.fiat_dialog(self)
+ CardSeparator
+ SettingsItem:
+ title: _('OpenAlias')
+ description: "Email-like address."
+ on_release:
+ settings.openalias_dialog()
+ Widget:
+ size_hint: 1, 1
+ BoxLayout:
+ Widget:
+ size_hint: 0.5, None
+ Button:
+ size_hint: 0.5, None
+ height: '48dp'
+ text: _('OK')
+ on_release:
+ settings.dismiss()
+''')
+
+class SettingsDialog(Factory.Popup):
+
+ def __init__(self, app):
+ self.app = app
+ Factory.Popup.__init__(self)
+
+ def get_language_name(self):
+ return languages.get(self.app.electrum_config.get('language', 'en_UK'), '')
+
+ def language_dialog(self, item):
+ from choice_dialog import ChoiceDialog
+ l = self.app.electrum_config.get('language', 'en_UK')
+ def cb(key):
+ set_language(key)
+ self.app.electrum_config.set_key("language", key, True)
+ item.lang = self.get_language_name()
+ d = ChoiceDialog(_('Language'), languages, l, cb)
+ d.open()
+
+ def unit_dialog(self, item):
+ from choice_dialog import ChoiceDialog
+ def cb(text):
+ self.app._set_bu(text)
+ item.bu = self.app.base_unit
+ d = ChoiceDialog(_('Denomination'), dict(map(lambda x: (x,x), base_units)), self.app.base_unit, cb)
+ d.open()
+
+ def fiat_dialog(self, item):
+ from choice_dialog import ChoiceDialog
+ def cb(text):
+ pass
+ d = ChoiceDialog(_('Fiat Currency'), {}, '', cb)
+ d.open()
+
+ def openalias_dialog(self):
+ from label_dialog import LabelDialog
+ def callback(text):
+ pass
+ d = LabelDialog(_('OpenAlias'), '', callback)
+ d.open()
diff --git a/gui/kivy/uix/ui_screens/settings.kv b/gui/kivy/uix/ui_screens/settings.kv
@@ -1,34 +0,0 @@
-Popup:
- id: settings
- title: _('Settings')
- BoxLayout:
- orientation: 'vertical'
- SettingsItem:
- title: _('PIN Code') + ' (%s)'%('ON' if app.wallet.use_encryption else 'OFF')
- description: _("Your PIN code will be required in order to spend bitcoins.")
- on_release:
- app.change_password()
- self.title = _('PIN Code') + ' (%s)'%('ON' if app.wallet.use_encryption else 'OFF')
- CardSeparator
- SettingsItem:
- bu: app.base_unit
- title: _('Denomination') + ' (' + self.bu + ')'
- description: _("Base unit for Bitcoin amounts.")
- on_release:
- app.unit_dialog(self)
- CardSeparator
- SettingsItem:
- title: _('OpenAlias')
- description: "Email-like address."
- Widget:
- size_hint: 1, 1
- BoxLayout:
- Widget:
- size_hint: 0.5, None
- Button:
- size_hint: 0.5, None
- height: '48dp'
- text: _('OK')
- on_release:
- settings.dismiss()
-
diff --git a/lib/util.py b/lib/util.py
@@ -10,6 +10,8 @@ import urllib
import threading
from i18n import _
+base_units = {'BTC':8, 'mBTC':5, 'uBTC':2}
+
def normalize_version(v):
return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]