Browse Source

Refactor for loop in UTXOList

This refactor makes UTXOList somewhat easier to subclass.
sqlite_db
JeremyRand 6 years ago
parent
commit
8716bc8cfb
No known key found for this signature in database GPG Key ID: B3F2D165786D6570
  1. 35
      electrum/gui/qt/utxo_list.py

35
electrum/gui/qt/utxo_list.py

@ -47,22 +47,25 @@ class UTXOList(MyTreeView):
self.model().clear() self.model().clear()
self.update_headers(self.__class__.headers) self.update_headers(self.__class__.headers)
for idx, x in enumerate(utxos): for idx, x in enumerate(utxos):
address = x.get('address') self.insert_utxo(idx, x)
height = x.get('height')
name = x.get('prevout_hash') + ":%d"%x.get('prevout_n') def insert_utxo(self, idx, x):
self.utxo_dict[name] = x address = x.get('address')
label = self.wallet.get_label(x.get('prevout_hash')) height = x.get('height')
amount = self.parent.format_amount(x['value'], whitespaces=True) name = x.get('prevout_hash') + ":%d"%x.get('prevout_n')
labels = [address, label, amount, '%d'%height, name[0:10] + '...' + name[-2:]] self.utxo_dict[name] = x
utxo_item = [QStandardItem(x) for x in labels] label = self.wallet.get_label(x.get('prevout_hash'))
self.set_editability(utxo_item) amount = self.parent.format_amount(x['value'], whitespaces=True)
utxo_item[0].setFont(QFont(MONOSPACE_FONT)) labels = [address, label, amount, '%d'%height, name[0:10] + '...' + name[-2:]]
utxo_item[2].setFont(QFont(MONOSPACE_FONT)) utxo_item = [QStandardItem(x) for x in labels]
utxo_item[4].setFont(QFont(MONOSPACE_FONT)) self.set_editability(utxo_item)
utxo_item[0].setData(name, Qt.UserRole) utxo_item[0].setFont(QFont(MONOSPACE_FONT))
if self.wallet.is_frozen(address): utxo_item[2].setFont(QFont(MONOSPACE_FONT))
utxo_item[0].setBackground(ColorScheme.BLUE.as_color(True)) utxo_item[4].setFont(QFont(MONOSPACE_FONT))
self.model().insertRow(idx, utxo_item) utxo_item[0].setData(name, Qt.UserRole)
if self.wallet.is_frozen(address):
utxo_item[0].setBackground(ColorScheme.BLUE.as_color(True))
self.model().insertRow(idx, utxo_item)
def selected_column_0_user_roles(self) -> Optional[List[str]]: def selected_column_0_user_roles(self) -> Optional[List[str]]:
if not self.model(): if not self.model():

Loading…
Cancel
Save