Have fields update as exchange rates do

Currently the exchange rates plugin shows the converted
rate at the time of last user input.  If the fx rate
changes the send and receive tabs do not update.

This makes them update.  It also means that when enabling
the plugin, if the user had input a BTC amount in the send
or receive, the other fields will refresh.  This didn't
used to happen - they stayed blank.
This commit is contained in:
Neil Booth 2015-08-31 20:14:44 +09:00
parent cd83b93e98
commit f5a8da43e9
1 changed files with 10 additions and 0 deletions

View File

@ -95,6 +95,7 @@ class Exchanger(threading.Thread):
with self.lock:
self.quote_currencies = rates
self.parent.set_currencies(rates)
self.parent.refresh_fields()
def run(self):
self.is_running = True
@ -190,6 +191,7 @@ class Plugin(BasePlugin):
self.exchanger.start()
self.win = None
self.resp_hist = {}
self.fields = {}
@hook
def init_qt(self, gui):
@ -496,6 +498,11 @@ class Plugin(BasePlugin):
def fiat_unit(self):
return self.config.get("currency", "EUR")
def refresh_fields(self):
'''Update the display at the new rate'''
for field in self.fields.values():
field.textEdited.emit(field.text())
def add_send_edit(self):
self.send_fiat_e = AmountEdit(self.fiat_unit)
btc_e = self.win.amount_e
@ -513,6 +520,7 @@ class Plugin(BasePlugin):
def connect_fields(self, btc_e, fiat_e, fee_e):
def fiat_changed():
fiat_e.setStyleSheet(BLACK_FG)
self.fields[(fiat_e, btc_e)] = fiat_e
try:
fiat_amount = Decimal(str(fiat_e.text()))
except:
@ -528,6 +536,7 @@ class Plugin(BasePlugin):
fiat_e.textEdited.connect(fiat_changed)
def btc_changed():
btc_e.setStyleSheet(BLACK_FG)
self.fields[(fiat_e, btc_e)] = btc_e
if self.exchanger is None:
return
btc_amount = btc_e.get_amount()
@ -541,6 +550,7 @@ class Plugin(BasePlugin):
fiat_e.setCursorPosition(pos)
fiat_e.setStyleSheet(BLUE_FG)
btc_e.textEdited.connect(btc_changed)
self.fields[(fiat_e, btc_e)] = btc_e
@hook
def do_clear(self):