kivy: simplify currency dialog
This commit is contained in:
parent
132fca86b2
commit
1f350c31dd
|
@ -11,16 +11,6 @@ Builder.load_string('''
|
||||||
pos_hint: {'top':0.9}
|
pos_hint: {'top':0.9}
|
||||||
BoxLayout:
|
BoxLayout:
|
||||||
orientation: 'vertical'
|
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:
|
Widget:
|
||||||
size_hint: 1, 0.1
|
size_hint: 1, 0.1
|
||||||
|
@ -76,7 +66,7 @@ from kivy.uix.checkbox import CheckBox
|
||||||
from kivy.uix.widget import Widget
|
from kivy.uix.widget import Widget
|
||||||
from kivy.clock import Clock
|
from kivy.clock import Clock
|
||||||
|
|
||||||
from electrum.plugins import run_hook
|
from electrum_gui.kivy.i18n import _
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
class FxDialog(Factory.Popup):
|
class FxDialog(Factory.Popup):
|
||||||
|
@ -87,11 +77,8 @@ class FxDialog(Factory.Popup):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.fx = self.app.fx
|
self.fx = self.app.fx
|
||||||
self.ids.enabled.active = self.fx.is_enabled()
|
self.fx.set_history_config(True)
|
||||||
|
self.add_currencies()
|
||||||
def on_active(self, b):
|
|
||||||
self.fx.set_enabled(b)
|
|
||||||
Clock.schedule_once(lambda dt: self.add_currencies())
|
|
||||||
|
|
||||||
def add_exchanges(self):
|
def add_exchanges(self):
|
||||||
exchanges = sorted(self.fx.get_exchanges_by_ccy(self.fx.get_currency(), True)) if self.fx.is_enabled() else []
|
exchanges = sorted(self.fx.get_exchanges_by_ccy(self.fx.get_currency(), True)) if self.fx.is_enabled() else []
|
||||||
|
@ -107,14 +94,16 @@ class FxDialog(Factory.Popup):
|
||||||
self.fx.set_exchange(text)
|
self.fx.set_exchange(text)
|
||||||
|
|
||||||
def add_currencies(self):
|
def add_currencies(self):
|
||||||
currencies = sorted(self.fx.get_currencies()) if self.fx else []
|
currencies = [_('None')] + self.fx.get_currencies(True)
|
||||||
my_ccy = self.fx.get_currency() if self.fx.is_enabled() else ''
|
my_ccy = self.fx.get_currency() if self.fx.is_enabled() else _('None')
|
||||||
self.ids.ccy.values = currencies
|
self.ids.ccy.values = currencies
|
||||||
self.ids.ccy.text = my_ccy
|
self.ids.ccy.text = my_ccy
|
||||||
|
|
||||||
def on_currency(self, ccy):
|
def on_currency(self, ccy):
|
||||||
if ccy:
|
b = (ccy != _('None'))
|
||||||
if self.fx.is_enabled() and ccy != self.fx.get_currency():
|
self.fx.set_enabled(b)
|
||||||
|
if b:
|
||||||
|
if ccy != self.fx.get_currency():
|
||||||
self.fx.set_currency(ccy)
|
self.fx.set_currency(ccy)
|
||||||
self.app.fiat_unit = ccy
|
self.app.fiat_unit = ccy
|
||||||
Clock.schedule_once(lambda dt: self.add_exchanges())
|
Clock.schedule_once(lambda dt: self.add_exchanges())
|
||||||
|
|
|
@ -246,7 +246,7 @@ class SettingsDialog(Factory.Popup):
|
||||||
ccy = fx.get_currency()
|
ccy = fx.get_currency()
|
||||||
return '%s [%s]' %(ccy, source)
|
return '%s [%s]' %(ccy, source)
|
||||||
else:
|
else:
|
||||||
return 'Disabled'
|
return _('None')
|
||||||
|
|
||||||
def fx_dialog(self, label, dt):
|
def fx_dialog(self, label, dt):
|
||||||
if self._fx_dialog is None:
|
if self._fx_dialog is None:
|
||||||
|
|
|
@ -2578,7 +2578,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
ex_combo = QComboBox()
|
ex_combo = QComboBox()
|
||||||
|
|
||||||
def update_currencies():
|
def update_currencies():
|
||||||
currencies = sorted(self.fx.get_currencies())
|
currencies = sorted(self.fx.get_currencies(self.fx.get_history_config()))
|
||||||
ccy_combo.clear()
|
ccy_combo.clear()
|
||||||
ccy_combo.addItems([_('None')] + currencies)
|
ccy_combo.addItems([_('None')] + currencies)
|
||||||
if self.fx.is_enabled():
|
if self.fx.is_enabled():
|
||||||
|
|
|
@ -333,8 +333,8 @@ class FxThread(ThreadJob):
|
||||||
self.hist_checkbox = None
|
self.hist_checkbox = None
|
||||||
self.set_exchange(self.config_exchange())
|
self.set_exchange(self.config_exchange())
|
||||||
|
|
||||||
def get_currencies(self):
|
def get_currencies(self, h):
|
||||||
d = get_exchanges_by_ccy(False)
|
d = get_exchanges_by_ccy(h)
|
||||||
return sorted(d.keys())
|
return sorted(d.keys())
|
||||||
|
|
||||||
def get_exchanges_by_ccy(self, ccy, h):
|
def get_exchanges_by_ccy(self, ccy, h):
|
||||||
|
|
Loading…
Reference in New Issue