qt: clean-up in some MyTreeView children (mv code from update to init)
This commit is contained in:
@@ -78,8 +78,9 @@ class AddressList(MyTreeView):
|
|||||||
|
|
||||||
filter_columns = [Columns.TYPE, Columns.ADDRESS, Columns.LABEL, Columns.COIN_BALANCE]
|
filter_columns = [Columns.TYPE, Columns.ADDRESS, Columns.LABEL, Columns.COIN_BALANCE]
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent):
|
||||||
super().__init__(parent, self.create_menu, stretch_column=self.Columns.LABEL)
|
super().__init__(parent, self.create_menu, stretch_column=self.Columns.LABEL)
|
||||||
|
self.wallet = self.parent.wallet
|
||||||
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
|
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
|
||||||
self.setSortingEnabled(True)
|
self.setSortingEnabled(True)
|
||||||
self.show_change = AddressTypeFilter.ALL # type: AddressTypeFilter
|
self.show_change = AddressTypeFilter.ALL # type: AddressTypeFilter
|
||||||
@@ -136,7 +137,6 @@ class AddressList(MyTreeView):
|
|||||||
|
|
||||||
@profiler
|
@profiler
|
||||||
def update(self):
|
def update(self):
|
||||||
self.wallet = self.parent.wallet
|
|
||||||
current_address = self.current_item_user_role(col=self.Columns.LABEL)
|
current_address = self.current_item_user_role(col=self.Columns.LABEL)
|
||||||
if self.show_change == AddressTypeFilter.RECEIVING:
|
if self.show_change == AddressTypeFilter.RECEIVING:
|
||||||
addr_list = self.wallet.get_receiving_addresses()
|
addr_list = self.wallet.get_receiving_addresses()
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class RequestList(MyTreeView):
|
|||||||
super().__init__(parent, self.create_menu,
|
super().__init__(parent, self.create_menu,
|
||||||
stretch_column=self.Columns.DESCRIPTION,
|
stretch_column=self.Columns.DESCRIPTION,
|
||||||
editable_columns=[])
|
editable_columns=[])
|
||||||
|
self.wallet = self.parent.wallet
|
||||||
self.setModel(QStandardItemModel(self))
|
self.setModel(QStandardItemModel(self))
|
||||||
self.setSortingEnabled(True)
|
self.setSortingEnabled(True)
|
||||||
self.update()
|
self.update()
|
||||||
@@ -106,8 +107,6 @@ class RequestList(MyTreeView):
|
|||||||
status_item.setIcon(read_QIcon(pr_icons.get(status)))
|
status_item.setIcon(read_QIcon(pr_icons.get(status)))
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.wallet = self.parent.wallet
|
|
||||||
domain = self.wallet.get_receiving_addresses()
|
|
||||||
self.parent.update_receive_address_styling()
|
self.parent.update_receive_address_styling()
|
||||||
self.model().clear()
|
self.model().clear()
|
||||||
self.update_headers(self.__class__.headers)
|
self.update_headers(self.__class__.headers)
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ from .util import MyTreeView, ColorScheme, MONOSPACE_FONT, EnterButton
|
|||||||
|
|
||||||
|
|
||||||
class UTXOList(MyTreeView):
|
class UTXOList(MyTreeView):
|
||||||
|
_spend_set: Optional[Set[str]] # coins selected by the user to spend from
|
||||||
|
_utxo_dict: Dict[str, PartialTxInput] # coin name -> coin
|
||||||
|
|
||||||
class Columns(IntEnum):
|
class Columns(IntEnum):
|
||||||
OUTPOINT = 0
|
OUTPOINT = 0
|
||||||
@@ -55,21 +57,23 @@ class UTXOList(MyTreeView):
|
|||||||
}
|
}
|
||||||
filter_columns = [Columns.ADDRESS, Columns.LABEL, Columns.OUTPOINT]
|
filter_columns = [Columns.ADDRESS, Columns.LABEL, Columns.OUTPOINT]
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent):
|
||||||
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._spend_set = None # type: Optional[Set[str]] # coins selected by the user to spend from
|
self._spend_set = None
|
||||||
|
self._utxo_dict = {}
|
||||||
|
self.wallet = self.parent.wallet
|
||||||
|
|
||||||
self.setModel(QStandardItemModel(self))
|
self.setModel(QStandardItemModel(self))
|
||||||
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
|
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
|
||||||
self.setSortingEnabled(True)
|
self.setSortingEnabled(True)
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.wallet = self.parent.wallet
|
|
||||||
utxos = self.wallet.get_utxos()
|
utxos = self.wallet.get_utxos()
|
||||||
self._maybe_reset_spend_list(utxos)
|
self._maybe_reset_spend_list(utxos)
|
||||||
self.utxo_dict = {} # type: Dict[str, PartialTxInput]
|
self._utxo_dict = {}
|
||||||
self.model().clear()
|
self.model().clear()
|
||||||
self.update_headers(self.__class__.headers)
|
self.update_headers(self.__class__.headers)
|
||||||
for idx, utxo in enumerate(utxos):
|
for idx, utxo in enumerate(utxos):
|
||||||
@@ -77,7 +81,7 @@ class UTXOList(MyTreeView):
|
|||||||
self.filter()
|
self.filter()
|
||||||
# update coincontrol status bar
|
# update coincontrol status bar
|
||||||
if self._spend_set is not None:
|
if self._spend_set is not None:
|
||||||
coins = [self.utxo_dict[x] for x in self._spend_set]
|
coins = [self._utxo_dict[x] for x in self._spend_set]
|
||||||
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)
|
||||||
@@ -91,7 +95,7 @@ class UTXOList(MyTreeView):
|
|||||||
height = utxo.block_height
|
height = utxo.block_height
|
||||||
name = utxo.prevout.to_str()
|
name = utxo.prevout.to_str()
|
||||||
name_short = utxo.prevout.txid.hex()[:16] + '...' + ":%d" % utxo.prevout.out_idx
|
name_short = utxo.prevout.txid.hex()[:16] + '...' + ":%d" % utxo.prevout.out_idx
|
||||||
self.utxo_dict[name] = utxo
|
self._utxo_dict[name] = utxo
|
||||||
label = self.wallet.get_label(utxo.prevout.txid.hex())
|
label = self.wallet.get_label(utxo.prevout.txid.hex())
|
||||||
amount = self.parent.format_amount(utxo.value_sats(), whitespaces=True)
|
amount = self.parent.format_amount(utxo.value_sats(), whitespaces=True)
|
||||||
labels = [name_short, address, label, amount, '%d'%height]
|
labels = [name_short, address, label, amount, '%d'%height]
|
||||||
@@ -142,7 +146,7 @@ class UTXOList(MyTreeView):
|
|||||||
def get_spend_list(self) -> Optional[Sequence[PartialTxInput]]:
|
def get_spend_list(self) -> Optional[Sequence[PartialTxInput]]:
|
||||||
if self._spend_set is None:
|
if self._spend_set is None:
|
||||||
return None
|
return None
|
||||||
utxos = [self.utxo_dict[x] for x in self._spend_set]
|
utxos = [self._utxo_dict[x] for x in self._spend_set]
|
||||||
return copy.deepcopy(utxos) # copy so that side-effects don't affect utxo_dict
|
return copy.deepcopy(utxos) # copy so that side-effects don't affect utxo_dict
|
||||||
|
|
||||||
def _maybe_reset_spend_list(self, current_wallet_utxos: Sequence[PartialTxInput]) -> None:
|
def _maybe_reset_spend_list(self, current_wallet_utxos: Sequence[PartialTxInput]) -> None:
|
||||||
@@ -159,7 +163,7 @@ class UTXOList(MyTreeView):
|
|||||||
return
|
return
|
||||||
menu = QMenu()
|
menu = QMenu()
|
||||||
menu.setSeparatorsCollapsible(True) # consecutive separators are merged together
|
menu.setSeparatorsCollapsible(True) # consecutive separators are merged together
|
||||||
coins = [self.utxo_dict[name] for name in selected]
|
coins = [self._utxo_dict[name] for name in selected]
|
||||||
if len(coins) == 0:
|
if len(coins) == 0:
|
||||||
menu.addAction(_("Spend (select none)"), lambda: self.set_spend_list(coins))
|
menu.addAction(_("Spend (select none)"), lambda: self.set_spend_list(coins))
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user