qt: persist addresses tab toolbar "show/hide" state, like in 4.3.4
This commit is contained in:
@@ -120,10 +120,11 @@ class AddressList(MyTreeView):
|
|||||||
addr = self.get_role_data_for_current_item(col=0, role=self.ROLE_ADDRESS_STR)
|
addr = self.get_role_data_for_current_item(col=0, role=self.ROLE_ADDRESS_STR)
|
||||||
self.main_window.show_address(addr)
|
self.main_window.show_address(addr)
|
||||||
|
|
||||||
|
CONFIG_KEY_SHOW_TOOLBAR = "show_toolbar_addresses"
|
||||||
def create_toolbar(self, config):
|
def create_toolbar(self, config):
|
||||||
toolbar, menu = self.create_toolbar_with_menu('')
|
toolbar, menu = self.create_toolbar_with_menu('')
|
||||||
self.num_addr_label = toolbar.itemAt(0).widget()
|
self.num_addr_label = toolbar.itemAt(0).widget()
|
||||||
menu.addToggle(_("Show Filter"), lambda: self.toggle_toolbar(self.config))
|
self._toolbar_checkbox = menu.addToggle(_("Show Filter"), lambda: self.toggle_toolbar())
|
||||||
menu.addConfig(_('Show Fiat balances'), 'fiat_address', False, callback=self.main_window.app.update_fiat_signal.emit)
|
menu.addConfig(_('Show Fiat balances'), 'fiat_address', False, callback=self.main_window.app.update_fiat_signal.emit)
|
||||||
hbox = self.create_toolbar_buttons()
|
hbox = self.create_toolbar_buttons()
|
||||||
toolbar.insertLayout(1, hbox)
|
toolbar.insertLayout(1, hbox)
|
||||||
|
|||||||
@@ -546,10 +546,11 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
|||||||
self.end_button.setText(_('To') + ' ' + self.format_date(self.end_date))
|
self.end_button.setText(_('To') + ' ' + self.format_date(self.end_date))
|
||||||
self.hide_rows()
|
self.hide_rows()
|
||||||
|
|
||||||
|
CONFIG_KEY_SHOW_TOOLBAR = "show_toolbar_history"
|
||||||
def create_toolbar(self, config):
|
def create_toolbar(self, config):
|
||||||
toolbar, menu = self.create_toolbar_with_menu('')
|
toolbar, menu = self.create_toolbar_with_menu('')
|
||||||
self.num_tx_label = toolbar.itemAt(0).widget()
|
self.num_tx_label = toolbar.itemAt(0).widget()
|
||||||
menu.addToggle(_("Filter by Date"), lambda: self.toggle_toolbar(self.config))
|
self._toolbar_checkbox = menu.addToggle(_("Filter by Date"), lambda: self.toggle_toolbar())
|
||||||
self.menu_fiat = menu.addConfig(_('Show Fiat Values'), 'history_rates', False, callback=self.main_window.app.update_fiat_signal.emit)
|
self.menu_fiat = menu.addConfig(_('Show Fiat Values'), 'history_rates', False, callback=self.main_window.app.update_fiat_signal.emit)
|
||||||
self.menu_capgains = menu.addConfig(_('Show Capital Gains'), 'history_rates_capital_gains', False, callback=self.main_window.app.update_fiat_signal.emit)
|
self.menu_capgains = menu.addConfig(_('Show Capital Gains'), 'history_rates_capital_gains', False, callback=self.main_window.app.update_fiat_signal.emit)
|
||||||
self.menu_summary = menu.addAction(_("&Summary"), self.show_summary)
|
self.menu_summary = menu.addAction(_("&Summary"), self.show_summary)
|
||||||
|
|||||||
@@ -1339,6 +1339,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
|||||||
if toolbar:
|
if toolbar:
|
||||||
vbox.addLayout(toolbar)
|
vbox.addLayout(toolbar)
|
||||||
vbox.addWidget(l)
|
vbox.addWidget(l)
|
||||||
|
if toolbar:
|
||||||
|
l.show_toolbar()
|
||||||
return w
|
return w
|
||||||
|
|
||||||
def create_addresses_tab(self):
|
def create_addresses_tab(self):
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ from PyQt5.QtWidgets import (QPushButton, QLabel, QMessageBox, QHBoxLayout,
|
|||||||
QFileDialog, QWidget, QToolButton, QTreeView, QPlainTextEdit,
|
QFileDialog, QWidget, QToolButton, QTreeView, QPlainTextEdit,
|
||||||
QHeaderView, QApplication, QToolTip, QTreeWidget, QStyledItemDelegate,
|
QHeaderView, QApplication, QToolTip, QTreeWidget, QStyledItemDelegate,
|
||||||
QMenu, QStyleOptionViewItem, QLayout, QLayoutItem, QAbstractButton,
|
QMenu, QStyleOptionViewItem, QLayout, QLayoutItem, QAbstractButton,
|
||||||
QGraphicsEffect, QGraphicsScene, QGraphicsPixmapItem, QSizePolicy)
|
QGraphicsEffect, QGraphicsScene, QGraphicsPixmapItem, QSizePolicy, QAction)
|
||||||
|
|
||||||
from electrum.i18n import _, languages
|
from electrum.i18n import _, languages
|
||||||
from electrum.util import FileImportFailed, FileExportFailed, make_aiohttp_session, resource_path
|
from electrum.util import FileImportFailed, FileExportFailed, make_aiohttp_session, resource_path
|
||||||
@@ -63,6 +63,7 @@ from electrum.qrreader import MissingQrDetectionLib
|
|||||||
from .util import read_QIcon
|
from .util import read_QIcon
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from electrum import SimpleConfig
|
||||||
from .main_window import ElectrumWindow
|
from .main_window import ElectrumWindow
|
||||||
|
|
||||||
|
|
||||||
@@ -73,13 +74,13 @@ class MyMenu(QMenu):
|
|||||||
self.setToolTipsVisible(True)
|
self.setToolTipsVisible(True)
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
def addToggle(self, text: str, callback, *, tooltip=''):
|
def addToggle(self, text: str, callback, *, tooltip='') -> QAction:
|
||||||
m = self.addAction(text, callback)
|
m = self.addAction(text, callback)
|
||||||
m.setCheckable(True)
|
m.setCheckable(True)
|
||||||
m.setToolTip(tooltip)
|
m.setToolTip(tooltip)
|
||||||
return m
|
return m
|
||||||
|
|
||||||
def addConfig(self, text:str, name:str, default:bool, *, tooltip='', callback=None):
|
def addConfig(self, text: str, name: str, default: bool, *, tooltip='', callback=None) -> QAction:
|
||||||
b = self.config.get(name, default)
|
b = self.config.get(name, default)
|
||||||
m = self.addAction(text, lambda: self._do_toggle_config(name, default, callback))
|
m = self.addAction(text, lambda: self._do_toggle_config(name, default, callback))
|
||||||
m.setCheckable(True)
|
m.setCheckable(True)
|
||||||
@@ -94,7 +95,7 @@ class MyMenu(QMenu):
|
|||||||
callback()
|
callback()
|
||||||
|
|
||||||
|
|
||||||
def create_toolbar_with_menu(config, title):
|
def create_toolbar_with_menu(config: 'SimpleConfig', title):
|
||||||
menu = MyMenu(config)
|
menu = MyMenu(config)
|
||||||
toolbar_button = QToolButton()
|
toolbar_button = QToolButton()
|
||||||
toolbar_button.setIcon(read_QIcon("preferences.png"))
|
toolbar_button.setIcon(read_QIcon("preferences.png"))
|
||||||
@@ -401,7 +402,15 @@ class MyTreeView(QTreeView):
|
|||||||
def create_toolbar_with_menu(self, title):
|
def create_toolbar_with_menu(self, title):
|
||||||
return create_toolbar_with_menu(self.config, title)
|
return create_toolbar_with_menu(self.config, title)
|
||||||
|
|
||||||
def show_toolbar(self, state, config=None):
|
CONFIG_KEY_SHOW_TOOLBAR = None # type: Optional[str]
|
||||||
|
_toolbar_checkbox = None # type: Optional[QAction]
|
||||||
|
def show_toolbar(self, state: bool = None):
|
||||||
|
if state is None: # get value from config
|
||||||
|
if self.config and self.CONFIG_KEY_SHOW_TOOLBAR:
|
||||||
|
state = self.config.get(self.CONFIG_KEY_SHOW_TOOLBAR, None)
|
||||||
|
if state is None:
|
||||||
|
return
|
||||||
|
assert isinstance(state, bool), state
|
||||||
if state == self.toolbar_shown:
|
if state == self.toolbar_shown:
|
||||||
return
|
return
|
||||||
self.toolbar_shown = state
|
self.toolbar_shown = state
|
||||||
@@ -409,9 +418,18 @@ class MyTreeView(QTreeView):
|
|||||||
b.setVisible(state)
|
b.setVisible(state)
|
||||||
if not state:
|
if not state:
|
||||||
self.on_hide_toolbar()
|
self.on_hide_toolbar()
|
||||||
|
if self._toolbar_checkbox is not None:
|
||||||
|
# update the cb state now, in case the checkbox was not what triggered us
|
||||||
|
self._toolbar_checkbox.setChecked(state)
|
||||||
|
|
||||||
def toggle_toolbar(self, config=None):
|
def on_hide_toolbar(self):
|
||||||
self.show_toolbar(not self.toolbar_shown, config)
|
pass
|
||||||
|
|
||||||
|
def toggle_toolbar(self):
|
||||||
|
new_state = not self.toolbar_shown
|
||||||
|
self.show_toolbar(new_state)
|
||||||
|
if self.config and self.CONFIG_KEY_SHOW_TOOLBAR:
|
||||||
|
self.config.set_key(self.CONFIG_KEY_SHOW_TOOLBAR, new_state)
|
||||||
|
|
||||||
def add_copy_menu(self, menu: QMenu, idx) -> QMenu:
|
def add_copy_menu(self, menu: QMenu, idx) -> QMenu:
|
||||||
cc = menu.addMenu(_("Copy"))
|
cc = menu.addMenu(_("Copy"))
|
||||||
|
|||||||
Reference in New Issue
Block a user