kivy: use EventDispatcher with exchange rates plugin
This commit is contained in:
@@ -55,9 +55,9 @@ class ExchangeBase(PrintError):
|
||||
self.print_error("getting fx quotes for", ccy)
|
||||
self.quotes = self.get_rates(ccy)
|
||||
self.print_error("received fx quotes")
|
||||
self.on_quotes()
|
||||
except BaseException as e:
|
||||
self.print_error("failed fx quotes:", e)
|
||||
self.on_quotes()
|
||||
|
||||
def update(self, ccy):
|
||||
t = Thread(target=self.update_safe, args=(ccy,))
|
||||
|
||||
@@ -1,14 +1,38 @@
|
||||
from exchange_rate import FxPlugin
|
||||
from __future__ import absolute_import
|
||||
|
||||
from .exchange_rate import FxPlugin
|
||||
from electrum.plugins import hook
|
||||
|
||||
|
||||
from kivy.event import EventDispatcher
|
||||
|
||||
class MyEventDispatcher(EventDispatcher):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.register_event_type('on_quotes')
|
||||
self.register_event_type('on_history')
|
||||
super(MyEventDispatcher, self).__init__(**kwargs)
|
||||
|
||||
def on_quotes(self, *args):
|
||||
pass
|
||||
|
||||
def on_history(self, *args):
|
||||
pass
|
||||
|
||||
|
||||
class Plugin(FxPlugin):
|
||||
|
||||
def __init__(self, parent, config, name):
|
||||
FxPlugin.__init__(self, parent, config, name)
|
||||
self.dispatcher = MyEventDispatcher()
|
||||
|
||||
def on_quotes(self):
|
||||
self.print_error("on quotes", self.ccy)
|
||||
self.print_error("on_quotes")
|
||||
self.dispatcher.dispatch('on_quotes')
|
||||
|
||||
def on_history(self):
|
||||
self.print_error("on history")
|
||||
self.window.history_screen.update()
|
||||
self.print_error("on_history")
|
||||
self.dispatcher.dispatch('on_history')
|
||||
|
||||
def on_close(self):
|
||||
self.print_error("on close")
|
||||
@@ -17,9 +41,12 @@ class Plugin(FxPlugin):
|
||||
|
||||
@hook
|
||||
def init_kivy(self, window):
|
||||
self.print_error("init_kivy")
|
||||
self.window = window
|
||||
self.dispatcher.bind(on_quotes=window.on_quotes)
|
||||
self.dispatcher.bind(on_history=window.on_history)
|
||||
self.window.fiat_unit = self.ccy
|
||||
self.window.history_screen.update()
|
||||
self.dispatcher.dispatch('on_history')
|
||||
|
||||
@hook
|
||||
def load_wallet(self, wallet, window):
|
||||
|
||||
Reference in New Issue
Block a user