qt coin control: introduce second status bar

This commit is contained in:
SomberNight 2019-11-13 19:09:07 +01:00
parent 800c05b32f
commit 970bd4e95f
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9
2 changed files with 43 additions and 15 deletions

View file

@ -174,6 +174,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.completions = QStringListModel() self.completions = QStringListModel()
coincontrol_sb = self.create_coincontrol_statusbar()
self.tabs = tabs = QTabWidget(self) self.tabs = tabs = QTabWidget(self)
self.send_tab = self.create_send_tab() self.send_tab = self.create_send_tab()
self.receive_tab = self.create_receive_tab() self.receive_tab = self.create_receive_tab()
@ -202,7 +204,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
add_optional_tab(tabs, self.console_tab, read_QIcon("tab_console.png"), _("Con&sole"), "console") add_optional_tab(tabs, self.console_tab, read_QIcon("tab_console.png"), _("Con&sole"), "console")
tabs.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) tabs.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.setCentralWidget(tabs)
central_widget = QWidget()
vbox = QVBoxLayout(central_widget)
vbox.setContentsMargins(0, 0, 0, 0)
vbox.addWidget(tabs)
vbox.addWidget(coincontrol_sb)
self.setCentralWidget(central_widget)
if self.config.get("is_maximized"): if self.config.get("is_maximized"):
self.showMaximized() self.showMaximized()
@ -1759,8 +1768,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
def create_utxo_tab(self): def create_utxo_tab(self):
from .utxo_list import UTXOList from .utxo_list import UTXOList
self.utxo_list = UTXOList(self) self.utxo_list = UTXOList(self)
t = self.utxo_list.get_toolbar() return self.create_list_tab(self.utxo_list)
return self.create_list_tab(self.utxo_list, t)
def create_contacts_tab(self): def create_contacts_tab(self):
from .contact_list import ContactList from .contact_list import ContactList
@ -1948,6 +1956,33 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
run_hook('create_status_bar', sb) run_hook('create_status_bar', sb)
self.setStatusBar(sb) self.setStatusBar(sb)
def create_coincontrol_statusbar(self):
self.coincontrol_sb = sb = QStatusBar()
sb.setSizeGripEnabled(False)
sb.setFixedHeight(3 * char_width_in_lineedit())
sb.setStyleSheet('QStatusBar::item {border: None;} '
+ ColorScheme.GREEN.as_stylesheet(True))
self.coincontrol_label = QLabel()
self.coincontrol_label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
self.coincontrol_label.setTextInteractionFlags(Qt.TextSelectableByMouse)
sb.addWidget(self.coincontrol_label)
clear_cc_button = EnterButton(_('Reset'), lambda: self.utxo_list.set_spend_list([]))
clear_cc_button.setStyleSheet("margin-right: 5px;")
sb.addPermanentWidget(clear_cc_button)
sb.setVisible(False)
return sb
def set_coincontrol_msg(self, msg: Optional[str]) -> None:
if not msg:
self.coincontrol_label.setText("")
self.coincontrol_sb.setVisible(False)
return
self.coincontrol_label.setText(msg)
self.coincontrol_sb.setVisible(True)
def update_lock_icon(self): def update_lock_icon(self):
icon = read_QIcon("lock.png") if self.wallet.has_password() else read_QIcon("unlock.png") icon = read_QIcon("lock.png") if self.wallet.has_password() else read_QIcon("unlock.png")
self.password_button.setIcon(icon) self.password_button.setIcon(icon)

View file

@ -58,8 +58,6 @@ class UTXOList(MyTreeView):
super().__init__(parent, self.create_menu, super().__init__(parent, self.create_menu,
stretch_column=self.Columns.LABEL, stretch_column=self.Columns.LABEL,
editable_columns=[]) editable_columns=[])
self.cc_label = QLabel('')
self.clear_cc_button = EnterButton(_('Reset'), lambda: self.set_spend_list([]))
self.spend_list = [] # type: Sequence[str] self.spend_list = [] # type: Sequence[str]
self.setModel(QStandardItemModel(self)) self.setModel(QStandardItemModel(self))
self.setSelectionMode(QAbstractItemView.ExtendedSelection) self.setSelectionMode(QAbstractItemView.ExtendedSelection)
@ -76,14 +74,16 @@ class UTXOList(MyTreeView):
for idx, utxo in enumerate(utxos): for idx, utxo in enumerate(utxos):
self.insert_utxo(idx, utxo) self.insert_utxo(idx, utxo)
self.filter() self.filter()
self.clear_cc_button.setEnabled(bool(self.spend_list)) # update coincontrol status bar
# update cc_label
coins = [self.utxo_dict[x] for x in self.spend_list] or utxos coins = [self.utxo_dict[x] for x in self.spend_list] or utxos
coins = self._filter_frozen_coins(coins) coins = self._filter_frozen_coins(coins)
amount = sum(x.value_sats() for x in coins) amount = sum(x.value_sats() for x in coins)
amount_str = self.parent.format_amount_and_units(amount) amount_str = self.parent.format_amount_and_units(amount)
num_outputs_str = _("{} outputs available ({} total)").format(len(coins), len(utxos)) num_outputs_str = _("{} outputs available ({} total)").format(len(coins), len(utxos))
self.cc_label.setText(f'{num_outputs_str}, {amount_str}') if self.spend_list:
self.parent.set_coincontrol_msg(_("Coin control active") + f': {num_outputs_str}, {amount_str}')
else:
self.parent.set_coincontrol_msg(None)
def insert_utxo(self, idx, utxo: PartialTxInput): def insert_utxo(self, idx, utxo: PartialTxInput):
address = utxo.address address = utxo.address
@ -145,13 +145,6 @@ class UTXOList(MyTreeView):
if not all([prevout_str in utxo_set for prevout_str in self.spend_list]): if not all([prevout_str in utxo_set for prevout_str in self.spend_list]):
self.spend_list = [] self.spend_list = []
def get_toolbar(self):
h = QHBoxLayout()
h.addWidget(self.cc_label)
h.addStretch()
h.addWidget(self.clear_cc_button)
return h
def create_menu(self, position): def create_menu(self, position):
selected = self.get_selected_outpoints() selected = self.get_selected_outpoints()
if not selected: if not selected: