Browse Source

plugins: on_close method

283
ThomasV 9 years ago
parent
commit
de964f4033
  1. 30
      gui/kivy/main_window.py
  2. 4
      lib/plugins.py
  3. 1
      plugins/exchange_rate/exchange_rate.py
  4. 20
      plugins/exchange_rate/kivy.py
  5. 4
      plugins/exchange_rate/qt.py

30
gui/kivy/main_window.py

@ -79,7 +79,7 @@ class ElectrumWindow(App):
context = StringProperty('') context = StringProperty('')
context_action = lambda x: None context_action = lambda x: None
status = StringProperty(_('Not Connected')) status = StringProperty('')
fiat_unit = StringProperty('') fiat_unit = StringProperty('')
def decimal_point(self): def decimal_point(self):
@ -224,6 +224,7 @@ class ElectrumWindow(App):
def show_plugins(self, plugins_list): def show_plugins(self, plugins_list):
def on_active(sw, value): def on_active(sw, value):
self.plugins.toggle_enabled(self.electrum_config, sw.name) self.plugins.toggle_enabled(self.electrum_config, sw.name)
run_hook('init_kivy', self)
for item in self.plugins.descriptions: for item in self.plugins.descriptions:
if 'kivy' not in item.get('available_for', []): if 'kivy' not in item.get('available_for', []):
continue continue
@ -424,13 +425,8 @@ class ElectrumWindow(App):
def update_status(self, *dt): def update_status(self, *dt):
if not self.wallet: if not self.wallet:
return return
unconfirmed = ''
quote_text = ''
if self.network is None or not self.network.is_running(): if self.network is None or not self.network.is_running():
text = _("Offline") self.status = _("Offline")
elif self.network.is_connected(): elif self.network.is_connected():
server_height = self.network.get_server_height() server_height = self.network.get_server_height()
server_lag = self.network.get_local_height() - server_height server_lag = self.network.get_local_height() - server_height
@ -440,29 +436,11 @@ class ElectrumWindow(App):
self.status = _("Server lagging (%d blocks)"%server_lag) self.status = _("Server lagging (%d blocks)"%server_lag)
else: else:
c, u, x = self.wallet.get_account_balance(self.current_account) c, u, x = self.wallet.get_account_balance(self.current_account)
text = self.format_amount(c) text = self.format_amount(c+x+u)
if u:
unconfirmed = " [%s unconfirmed]" %( self.format_amount(u, True).strip())
if x:
unmatured = " [%s unmatured]"%(self.format_amount(x, True).strip())
#quote_text = self.create_quote_text(Decimal(c+u+x)/100000000, mode='symbol') or ''
self.status = text.strip() + ' ' + self.base_unit self.status = text.strip() + ' ' + self.base_unit
else: else:
self.status = _("Not connected") self.status = _("Not connected")
return
print self.root.manager.ids
#try:
status_card = self.root.main_screen.ids.tabs.ids.\
screen_dashboard.ids.status_card
#except AttributeError:
# return
status_card.quote_text = quote_text.strip()
status_card.uncomfirmed = unconfirmed.strip()
def get_max_amount(self): def get_max_amount(self):
inputs = self.wallet.get_spendable_coins(None) inputs = self.wallet.get_spendable_coins(None)

4
lib/plugins.py

@ -187,6 +187,10 @@ class BasePlugin(PrintError):
l.remove((self, getattr(self, k))) l.remove((self, getattr(self, k)))
hooks[k] = l hooks[k] = l
self.parent.close_plugin(self) self.parent.close_plugin(self)
self.on_close()
def on_close(self):
pass
def requires_settings(self): def requires_settings(self):
return False return False

1
plugins/exchange_rate/exchange_rate.py

@ -288,7 +288,6 @@ class FxPlugin(BasePlugin, ThreadJob):
def show_history(self): def show_history(self):
return self.config_history() and self.exchange.history_ccys() return self.config_history() and self.exchange.history_ccys()
def set_exchange(self, name): def set_exchange(self, name):
class_ = self.exchanges.get(name) or self.exchanges.values()[0] class_ = self.exchanges.get(name) or self.exchanges.values()[0]
name = class_.__name__ name = class_.__name__

20
plugins/exchange_rate/kivy.py

@ -2,14 +2,26 @@ from exchange_rate import FxPlugin
from electrum.plugins import hook from electrum.plugins import hook
class Plugin(FxPlugin): class Plugin(FxPlugin):
@hook
def load_wallet(self, wallet, window):
self.window = window
def on_quotes(self): def on_quotes(self):
self.print_error("on quotes", self.ccy) self.print_error("on quotes", self.ccy)
self.window.fiat_unit = self.ccy
def on_history(self): def on_history(self):
self.print_error("on history") self.print_error("on history")
self.window.history_screen.update() self.window.history_screen.update()
def on_close(self):
self.print_error("on close")
self.window.fiat_unit = ''
self.window.history_screen.update()
@hook
def init_kivy(self, window):
self.window = window
self.window.fiat_unit = self.ccy
self.window.history_screen.update()
@hook
def load_wallet(self, wallet, window):
self.window = window
self.window.fiat_unit = self.ccy

4
plugins/exchange_rate/qt.py

@ -49,9 +49,7 @@ class Plugin(FxPlugin):
def do_clear(self, window): def do_clear(self, window):
window.fiat_send_e.setText('') window.fiat_send_e.setText('')
def close(self): def on_close(self):
# Get rid of hooks before updating status bars.
FxPlugin.close(self)
self.app.emit(SIGNAL('close_fx_plugin')) self.app.emit(SIGNAL('close_fx_plugin'))
def restore_window(self, window): def restore_window(self, window):

Loading…
Cancel
Save