Skip to content

Commit 328a2bb

Browse files
committed
config: migrate qt gui optional tabs to config vars
1 parent dfa2b71 commit 328a2bb

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

electrum/gui/qt/main_window.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
from .balance_dialog import BalanceToolButton, COLOR_FROZEN, COLOR_UNMATURED, COLOR_UNCONFIRMED, COLOR_CONFIRMED, COLOR_LIGHTNING, COLOR_FROZEN_LIGHTNING
104104

105105
if TYPE_CHECKING:
106+
from electrum.simple_config import ConfigVarWithConfig
106107
from . import ElectrumGui
107108

108109

@@ -173,8 +174,8 @@ def __init__(self, gui_object: 'ElectrumGui', wallet: Abstract_Wallet):
173174
self.gui_thread = gui_object.gui_thread
174175
assert wallet, "no wallet"
175176
self.wallet = wallet
176-
if wallet.has_lightning():
177-
self.wallet.config.set_key('show_channels_tab', True)
177+
if wallet.has_lightning() and not self.config.cv.GUI_QT_SHOW_TAB_CHANNELS.is_set():
178+
self.config.GUI_QT_SHOW_TAB_CHANNELS = True # override default, but still allow disabling tab manually
178179

179180
Exception_Hook.maybe_setup(config=self.config, wallet=self.wallet)
180181

@@ -216,19 +217,18 @@ def __init__(self, gui_object: 'ElectrumGui', wallet: Abstract_Wallet):
216217
tabs.addTab(self.send_tab, read_QIcon("tab_send.png"), _('Send'))
217218
tabs.addTab(self.receive_tab, read_QIcon("tab_receive.png"), _('Receive'))
218219

219-
def add_optional_tab(tabs, tab, icon, description, name):
220+
def add_optional_tab(tabs, tab, icon, description):
220221
tab.tab_icon = icon
221222
tab.tab_description = description
222223
tab.tab_pos = len(tabs)
223-
tab.tab_name = name
224-
if self.config.get('show_{}_tab'.format(name), False):
224+
if tab.is_shown_cv.get():
225225
tabs.addTab(tab, icon, description.replace("&", ""))
226226

227-
add_optional_tab(tabs, self.addresses_tab, read_QIcon("tab_addresses.png"), _("&Addresses"), "addresses")
228-
add_optional_tab(tabs, self.channels_tab, read_QIcon("lightning.png"), _("Channels"), "channels")
229-
add_optional_tab(tabs, self.utxo_tab, read_QIcon("tab_coins.png"), _("Co&ins"), "utxo")
230-
add_optional_tab(tabs, self.contacts_tab, read_QIcon("tab_contacts.png"), _("Con&tacts"), "contacts")
231-
add_optional_tab(tabs, self.console_tab, read_QIcon("tab_console.png"), _("Con&sole"), "console")
227+
add_optional_tab(tabs, self.addresses_tab, read_QIcon("tab_addresses.png"), _("&Addresses"))
228+
add_optional_tab(tabs, self.channels_tab, read_QIcon("lightning.png"), _("Channels"))
229+
add_optional_tab(tabs, self.utxo_tab, read_QIcon("tab_coins.png"), _("Co&ins"))
230+
add_optional_tab(tabs, self.contacts_tab, read_QIcon("tab_contacts.png"), _("Con&tacts"))
231+
add_optional_tab(tabs, self.console_tab, read_QIcon("tab_console.png"), _("Con&sole"))
232232

233233
tabs.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
234234

@@ -339,8 +339,8 @@ def on_fx_quotes(self):
339339
self.address_list.refresh_all()
340340

341341
def toggle_tab(self, tab):
342-
show = not self.config.get('show_{}_tab'.format(tab.tab_name), False)
343-
self.config.set_key('show_{}_tab'.format(tab.tab_name), show)
342+
show = not tab.is_shown_cv.get()
343+
tab.is_shown_cv.set(show)
344344
if show:
345345
# Find out where to place the tab
346346
index = len(self.tabs)
@@ -698,7 +698,7 @@ def init_menubar(self):
698698
wallet_menu.addAction(_("Find"), self.toggle_search).setShortcut(QKeySequence("Ctrl+F"))
699699

