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.
This commit is contained in:
Neil Booth 2015-09-04 09:12:11 +09:00
parent ec3b7ba5ee
commit 8ce2a95695
4 changed files with 23 additions and 25 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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 = {}

View File

@ -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):
@ -182,14 +185,6 @@ class Plugin(BasePlugin):
if network:
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()"),
@ -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())