Browse Source

qt: persist addresses tab toolbar "show/hide" state, like in 4.3.4

master
SomberNight 3 years ago
parent
commit
b40a608b74
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 3
      electrum/gui/qt/address_list.py
  2. 3
      electrum/gui/qt/history_list.py
  3. 2
      electrum/gui/qt/main_window.py
  4. 32
      electrum/gui/qt/my_treeview.py

3
electrum/gui/qt/address_list.py

@ -120,10 +120,11 @@ class AddressList(MyTreeView):
addr = self.get_role_data_for_current_item(col=0, role=self.ROLE_ADDRESS_STR)
self.main_window.show_address(addr)
CONFIG_KEY_SHOW_TOOLBAR = "show_toolbar_addresses"
def create_toolbar(self, config):
toolbar, menu = self.create_toolbar_with_menu('')
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)
hbox = self.create_toolbar_buttons()
toolbar.insertLayout(1, hbox)

3
electrum/gui/qt/history_list.py

@ -546,10 +546,11 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
self.end_button.setText(_('To') + ' ' + self.format_date(self.end_date))
self.hide_rows()
CONFIG_KEY_SHOW_TOOLBAR = "show_toolbar_history"
def create_toolbar(self, config):
toolbar, menu = self.create_toolbar_with_menu('')
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_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)

2
electrum/gui/qt/main_window.py

@ -1339,6 +1339,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
if toolbar:
vbox.addLayout(toolbar)
vbox.addWidget(l)
if toolbar:
l.show_toolbar()
return w
def create_addresses_tab(self):

32
electrum/gui/qt/my_treeview.py

@ -51,7 +51,7 @@ from PyQt5.QtWidgets import (QPushButton, QLabel, QMessageBox, QHBoxLayout,
QFileDialog, QWidget, QToolButton, QTreeView, QPlainTextEdit,
QHeaderView, QApplication, QToolTip, QTreeWidget, QStyledItemDelegate,
QMenu, QStyleOptionViewItem, QLayout, QLayoutItem, QAbstractButton,
QGraphicsEffect, QGraphicsScene, QGraphicsPixmapItem, QSizePolicy)
QGraphicsEffect, QGraphicsScene, QGraphicsPixmapItem, QSizePolicy, QAction)
from electrum.i18n import _, languages
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
if TYPE_CHECKING:
from electrum import SimpleConfig
from .main_window import ElectrumWindow
@ -73,13 +74,13 @@ class MyMenu(QMenu):
self.setToolTipsVisible(True)
self.config = config
def addToggle(self, text: str, callback, *, tooltip=''):
def addToggle(self, text: str, callback, *, tooltip='') -> QAction:
m = self.addAction(text, callback)
m.setCheckable(True)
m.setToolTip(tooltip)
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)
m = self.addAction(text, lambda: self._do_toggle_config(name, default, callback))
m.setCheckable(True)
@ -94,7 +95,7 @@ class MyMenu(QMenu):
callback()
def create_toolbar_with_menu(config, title):
def create_toolbar_with_menu(config: 'SimpleConfig', title):
menu = MyMenu(config)
toolbar_button = QToolButton()
toolbar_button.setIcon(read_QIcon("preferences.png"))
@ -401,7 +402,15 @@ class MyTreeView(QTreeView):
def create_toolbar_with_menu(self, 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:
return
self.toolbar_shown = state
@ -409,9 +418,18 @@ class MyTreeView(QTreeView):
b.setVisible(state)
if not state:
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):
self.show_toolbar(not self.toolbar_shown, config)
def on_hide_toolbar(self):
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:
cc = menu.addMenu(_("Copy"))

Loading…
Cancel
Save