Browse Source

kivy: update fiat amounts when changed

283
ThomasV 9 years ago
parent
commit
5a03caf051
  1. 31
      gui/kivy/main_window.py
  2. 7
      gui/kivy/uix/dialogs/settings.py
  3. 9
      plugins/exchange_rate/exchange_rate.py
  4. 8
      plugins/exchange_rate/qt.py

31
gui/kivy/main_window.py

@ -78,6 +78,10 @@ class ElectrumWindow(App):
status = StringProperty('')
fiat_unit = StringProperty('')
def on_fiat_unit(self, a, b):
if self.history_screen:
self.history_screen.update()
def decimal_point(self):
return base_units[self.base_unit]
@ -548,36 +552,9 @@ class ElectrumWindow(App):
#Logger.info('orientation: {}'.format(self._orientation))
#Logger.info('ui_mode: {}'.format(self._ui_mode))
def save_new_contact(self, address, label):
address = unicode(address)
label = unicode(label)
global is_valid
if not is_valid:
from electrum.bitcoin import is_valid
if is_valid(address):
if label:
self.set_label(address, text=label)
self.wallet.add_contact(address)
self.update_contacts_tab()
self.update_history_tab()
else:
self.show_error(_('Invalid Address'))
def set_send(self, address, amount, label, message):
self.send_payment(address, amount=amount, label=label, message=message)
def set_frozen(self, entry, frozen):
if frozen:
entry.disabled = True
Factory.Animation(opacity=0).start(content)
else:
entry.disabled = False
Factory.Animation(opacity=1).start(content)
def show_error(self, error, width='200dp', pos=None, arrow_pos=None,
exit=False, icon='atlas://gui/kivy/theming/light/error', duration=0,
modal=False):

7
gui/kivy/uix/dialogs/settings.py

@ -131,7 +131,7 @@ class SettingsDialog(Factory.Popup):
def cb(text):
self.app._set_bu(text)
item.bu = self.app.base_unit
d = ChoiceDialog(_('Denomination'), base_units, self.app.base_unit, cb)
d = ChoiceDialog(_('Denomination'), base_units.keys(), self.app.base_unit, cb)
d.open()
def fiat_currency_dialog(self, item):
@ -140,10 +140,11 @@ class SettingsDialog(Factory.Popup):
if not p:
return
def cb(text):
self.config.set_key('currency', text, True)
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, '', cb)
d = ChoiceDialog(_('Fiat Currency'), l, p.get_currency(), cb)
d.open()
def fiat_source(self):

9
plugins/exchange_rate/exchange_rate.py

@ -264,7 +264,7 @@ class FxPlugin(BasePlugin, ThreadJob):
def __init__(self, parent, config, name):
BasePlugin.__init__(self, parent, config, name)
self.ccy = self.config_ccy()
self.ccy = self.get_currency()
self.history_used_spot = False
self.ccy_combo = None
self.hist_checkbox = None
@ -289,7 +289,7 @@ class FxPlugin(BasePlugin, ThreadJob):
self.timeout = time.time() + 150
self.exchange.update(self.ccy)
def config_ccy(self):
def get_currency(self):
'''Use when dynamic fetching is needed'''
return self.config.get("currency", "EUR")
@ -302,6 +302,11 @@ class FxPlugin(BasePlugin, ThreadJob):
def show_history(self):
return self.config_history() and self.exchange.history_ccys()
def set_currency(self, ccy):
self.ccy = ccy
self.config.set_key('currency', ccy, True)
self.get_historical_rates() # Because self.ccy changes
def set_exchange(self, name):
class_ = self.exchanges.get(name) or self.exchanges.values()[0]
name = class_.__name__

8
plugins/exchange_rate/qt.py

@ -85,10 +85,8 @@ class Plugin(FxPlugin):
'''Called when the chosen currency changes'''
ccy = str(self.ccy_combo.currentText())
if ccy and ccy != self.ccy:
self.ccy = ccy
self.config.set_key('currency', ccy, True)
self.set_currency(ccy)
self.app.emit(SIGNAL('new_fx_quotes'))
self.get_historical_rates() # Because self.ccy changes
self.hist_checkbox_update()
def hist_checkbox_update(self):
@ -110,11 +108,11 @@ class Plugin(FxPlugin):
@hook
def on_new_window(self, window):
# Additional send and receive edit boxes
send_e = AmountEdit(self.config_ccy)
send_e = AmountEdit(self.get_currency)
window.send_grid.addWidget(send_e, 4, 2, Qt.AlignLeft)
window.amount_e.frozen.connect(
lambda: send_e.setFrozen(window.amount_e.isReadOnly()))
receive_e = AmountEdit(self.config_ccy)
receive_e = AmountEdit(self.get_currency)
window.receive_grid.addWidget(receive_e, 2, 2, Qt.AlignLeft)
window.fiat_send_e = send_e
window.fiat_receive_e = receive_e

Loading…
Cancel
Save