mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 01:35:20 +00:00
kivy: improve settings dialog
This commit is contained in:
parent
6aea1e8a79
commit
8ed443b4c8
3 changed files with 93 additions and 32 deletions
52
gui/kivy/uix/dialogs/checkbox_dialog.py
Normal file
52
gui/kivy/uix/dialogs/checkbox_dialog.py
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
from kivy.app import App
|
||||||
|
from kivy.factory import Factory
|
||||||
|
from kivy.properties import ObjectProperty
|
||||||
|
from kivy.lang import Builder
|
||||||
|
|
||||||
|
Builder.load_string('''
|
||||||
|
<CheckBoxDialog@Popup>
|
||||||
|
id: popup
|
||||||
|
title: ''
|
||||||
|
size_hint: 0.8, 0.5
|
||||||
|
pos_hint: {'top':0.9}
|
||||||
|
BoxLayout:
|
||||||
|
orientation: 'vertical'
|
||||||
|
Label:
|
||||||
|
id: description
|
||||||
|
text: ''
|
||||||
|
size_hint: 1, 1
|
||||||
|
halign: 'left'
|
||||||
|
text_size: self.width, None
|
||||||
|
BoxLayout:
|
||||||
|
orientation: 'horizontal'
|
||||||
|
size_hint: 1, 1
|
||||||
|
Label:
|
||||||
|
text: _('Enable')
|
||||||
|
CheckBox:
|
||||||
|
id:cb
|
||||||
|
Widget:
|
||||||
|
size_hint: 1, 1
|
||||||
|
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(cb.active)
|
||||||
|
popup.dismiss()
|
||||||
|
''')
|
||||||
|
|
||||||
|
class CheckBoxDialog(Factory.Popup):
|
||||||
|
def __init__(self, title, text, status, callback):
|
||||||
|
Factory.Popup.__init__(self)
|
||||||
|
self.ids.cb.active = status
|
||||||
|
self.ids.description.text = text
|
||||||
|
self.callback = callback
|
||||||
|
self.title = title
|
|
@ -6,6 +6,7 @@ from kivy.lang import Builder
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.util import base_units
|
from electrum.util import base_units
|
||||||
from electrum.i18n import languages, set_language
|
from electrum.i18n import languages, set_language
|
||||||
|
from electrum.plugins import run_hook
|
||||||
|
|
||||||
Builder.load_string('''
|
Builder.load_string('''
|
||||||
<SettingsItem@ButtonBehavior+BoxLayout>
|
<SettingsItem@ButtonBehavior+BoxLayout>
|
||||||
|
@ -16,16 +17,16 @@ Builder.load_string('''
|
||||||
Label:
|
Label:
|
||||||
id: title
|
id: title
|
||||||
text: self.parent.title
|
text: self.parent.title
|
||||||
size_hint: 1, 1
|
|
||||||
bold: True
|
bold: True
|
||||||
text_size: self.size
|
|
||||||
halign: 'left'
|
halign: 'left'
|
||||||
Label:
|
|
||||||
text: self.parent.description
|
|
||||||
size_hint: 1, 1
|
size_hint: 1, 1
|
||||||
text_size: self.width, None
|
text_size: self.width, None
|
||||||
|
Label:
|
||||||
|
text: self.parent.description
|
||||||
color: 0.8, 0.8, 0.8, 1
|
color: 0.8, 0.8, 0.8, 1
|
||||||
|
size_hint: 1, 1
|
||||||
halign: 'left'
|
halign: 'left'
|
||||||
|
text_size: self.width, None
|
||||||
|
|
||||||
<PluginItem@ButtonBehavior+BoxLayout>
|
<PluginItem@ButtonBehavior+BoxLayout>
|
||||||
orientation: 'vertical'
|
orientation: 'vertical'
|
||||||
|
@ -64,11 +65,12 @@ Builder.load_string('''
|
||||||
settings.language_dialog(self)
|
settings.language_dialog(self)
|
||||||
CardSeparator
|
CardSeparator
|
||||||
SettingsItem:
|
SettingsItem:
|
||||||
title: _('PIN Code') + ': %s'%('ON' if app.wallet.use_encryption else 'OFF')
|
status: 'ON' if app.wallet.use_encryption else 'OFF'
|
||||||
description: _("Your PIN code will be required in order to spend bitcoins.")
|
title: _('PIN code') + ': ' + self.status
|
||||||
|
description: _("Change your PIN code.")
|
||||||
on_release:
|
on_release:
|
||||||
app.change_password()
|
app.change_password()
|
||||||
self.title = _('PIN Code') + ' (%s)'%('ON' if app.wallet.use_encryption else 'OFF')
|
self.status = 'ON' if app.wallet.use_encryption else 'OFF'
|
||||||
CardSeparator
|
CardSeparator
|
||||||
SettingsItem:
|
SettingsItem:
|
||||||
bu: app.base_unit
|
bu: app.base_unit
|
||||||
|
@ -83,9 +85,16 @@ Builder.load_string('''
|
||||||
on_release:
|
on_release:
|
||||||
settings.fiat_dialog(self)
|
settings.fiat_dialog(self)
|
||||||
CardSeparator
|
CardSeparator
|
||||||
|
SettingsItem:
|
||||||
|
status: 'ON' if bool(app.plugins.get('labels')) else 'OFF'
|
||||||
|
title: _('Labels Sync') + ': ' + self.status
|
||||||
|
description: "Synchronize labels."
|
||||||
|
on_release:
|
||||||
|
settings.labelsync_dialog(self)
|
||||||
|
CardSeparator
|
||||||
SettingsItem:
|
SettingsItem:
|
||||||
title: _('OpenAlias')
|
title: _('OpenAlias')
|
||||||
description: "Email-like address."
|
description: "DNS record that stores one of your Bitcoin addresses."
|
||||||
on_release:
|
on_release:
|
||||||
settings.openalias_dialog()
|
settings.openalias_dialog()
|
||||||
Widget:
|
Widget:
|
||||||
|
@ -105,16 +114,18 @@ class SettingsDialog(Factory.Popup):
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
|
self.plugins = self.app.plugins
|
||||||
|
self.config = self.app.electrum_config
|
||||||
Factory.Popup.__init__(self)
|
Factory.Popup.__init__(self)
|
||||||
|
|
||||||
def get_language_name(self):
|
def get_language_name(self):
|
||||||
return languages.get(self.app.electrum_config.get('language', 'en_UK'), '')
|
return languages.get(self.config.get('language', 'en_UK'), '')
|
||||||
|
|
||||||
def language_dialog(self, item):
|
def language_dialog(self, item):
|
||||||
from choice_dialog import ChoiceDialog
|
from choice_dialog import ChoiceDialog
|
||||||
l = self.app.electrum_config.get('language', 'en_UK')
|
l = self.config.get('language', 'en_UK')
|
||||||
def cb(key):
|
def cb(key):
|
||||||
self.app.electrum_config.set_key("language", key, True)
|
self.config.set_key("language", key, True)
|
||||||
item.lang = self.get_language_name()
|
item.lang = self.get_language_name()
|
||||||
set_language(key)
|
set_language(key)
|
||||||
d = ChoiceDialog(_('Language'), languages, l, cb)
|
d = ChoiceDialog(_('Language'), languages, l, cb)
|
||||||
|
@ -131,8 +142,14 @@ class SettingsDialog(Factory.Popup):
|
||||||
def fiat_dialog(self, item):
|
def fiat_dialog(self, item):
|
||||||
from choice_dialog import ChoiceDialog
|
from choice_dialog import ChoiceDialog
|
||||||
def cb(text):
|
def cb(text):
|
||||||
pass
|
if text == 'None':
|
||||||
d = ChoiceDialog(_('Fiat Currency'), {}, '', cb)
|
self.plugins.disable('exchange_rate')
|
||||||
|
else:
|
||||||
|
self.config.set_key('currency', text, True)
|
||||||
|
p = self.app.plugins.enable('exchange_rate')
|
||||||
|
p.init_kivy(self.app)
|
||||||
|
|
||||||
|
d = ChoiceDialog(_('Fiat Currency'), { 'None': 'None', 'USD':'USD', 'EUR':'EUR'}, '', cb)
|
||||||
d.open()
|
d.open()
|
||||||
|
|
||||||
def openalias_dialog(self):
|
def openalias_dialog(self):
|
||||||
|
@ -142,25 +159,17 @@ class SettingsDialog(Factory.Popup):
|
||||||
d = LabelDialog(_('OpenAlias'), '', callback)
|
d = LabelDialog(_('OpenAlias'), '', callback)
|
||||||
d.open()
|
d.open()
|
||||||
|
|
||||||
|
def labelsync_dialog(self, label):
|
||||||
|
from checkbox_dialog import CheckBoxDialog
|
||||||
|
def callback(status):
|
||||||
|
self.plugins.enable('labels') if status else self.plugins.disable('labels')
|
||||||
|
status = bool(self.plugins.get('labels'))
|
||||||
|
label.status = 'ON' if status else 'OFF'
|
||||||
|
status = bool(self.plugins.get('labels'))
|
||||||
|
descr = _('Save your labels on a remote server, and synchronizes them between various instances of your wallet.')
|
||||||
|
d = CheckBoxDialog(_('Labels Sync'), descr, status, callback)
|
||||||
|
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():
|
class PluginItem():
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
|
|
|
@ -294,7 +294,7 @@ class FxPlugin(BasePlugin, ThreadJob):
|
||||||
return self.config.get("currency", "EUR")
|
return self.config.get("currency", "EUR")
|
||||||
|
|
||||||
def config_exchange(self):
|
def config_exchange(self):
|
||||||
return self.config.get('use_exchange', 'Blockchain')
|
return self.config.get('use_exchange', 'BitcoinAverage')
|
||||||
|
|
||||||
def config_history(self):
|
def config_history(self):
|
||||||
return self.config.get('history_rates', 'unchecked') != 'unchecked'
|
return self.config.get('history_rates', 'unchecked') != 'unchecked'
|
||||||
|
|
Loading…
Add table
Reference in a new issue