tkivy: * improve settings dialog * add fx_dialog - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 488bdbf4b51a107361cbcf8c6b0506ecaf6c820d DIR parent 97bc1b278876674e3481f135f28413c7877aec5d HTML Author: ThomasV <thomasv@electrum.org> Date: Sat, 23 Jan 2016 09:54:26 +0100 kivy: * improve settings dialog * add fx_dialog Diffstat: M gui/kivy/uix/dialogs/fee_dialog.py | 2 +- A gui/kivy/uix/dialogs/fx_dialog.py | 132 +++++++++++++++++++++++++++++++ M gui/kivy/uix/dialogs/settings.py | 72 ++++++++++++------------------- 3 files changed, 161 insertions(+), 45 deletions(-) --- DIR diff --git a/gui/kivy/uix/dialogs/fee_dialog.py b/gui/kivy/uix/dialogs/fee_dialog.py t@@ -41,7 +41,7 @@ class FeeDialog(Factory.Popup): Factory.Popup.__init__(self) self.config = config 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): self.config.set_key('dynamic_fees', self.ids.dynfees.active, True) DIR diff --git a/gui/kivy/uix/dialogs/fx_dialog.py b/gui/kivy/uix/dialogs/fx_dialog.py t@@ -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 DIR diff --git a/gui/kivy/uix/dialogs/settings.py b/gui/kivy/uix/dialogs/settings.py t@@ -15,6 +15,14 @@ Builder.load_string(''' title: '' description: '' 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: id: title text: self.parent.title t@@ -70,23 +78,11 @@ Builder.load_string(''' on_release: root.fee_dialog(self) SettingsItem: - status: 'ON' if bool(app.plugins.get('exchange_rate')) else 'OFF' - title: _('Exchange rates') + ': ' + self.status - description: _("Display amounts in fiat currency.") - on_release: - settings.plugin_dialog('exchange_rate', self) - SettingsItem: - status: app.fiat_unit + status: root.fx_status() 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.") + description: _("Display amounts in fiat currency.") on_release: - settings.fiat_source_dialog(self) + root.fx_dialog(self) SettingsItem: status: 'ON' if bool(app.plugins.get('labels')) else 'OFF' title: _('Labels Sync') + ': ' + self.status t@@ -141,35 +137,6 @@ class SettingsDialog(Factory.Popup): d = ChoiceDialog(_('Denomination'), base_units.keys(), self.app.base_unit, cb) 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): from label_dialog import LabelDialog def callback(text): t@@ -204,3 +171,20 @@ class SettingsDialog(Factory.Popup): label.status = self.fee_status() d = FeeDialog(self.config, cb) 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() +