electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 8ce2a95695315f8d3cd39b8009612bc1db2d10a2
parent ec3b7ba5ee0fd20ceae9766589c492f03d14fc64
Author: Neil Booth <kyuupichan@gmail.com>
Date:   Fri,  4 Sep 2015 09:12:11 +0900

Have plugins object track the window set

No need for self.gui nor init_qt hook any more.  This makes
plugins more independent of window and gui types.

Diffstat:
Mgui/qt/__init__.py | 2++
Mgui/qt/main_window.py | 5-----
Mlib/plugins.py | 7+++++++
Mplugins/exchange_rate.py | 34++++++++++++++--------------------
4 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py @@ -231,6 +231,7 @@ class ElectrumGui: w.show() self.windows.append(w) self.build_tray_menu() + self.plugins.on_new_window(w) if uri: w.pay_to_URI(uri) @@ -240,6 +241,7 @@ class ElectrumGui: def close_window(self, window): self.windows.remove(window) self.build_tray_menu() + self.plugins.on_close_window(window) def main(self): self.timer.start() diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -2835,11 +2835,6 @@ class ElectrumWindow(QMainWindow): def do_toggle(cb, name, w): p = plugins.toggle_enabled(self.config, name) - if p: - # FIXME: this is hosed for multiple windows - p.wallet = self.wallet - p.load_wallet(self.wallet, self) - p.init_qt(self.gui_object) enabled = p is not None cb.setChecked(enabled) if w: w.setEnabled(enabled) diff --git a/lib/plugins.py b/lib/plugins.py @@ -39,6 +39,7 @@ class Plugins: self.pathname = None self.plugins = {} + self.windows = [] self.descriptions = plugins.descriptions for item in self.descriptions: name = item['name'] @@ -114,6 +115,12 @@ class Plugins: x += (lambda: self.wallet_plugin_loader(config, name),) wallet.wallet_types.append(x) + def on_new_window(self, window): + self.windows.append(window) + + def on_close_window(self, window): + self.windows.remove(window) + hook_names = set() hooks = {} diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py @@ -81,7 +81,7 @@ class Exchanger(ThreadJob): self.parent.refresh_fields() def run(self): - if self.parent.gui and self.timeout <= time.time(): + if self.parent.parent.windows and self.timeout <= time.time(): self.update_rate() self.timeout = time.time() + 150 @@ -170,8 +170,11 @@ class Plugin(BasePlugin): self.resp_hist = {} self.btc_rate = Decimal("0.0") self.network = None - self.gui = None self.wallet_tx_list = {} + # For mid-session plugin loads + for window in parent.windows: + self.new_window(window) + self.new_wallets([window.wallet for window in parent.windows]) @hook def set_network(self, network): @@ -183,14 +186,6 @@ class Plugin(BasePlugin): network.add_job(self.exchanger) @hook - def init_qt(self, gui): - self.gui = gui - # For mid-session plugin loads - for window in gui.windows: - self.new_window(window) - self.new_wallets([window.wallet for window in gui.windows]) - - @hook def new_window(self, window): window.connect(window, SIGNAL("refresh_currencies()"), window.update_status) @@ -203,14 +198,14 @@ class Plugin(BasePlugin): BasePlugin.close(self) self.set_network(None) self.exchanger = None - for window in self.gui.windows: + for window in self.parent.windows: window.send_fiat_e.hide() window.receive_fiat_e.hide() window.update_status() def set_currencies(self, currency_options): self.currencies = sorted(currency_options) - for window in self.gui.windows: + for window in self.parent.windows: window.emit(SIGNAL("refresh_currencies()")) window.emit(SIGNAL("refresh_currencies_combo()")) @@ -323,9 +318,8 @@ class Plugin(BasePlugin): else: return - if self.gui: - for window in self.gui.windows: - window.need_update.set() + for window in self.parent.windows: + window.need_update.set() def requires_settings(self): return True @@ -421,7 +415,7 @@ class Plugin(BasePlugin): hist_checkbox.setEnabled(True) else: disable_check() - for window in self.gui.windows: + for window in self.parent.windows: window.update_status() try: self.fiat_button @@ -448,7 +442,7 @@ class Plugin(BasePlugin): else: disable_check() set_currencies(combo) - for window in self.gui.windows: + for window in self.parent.windows: window.update_status() def on_change_hist(checked): @@ -457,7 +451,7 @@ class Plugin(BasePlugin): self.get_historical_rates() else: self.config.set_key('history_rates', 'unchecked') - for window in self.gui.windows: + for window in self.parent.windows: window.history_list.setHeaderLabels( [ '', '', _('Date'), _('Description') , _('Amount'), _('Balance')] ) window.history_list.setColumnCount(6) @@ -489,7 +483,7 @@ class Plugin(BasePlugin): combo.currentIndexChanged.connect(on_change) combo_ex.currentIndexChanged.connect(on_change_ex) hist_checkbox.stateChanged.connect(on_change_hist) - for window in self.gui.windows: + for window in self.parent.windows: combo.connect(window, SIGNAL('refresh_currencies_combo()'), lambda: set_currencies(combo)) combo_ex.connect(d, SIGNAL('refresh_exchanges_combo()'), lambda: set_exchanges(combo_ex)) ok_button.clicked.connect(lambda: ok_clicked()) @@ -508,7 +502,7 @@ class Plugin(BasePlugin): def refresh_fields(self): '''Update the display at the new rate''' - for window in self.gui.windows: + for window in self.parent.windows: for field in window.fx_fields.values(): field.textEdited.emit(field.text())