mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
kivy:
* improve settings dialog * add fx_dialog
This commit is contained in:
parent
97bc1b2788
commit
488bdbf4b5
3 changed files with 161 additions and 45 deletions
|
@ -41,7 +41,7 @@ class FeeDialog(Factory.Popup):
|
||||||
Factory.Popup.__init__(self)
|
Factory.Popup.__init__(self)
|
||||||
self.config = config
|
self.config = config
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.ids.dynfees.active = self.config.get('dynamic_fees')
|
self.ids.dynfees.active = bool(self.config.get('dynamic_fees'))
|
||||||
|
|
||||||
def on_ok(self):
|
def on_ok(self):
|
||||||
self.config.set_key('dynamic_fees', self.ids.dynfees.active, True)
|
self.config.set_key('dynamic_fees', self.ids.dynfees.active, True)
|
||||||
|
|
132
gui/kivy/uix/dialogs/fx_dialog.py
Normal file
132
gui/kivy/uix/dialogs/fx_dialog.py
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
from kivy.app import App
|
||||||
|
from kivy.factory import Factory
|
||||||
|
from kivy.properties import ObjectProperty
|
||||||
|
from kivy.lang import Builder
|
||||||
|
|
||||||
|
Builder.load_string('''
|
||||||
|
<FxDialog@Popup>
|
||||||
|
id: popup
|
||||||
|
title: 'Fiat Currency'
|
||||||
|
size_hint: 0.8, 0.8
|
||||||
|
pos_hint: {'top':0.9}
|
||||||
|
BoxLayout:
|
||||||
|
orientation: 'vertical'
|
||||||
|
BoxLayout:
|
||||||
|
orientation: 'horizontal'
|
||||||
|
size_hint: 1, 0.1
|
||||||
|
Label:
|
||||||
|
text: _('Enable')
|
||||||
|
height: '48dp'
|
||||||
|
CheckBox:
|
||||||
|
height: '48dp'
|
||||||
|
id: enabled
|
||||||
|
on_active: popup.on_active(self.active)
|
||||||
|
|
||||||
|
Widget:
|
||||||
|
size_hint: 1, 0.1
|
||||||
|
|
||||||
|
BoxLayout:
|
||||||
|
orientation: 'horizontal'
|
||||||
|
size_hint: 1, 0.1
|
||||||
|
Label:
|
||||||
|
text: _('Source')
|
||||||
|
height: '48dp'
|
||||||
|
Spinner:
|
||||||
|
height: '48dp'
|
||||||
|
id: exchanges
|
||||||
|
on_text: popup.on_exchange(self.text)
|
||||||
|
|
||||||
|
Widget:
|
||||||
|
size_hint: 1, 0.1
|
||||||
|
|
||||||
|
BoxLayout:
|
||||||
|
orientation: 'horizontal'
|
||||||
|
size_hint: 1, 0.1
|
||||||
|
Label:
|
||||||
|
text: _('Currency')
|
||||||
|
height: '48dp'
|
||||||
|
Spinner:
|
||||||
|
height: '48dp'
|
||||||
|
id: ccy
|
||||||
|
on_text: popup.on_currency(self.text)
|
||||||
|
Widget:
|
||||||
|
size_hint: 1, 0.2
|
||||||
|
|
||||||
|
BoxLayout:
|
||||||
|
orientation: 'horizontal'
|
||||||
|
size_hint: 1, 0.2
|
||||||
|
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.dismiss()
|
||||||
|
''')
|
||||||
|
|
||||||
|
|
||||||
|
from kivy.uix.label import Label
|
||||||
|
from kivy.uix.checkbox import CheckBox
|
||||||
|
from kivy.uix.widget import Widget
|
||||||
|
from kivy.clock import Clock
|
||||||
|
|
||||||
|
from electrum.plugins import run_hook
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
class FxDialog(Factory.Popup):
|
||||||
|
|
||||||
|
def __init__(self, app, plugins, config, callback):
|
||||||
|
Factory.Popup.__init__(self)
|
||||||
|
self.app = app
|
||||||
|
self.config = config
|
||||||
|
self.callback = callback
|
||||||
|
self.plugins = plugins
|
||||||
|
p = self.plugins.get('exchange_rate')
|
||||||
|
self.ids.enabled.active = bool(p)
|
||||||
|
|
||||||
|
def on_active(self, b):
|
||||||
|
if b:
|
||||||
|
p = self.plugins.enable('exchange_rate')
|
||||||
|
p.init_kivy(self.app)
|
||||||
|
values = sorted(p.exchanges.keys())
|
||||||
|
text = p.exchange.name()
|
||||||
|
else:
|
||||||
|
self.plugins.disable('exchange_rate')
|
||||||
|
values = []
|
||||||
|
text = ''
|
||||||
|
Clock.schedule_once(partial(self.add_exchanges, values, text), 0.1)
|
||||||
|
|
||||||
|
def add_exchanges(self, values, text, dt):
|
||||||
|
ex = self.ids.exchanges
|
||||||
|
ex.values = values
|
||||||
|
ex.text = text
|
||||||
|
|
||||||
|
|
||||||
|
def on_exchange(self, text):
|
||||||
|
if not text:
|
||||||
|
return
|
||||||
|
p = self.plugins.get('exchange_rate')
|
||||||
|
if p and text != p.exchange.name():
|
||||||
|
p.set_exchange(text)
|
||||||
|
Clock.schedule_once(self.add_currencies, 1)
|
||||||
|
|
||||||
|
def add_currencies(self, dt):
|
||||||
|
p = self.plugins.get('exchange_rate')
|
||||||
|
currencies = sorted(p.exchange.quotes.keys()) if p else []
|
||||||
|
self.ids.ccy.values = currencies
|
||||||
|
my_ccy = p.get_currency() if p else None
|
||||||
|
if currencies:
|
||||||
|
self.ids.ccy.text = my_ccy if my_ccy in currencies else currencies[0]
|
||||||
|
|
||||||
|
def on_currency(self, ccy):
|
||||||
|
if not ccy:
|
||||||
|
return
|
||||||
|
p = self.plugins.get('exchange_rate')
|
||||||
|
if p and ccy != p.get_currency():
|
||||||
|
p.set_currency(ccy)
|
||||||
|
self.app.fiat_unit = ccy
|
|
@ -15,6 +15,14 @@ Builder.load_string('''
|
||||||
title: ''
|
title: ''
|
||||||
description: ''
|
description: ''
|
||||||
size_hint: 1, None
|
size_hint: 1, None
|
||||||
|
|
||||||
|
canvas.before:
|
||||||
|
Color:
|
||||||
|
rgba: (0.192, .498, 0.745, 1) if self.state == 'down' else (0.3, 0.3, 0.3, 0)
|
||||||
|
Rectangle:
|
||||||
|
size: self.size
|
||||||
|
pos: self.pos
|
||||||
|
|
||||||
Label:
|
Label:
|
||||||
id: title
|
id: title
|
||||||
text: self.parent.title
|
text: self.parent.title
|
||||||
|
@ -70,23 +78,11 @@ Builder.load_string('''
|
||||||
on_release:
|
on_release:
|
||||||
root.fee_dialog(self)
|
root.fee_dialog(self)
|
||||||
SettingsItem:
|
SettingsItem:
|
||||||
status: 'ON' if bool(app.plugins.get('exchange_rate')) else 'OFF'
|
status: root.fx_status()
|
||||||
title: _('Exchange rates') + ': ' + self.status
|
title: _('Fiat Currency') + ': ' + self.status
|
||||||
description: _("Display amounts in fiat currency.")
|
description: _("Display amounts in fiat currency.")
|
||||||
on_release:
|
on_release:
|
||||||
settings.plugin_dialog('exchange_rate', self)
|
root.fx_dialog(self)
|
||||||
SettingsItem:
|
|
||||||
status: app.fiat_unit
|
|
||||||
title: _('Fiat Currency') + ': ' + self.status
|
|
||||||
description: _("Select the local fiat currency.")
|
|
||||||
on_release:
|
|
||||||
settings.fiat_currency_dialog(self)
|
|
||||||
SettingsItem:
|
|
||||||
status: root.fiat_source()
|
|
||||||
title: _('Fiat source') + ': ' + self.status
|
|
||||||
description: _("Source for fiat currency exchange rate.")
|
|
||||||
on_release:
|
|
||||||
settings.fiat_source_dialog(self)
|
|
||||||
SettingsItem:
|
SettingsItem:
|
||||||
status: 'ON' if bool(app.plugins.get('labels')) else 'OFF'
|
status: 'ON' if bool(app.plugins.get('labels')) else 'OFF'
|
||||||
title: _('Labels Sync') + ': ' + self.status
|
title: _('Labels Sync') + ': ' + self.status
|
||||||
|
@ -141,35 +137,6 @@ class SettingsDialog(Factory.Popup):
|
||||||
d = ChoiceDialog(_('Denomination'), base_units.keys(), self.app.base_unit, cb)
|
d = ChoiceDialog(_('Denomination'), base_units.keys(), self.app.base_unit, cb)
|
||||||
d.open()
|
d.open()
|
||||||
|
|
||||||
def fiat_currency_dialog(self, item):
|
|
||||||
from choice_dialog import ChoiceDialog
|
|
||||||
p = self.app.plugins.get('exchange_rate')
|
|
||||||
if not p:
|
|
||||||
return
|
|
||||||
def cb(text):
|
|
||||||
p.set_currency(text)
|
|
||||||
item.status = text
|
|
||||||
self.app.fiat_unit = text
|
|
||||||
l = sorted(p.exchange.quotes.keys()) if p else []
|
|
||||||
d = ChoiceDialog(_('Fiat Currency'), l, p.get_currency(), cb)
|
|
||||||
d.open()
|
|
||||||
|
|
||||||
def fiat_source(self):
|
|
||||||
p = self.app.plugins.get('exchange_rate')
|
|
||||||
return p.exchange.name() if p else 'None'
|
|
||||||
|
|
||||||
def fiat_source_dialog(self, item):
|
|
||||||
from choice_dialog import ChoiceDialog
|
|
||||||
p = self.plugins.get('exchange_rate')
|
|
||||||
if not p:
|
|
||||||
return
|
|
||||||
def cb(text):
|
|
||||||
p.set_exchange(text)
|
|
||||||
item.status = text
|
|
||||||
l = sorted(p.exchanges.keys())
|
|
||||||
d = ChoiceDialog(_('Exchange rate source'), l, self.fiat_source(), cb)
|
|
||||||
d.open()
|
|
||||||
|
|
||||||
def openalias_dialog(self):
|
def openalias_dialog(self):
|
||||||
from label_dialog import LabelDialog
|
from label_dialog import LabelDialog
|
||||||
def callback(text):
|
def callback(text):
|
||||||
|
@ -204,3 +171,20 @@ class SettingsDialog(Factory.Popup):
|
||||||
label.status = self.fee_status()
|
label.status = self.fee_status()
|
||||||
d = FeeDialog(self.config, cb)
|
d = FeeDialog(self.config, cb)
|
||||||
d.open()
|
d.open()
|
||||||
|
|
||||||
|
def fx_status(self):
|
||||||
|
p = self.plugins.get('exchange_rate')
|
||||||
|
if p:
|
||||||
|
source = p.exchange.name()
|
||||||
|
ccy = p.get_currency()
|
||||||
|
return '%s [%s]' %(ccy, source)
|
||||||
|
else:
|
||||||
|
return 'Disabled'
|
||||||
|
|
||||||
|
def fx_dialog(self, label):
|
||||||
|
from fx_dialog import FxDialog
|
||||||
|
def cb():
|
||||||
|
label.status = self.fx_status()
|
||||||
|
d = FxDialog(self.app, self.plugins, self.config, cb)
|
||||||
|
d.open()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue