electrum-bitcoinprivate/gui/qt/history_list.py

149 lines
6.0 KiB
Python
Raw Normal View History

2015-04-04 11:59:57 -07:00
#!/usr/bin/env python
#
# Electrum - lightweight Bitcoin client
# Copyright (C) 2015 Thomas Voegtlin
#
2016-02-23 02:36:42 -08:00
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
2015-04-04 11:59:57 -07:00
#
2016-02-23 02:36:42 -08:00
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
2015-04-04 11:59:57 -07:00
#
2016-02-23 02:36:42 -08:00
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
2015-04-04 11:59:57 -07:00
import webbrowser
from util import *
from electrum.i18n import _
from electrum.util import block_explorer_URL, format_satoshis, format_time
2015-04-04 11:59:57 -07:00
from electrum.plugins import run_hook
class HistoryList(MyTreeWidget):
2015-04-04 11:59:57 -07:00
def __init__(self, parent=None):
MyTreeWidget.__init__(self, parent, self.create_menu, [], 3)
self.refresh_headers()
self.setColumnHidden(1, True)
2015-04-04 11:59:57 -07:00
def refresh_headers(self):
headers = ['', '', _('Date'), _('Description') , _('Amount'),
_('Balance')]
run_hook('history_tab_headers', headers)
self.update_headers(headers)
def get_icon(self, height, conf, timestamp, is_final):
time_str = format_time(timestamp) if timestamp else _("unknown")
if not is_final:
time_str = _('Replaceable')
icon = QIcon(":icons/warning.png")
elif height < 0:
time_str = _('Unconfirmed inputs')
icon = QIcon(":icons/warning.png")
elif height == 0:
time_str = _('Unconfirmed')
icon = QIcon(":icons/unconfirmed.png")
elif conf == 0:
time_str = _('Not Verified')
icon = QIcon(":icons/unconfirmed.png")
elif conf < 6:
icon = QIcon(":icons/clock%d.png"%conf)
else:
icon = QIcon(":icons/confirmed.png")
return icon, time_str
def get_domain(self):
'''Replaced in address_dialog.py'''
return self.wallet.get_account_addresses(self.parent.current_account)
def on_update(self):
2015-04-04 11:59:57 -07:00
self.wallet = self.parent.wallet
h = self.wallet.get_history(self.get_domain())
2015-04-04 11:59:57 -07:00
item = self.currentItem()
current_tx = item.data(0, Qt.UserRole).toString() if item else None
self.clear()
run_hook('history_tab_update_begin')
2016-05-28 06:51:00 -07:00
for h_item in h:
tx_hash, height, conf, timestamp, value, balance = h_item
if conf == 0:
tx = self.wallet.transactions.get(tx_hash)
2016-05-30 07:10:25 -07:00
is_final = tx and tx.is_final()
else:
is_final = True
icon, time_str = self.get_icon(height, conf, timestamp, is_final)
2015-04-04 11:59:57 -07:00
v_str = self.parent.format_amount(value, True, whitespaces=True)
balance_str = self.parent.format_amount(balance, whitespaces=True)
2015-12-15 03:52:30 -08:00
label = self.wallet.get_label(tx_hash)
2015-09-05 00:11:48 -07:00
entry = ['', tx_hash, time_str, label, v_str, balance_str]
2016-05-28 06:51:00 -07:00
run_hook('history_tab_update', h_item, entry)
item = QTreeWidgetItem(entry)
item.setIcon(0, icon)
2015-09-05 00:11:48 -07:00
for i in range(len(entry)):
if i>3:
item.setTextAlignment(i, Qt.AlignRight)
2015-09-05 00:24:53 -07:00
if i!=2:
item.setFont(i, QFont(MONOSPACE_FONT))
2015-04-04 11:59:57 -07:00
if value < 0:
item.setForeground(3, QBrush(QColor("#BC1E1E")))
item.setForeground(4, QBrush(QColor("#BC1E1E")))
2015-04-04 11:59:57 -07:00
if tx_hash:
item.setData(0, Qt.UserRole, tx_hash)
self.insertTopLevelItem(0, item)
if current_tx == tx_hash:
self.setCurrentItem(item)
def update_item(self, tx_hash, height, conf, timestamp):
icon, time_str = self.get_icon(height, conf, timestamp, True)
items = self.findItems(tx_hash, Qt.UserRole|Qt.MatchContains|Qt.MatchRecursive, column=1)
if items:
item = items[0]
item.setIcon(0, icon)
item.setText(2, time_str)
2015-04-04 11:59:57 -07:00
def create_menu(self, position):
self.selectedIndexes()
item = self.currentItem()
if not item:
return
column = self.currentColumn()
2015-04-04 11:59:57 -07:00
tx_hash = str(item.data(0, Qt.UserRole).toString())
if not tx_hash:
return
if column is 0:
column_title = "ID"
column_data = tx_hash
else:
column_title = self.headerItem().text(column)
column_data = item.text(column)
tx_URL = block_explorer_URL(self.config, 'tx', tx_hash)
height, conf, timestamp = self.wallet.get_tx_height(tx_hash)
2016-05-20 01:38:48 -07:00
tx = self.wallet.transactions.get(tx_hash)
is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx)
rbf = is_mine and height <=0 and tx and not tx.is_final()
2015-04-04 11:59:57 -07:00
menu = QMenu()
menu.addAction(_("Copy %s")%column_title, lambda: self.parent.app.clipboard().setText(column_data))
if column in self.editable_columns:
menu.addAction(_("Edit %s")%column_title, lambda: self.editItem(item, column))
2016-05-20 01:38:48 -07:00
menu.addAction(_("Details"), lambda: self.parent.show_transaction(tx))
if rbf:
menu.addAction(_("Increase fee"), lambda: self.parent.bump_fee_dialog(tx))
if tx_URL:
menu.addAction(_("View on block explorer"), lambda: webbrowser.open(tx_URL))
2015-04-04 11:59:57 -07:00
menu.exec_(self.viewport().mapToGlobal(position))