700700
def add_toggle_action(view_menu, tab):
701-
is_shown = self.config.get('show_{}_tab'.format(tab.tab_name), False)
701+
is_shown = tab.is_shown_cv.get()
702702
tab.menu_action = view_menu.addAction(tab.tab_description, lambda: self.toggle_tab(tab))
703703
tab.menu_action.setCheckable(True)
704704
tab.menu_action.setChecked(is_shown)
@@ -1026,7 +1026,9 @@ def refresh_tabs(self, wallet=None):
10261026

10271027
def create_channels_tab(self):
10281028
self.channels_list = ChannelsList(self)
1029-
return self.create_list_tab(self.channels_list)
1029+
tab = self.create_list_tab(self.channels_list)
1030+
tab.is_shown_cv = self.config.cv.GUI_QT_SHOW_TAB_CHANNELS
1031+
return tab
10301032

10311033
def create_history_tab(self):
10321034
self.history_model = HistoryModel(self)
@@ -1351,17 +1353,22 @@ def create_addresses_tab(self):
13511353
from .address_list import AddressList
13521354
self.address_list = AddressList(self)
13531355
tab = self.create_list_tab(self.address_list)
1356+
tab.is_shown_cv = self.config.cv.GUI_QT_SHOW_TAB_ADDRESSES
13541357
return tab
13551358

13561359
def create_utxo_tab(self):
13571360
from .utxo_list import UTXOList
13581361
self.utxo_list = UTXOList(self)
1359-
return self.create_list_tab(self.utxo_list)
1362+
tab = self.create_list_tab(self.utxo_list)
1363+
tab.is_shown_cv = self.config.cv.GUI_QT_SHOW_TAB_UTXO
1364+
return tab
13601365

13611366
def create_contacts_tab(self):
13621367
from .contact_list import ContactList
13631368
self.contact_list = l = ContactList(self)
1364-
return self.create_list_tab(l)
1369+
tab = self.create_list_tab(l)
1370+
tab.is_shown_cv = self.config.cv.GUI_QT_SHOW_TAB_CONTACTS
1371+
return tab
13651372

13661373
def remove_address(self, addr):
13671374
if not self.question(_("Do you want to remove {} from your wallet?").format(addr)):
@@ -1489,6 +1496,7 @@ def show_lightning_invoice(self, invoice: Invoice):
14891496
def create_console_tab(self):
14901497
from .console import Console
14911498
self.console = console = Console()
1499+
console.is_shown_cv = self.config.cv.GUI_QT_SHOW_TAB_CONSOLE
14921500
return console
14931501

14941502
def update_console(self):

electrum/simple_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,11 @@ def __setattr__(self, name, value):
911911
GUI_QT_TX_EDITOR_SHOW_IO = ConfigVar('show_tx_io', default=False, type_=bool)
912912
GUI_QT_TX_EDITOR_SHOW_FEE_DETAILS = ConfigVar('show_tx_fee_details', default=False, type_=bool)
913913
GUI_QT_TX_EDITOR_SHOW_LOCKTIME = ConfigVar('show_tx_locktime', default=False, type_=bool)
914+
GUI_QT_SHOW_TAB_ADDRESSES = ConfigVar('show_addresses_tab', default=False, type_=bool)
915+
GUI_QT_SHOW_TAB_CHANNELS = ConfigVar('show_channels_tab', default=False, type_=bool)
916+
GUI_QT_SHOW_TAB_UTXO = ConfigVar('show_utxo_tab', default=False, type_=bool)
917+
GUI_QT_SHOW_TAB_CONTACTS = ConfigVar('show_contacts_tab', default=False, type_=bool)
918+
GUI_QT_SHOW_TAB_CONSOLE = ConfigVar('show_console_tab', default=False, type_=bool)
914919

915920
GUI_QML_PREFERRED_REQUEST_TYPE = ConfigVar('preferred_request_type', default='bolt11', type_=str)
916921
GUI_QML_USER_KNOWS_PRESS_AND_HOLD = ConfigVar('user_knows_press_and_hold', default=False, type_=bool)

0 commit comments

Comments
 (0)