Browse Source

move freeze/unfreeze menus to coins tab, show utxos as tree

283
ThomasV 8 years ago
parent
commit
ac53585a40
  1. 5
      gui/qt/address_list.py
  2. 42
      gui/qt/utxo_list.py

5
gui/qt/address_list.py

@ -124,11 +124,6 @@ class AddressList(MyTreeWidget):
if addr_URL:
menu.addAction(_("View on block explorer"), lambda: webbrowser.open(addr_URL))
if any(not self.wallet.is_frozen(addr) for addr in addrs):
menu.addAction(_("Freeze"), lambda: self.parent.set_frozen_state(addrs, True))
if any(self.wallet.is_frozen(addr) for addr in addrs):
menu.addAction(_("Unfreeze"), lambda: self.parent.set_frozen_state(addrs, False))
run_hook('receive_menu', menu, addrs, self.wallet)
menu.exec_(self.viewport().mapToGlobal(position))

42
gui/qt/utxo_list.py

@ -25,12 +25,13 @@
from util import *
from electrum.i18n import _
from electrum.bitcoin import is_address
class UTXOList(MyTreeWidget):
def __init__(self, parent=None):
MyTreeWidget.__init__(self, parent, self.create_menu, [ _('Output'), _('Address'), _('Label'), _('Amount'), ''], 2)
MyTreeWidget.__init__(self, parent, self.create_menu, [ _('Address'), _('Label'), _('Amount'), ''], 1)
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
def get_name(self, x):
@ -41,29 +42,44 @@ class UTXOList(MyTreeWidget):
item = self.currentItem()
self.clear()
self.utxos = self.wallet.get_utxos()
address_items = {}
for x in self.utxos:
address = x.get('address')
address_item = address_items.get(address)
if address_item is None:
label = self.wallet.get_label(address)
address_item = QTreeWidgetItem([address, label, ''])
address_item.setData(0, Qt.UserRole, address)
address_items[address] = address_item
self.addChild(address_item)
address_item.setExpanded(True)
if self.wallet.is_frozen(address):
address_item.setBackgroundColor(0, QColor('lightblue'))
name = self.get_name(x)
label = self.wallet.get_label(x.get('prevout_hash'))
amount = self.parent.format_amount(x['value'])
utxo_item = QTreeWidgetItem([name[0:10]+'...'+name[-10:], address, label, amount])
utxo_item = QTreeWidgetItem([name[0:20]+'...'+name[-20:], label, amount])
utxo_item.setFont(0, QFont(MONOSPACE_FONT))
utxo_item.setFont(1, QFont(MONOSPACE_FONT))
utxo_item.setData(0, Qt.UserRole, name)
if self.wallet.is_frozen(address):
utxo_item.setBackgroundColor(1, QColor('lightblue'))
self.addChild(utxo_item)
address_item.addChild(utxo_item)
def create_menu(self, position):
from electrum.wallet import Multisig_Wallet
selected = [ x.data(0, Qt.UserRole).toString() for x in self.selectedItems()]
selected = [str(x.data(0, Qt.UserRole).toString()) for x in self.selectedItems()]
if not selected:
return
coins = filter(lambda x: self.get_name(x) in selected, self.utxos)
menu = QMenu()
if len(selected) == 1:
coin = coins[0]
menu.addAction(_("Copy Address"), lambda: self.parent.app.clipboard().setText(coin.get('address')))
menu.addAction(_("Spend"), lambda: self.parent.spend_coins(coins))
if len(selected) == 1 and is_address(selected[0]):
addr = selected[0]
coins = filter(lambda x: x.get('address') == addr, self.utxos)
menu.addAction(_("Copy Address"), lambda: self.parent.app.clipboard().setText(addr))
if not self.wallet.is_frozen(addr):
menu.addAction(_("Freeze"), lambda: self.parent.set_frozen_state([addr], True))
else:
menu.addAction(_("Unfreeze"), lambda: self.parent.set_frozen_state([addr], False))
menu.addAction(_("Spend from Address"), lambda: self.parent.spend_coins(coins))
else:
coins = filter(lambda x: self.get_name(x) in selected, self.utxos)
menu.addAction(_("Spend"), lambda: self.parent.spend_coins(coins))
menu.exec_(self.viewport().mapToGlobal(position))

Loading…
Cancel
Save