|
@ -80,6 +80,8 @@ from functools import partial |
|
|
|
|
|
|
|
|
class FxDialog(Factory.Popup): |
|
|
class FxDialog(Factory.Popup): |
|
|
|
|
|
|
|
|
|
|
|
__events__ = ('on_quotes', ) |
|
|
|
|
|
|
|
|
def __init__(self, app, plugins, config, callback): |
|
|
def __init__(self, app, plugins, config, callback): |
|
|
Factory.Popup.__init__(self) |
|
|
Factory.Popup.__init__(self) |
|
|
self.app = app |
|
|
self.app = app |
|
@ -88,34 +90,42 @@ class FxDialog(Factory.Popup): |
|
|
self.plugins = plugins |
|
|
self.plugins = plugins |
|
|
p = self.plugins.get('exchange_rate') |
|
|
p = self.plugins.get('exchange_rate') |
|
|
self.ids.enabled.active = bool(p) |
|
|
self.ids.enabled.active = bool(p) |
|
|
|
|
|
if p: |
|
|
|
|
|
p.dispatcher.bind(on_quotes=self.on_quotes) |
|
|
|
|
|
|
|
|
|
|
|
def on_quotes(self, b): |
|
|
|
|
|
self.add_currencies() |
|
|
|
|
|
|
|
|
def on_active(self, b): |
|
|
def on_active(self, b): |
|
|
if b: |
|
|
if b: |
|
|
|
|
|
p = self.plugins.get('exchange_rate') |
|
|
|
|
|
if p is None: |
|
|
p = self.plugins.enable('exchange_rate') |
|
|
p = self.plugins.enable('exchange_rate') |
|
|
p.init_kivy(self.app) |
|
|
p.init_kivy(self.app) |
|
|
|
|
|
p.dispatcher.bind(on_quotes=self.on_quotes) |
|
|
|
|
|
|
|
|
values = sorted(p.exchanges.keys()) |
|
|
values = sorted(p.exchanges.keys()) |
|
|
text = p.exchange.name() |
|
|
text = p.exchange.name() |
|
|
else: |
|
|
else: |
|
|
self.plugins.disable('exchange_rate') |
|
|
self.plugins.disable('exchange_rate') |
|
|
values = [] |
|
|
values = [] |
|
|
text = '' |
|
|
text = '' |
|
|
Clock.schedule_once(partial(self.add_exchanges, values, text), 0.1) |
|
|
Clock.schedule_once(lambda dt: self.add_exchanges(values, text)) |
|
|
|
|
|
Clock.schedule_once(lambda dt: self.add_currencies()) |
|
|
|
|
|
|
|
|
def add_exchanges(self, values, text, dt): |
|
|
def add_exchanges(self, values, text): |
|
|
ex = self.ids.exchanges |
|
|
ex = self.ids.exchanges |
|
|
ex.values = values |
|
|
ex.values = values |
|
|
ex.text = text |
|
|
ex.text = text |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_exchange(self, text): |
|
|
def on_exchange(self, text): |
|
|
if not text: |
|
|
if not text: |
|
|
return |
|
|
return |
|
|
p = self.plugins.get('exchange_rate') |
|
|
p = self.plugins.get('exchange_rate') |
|
|
if p and text != p.exchange.name(): |
|
|
if p and text != p.exchange.name(): |
|
|
p.set_exchange(text) |
|
|
p.set_exchange(text) |
|
|
Clock.schedule_once(self.add_currencies, 1) |
|
|
|
|
|
|
|
|
|
|
|
def add_currencies(self, dt): |
|
|
def add_currencies(self): |
|
|
p = self.plugins.get('exchange_rate') |
|
|
p = self.plugins.get('exchange_rate') |
|
|
currencies = sorted(p.exchange.quotes.keys()) if p else [] |
|
|
currencies = sorted(p.exchange.quotes.keys()) if p else [] |
|
|
self.ids.ccy.values = currencies |
|
|
self.ids.ccy.values = currencies |
|
|