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