From 7207f13e97cb3a15971488e7590e40124f606c00 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Thu, 16 Mar 2023 16:48:12 +0100 Subject: [PATCH] Qt: set history_rates both through settings_dialog and history_list follow-up 503776c0dee2a544c0d746e9b853f29fe0b54279 --- electrum/exchange_rate.py | 5 ++++- electrum/gui/qt/history_list.py | 7 ++++--- electrum/gui/qt/settings_dialog.py | 16 ++++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/electrum/exchange_rate.py b/electrum/exchange_rate.py index fd3280c9c..87b3996ba 100644 --- a/electrum/exchange_rate.py +++ b/electrum/exchange_rate.py @@ -597,9 +597,12 @@ class FxThread(ThreadJob, EventListener): self.config.set_key('use_exchange_rate', bool(b)) self.trigger_update() - def has_history(self): + def can_have_history(self): return self.is_enabled() and self.ccy in self.exchange.history_ccys() + def has_history(self): + return self.can_have_history() and self.config.get('history_rates', False) + def get_currency(self) -> str: '''Use when dynamic fetching is needed''' return self.config.get("currency", DEFAULT_CURRENCY) diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py index 5dc01dc37..ec3422d3f 100644 --- a/electrum/gui/qt/history_list.py +++ b/electrum/gui/qt/history_list.py @@ -562,9 +562,10 @@ class HistoryList(MyTreeView, AcceptFileDragDrop): def update_toolbar_menu(self): fx = self.main_window.fx - b = fx and fx.is_enabled() and fx.has_history() - self.menu_fiat.setEnabled(b) - self.menu_capgains.setEnabled(b) + self.menu_fiat.setEnabled(fx and fx.can_have_history()) + # setChecked because has_history can be modified through settings dialog + self.menu_fiat.setChecked(fx and fx.has_history()) + self.menu_capgains.setEnabled(fx and fx.has_history()) def get_toolbar_buttons(self): return self.period_combo, self.start_button, self.end_button diff --git a/electrum/gui/qt/settings_dialog.py b/electrum/gui/qt/settings_dialog.py index 6aeaf4a59..3ae4044e4 100644 --- a/electrum/gui/qt/settings_dialog.py +++ b/electrum/gui/qt/settings_dialog.py @@ -300,14 +300,15 @@ class SettingsDialog(QDialog, QtEventListener): block_ex_hbox_w.setLayout(block_ex_hbox) # Fiat Currency - self.require_history_checkbox = QCheckBox() + self.history_rates_cb = QCheckBox(_('Download historical rates')) ccy_combo = QComboBox() ex_combo = QComboBox() def update_currencies(): if not self.fx: return - currencies = sorted(self.fx.get_currencies(self.require_history_checkbox.isChecked())) + h = self.config.get('history_rates', False) + currencies = sorted(self.fx.get_currencies(h)) ccy_combo.clear() ccy_combo.addItems([_('None')] + currencies) if self.fx.is_enabled(): @@ -318,7 +319,7 @@ class SettingsDialog(QDialog, QtEventListener): b = self.fx.is_enabled() ex_combo.setEnabled(b) if b: - h = self.require_history_checkbox.isChecked() + h = self.config.get('history_rates', False) c = self.fx.get_currency() exchanges = self.fx.get_exchanges_by_ccy(c, h) else: @@ -345,15 +346,18 @@ class SettingsDialog(QDialog, QtEventListener): self.fx.set_exchange(exchange) self.app.update_fiat_signal.emit() - def on_require_history(checked): + def on_history_rates(checked): + self.config.set_key('history_rates', bool(checked)) if not self.fx: return update_exchanges() + window.app.update_fiat_signal.emit() update_currencies() update_exchanges() ccy_combo.currentIndexChanged.connect(on_currency) - self.require_history_checkbox.stateChanged.connect(on_require_history) + self.history_rates_cb.setChecked(self.config.get('history_rates', False)) + self.history_rates_cb.stateChanged.connect(on_history_rates) ex_combo.currentIndexChanged.connect(on_exchange) gui_widgets = [] @@ -371,7 +375,7 @@ class SettingsDialog(QDialog, QtEventListener): fiat_widgets = [] fiat_widgets.append((QLabel(_('Fiat currency')), ccy_combo)) fiat_widgets.append((QLabel(_('Source')), ex_combo)) - fiat_widgets.append((QLabel(_('Show sources with historical data')), self.require_history_checkbox)) + fiat_widgets.append((self.history_rates_cb, None)) misc_widgets = [] misc_widgets.append((updatecheck_cb, None)) misc_widgets.append((filelogging_cb, None))