electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 4a2a45d7e3fa79332d9defec9b2c63d35bd2f832
parent d493dd19539bea0d2240d8eaad75f8b99e257d53
Author: Janus <ysangkok@gmail.com>
Date:   Tue,  4 Dec 2018 18:56:30 +0100

lightning: post rebase qt gui fixes

Diffstat:
Melectrum/gui/qt/channels_list.py | 33++++++++++++++++++---------------
Melectrum/gui/qt/main_window.py | 2--
Melectrum/gui/qt/request_list.py | 73+++++++++++++++++++++++++++++++++----------------------------------------
3 files changed, 51 insertions(+), 57 deletions(-)

diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import traceback import asyncio -from PyQt5 import QtCore, QtWidgets +from PyQt5 import QtCore, QtWidgets, QtGui from PyQt5.QtWidgets import * from electrum.util import inv_dict, bh2u, bfh @@ -9,16 +9,17 @@ from electrum.i18n import _ from electrum.lnchan import Channel from electrum.lnutil import LOCAL, REMOTE, ConnStringFormatError -from .util import MyTreeWidget, SortableTreeWidgetItem, WindowModalDialog, Buttons, OkButton, CancelButton +from .util import MyTreeView, WindowModalDialog, Buttons, OkButton, CancelButton from .amountedit import BTCAmountEdit from .channel_details import ChannelDetailsDialog -class ChannelsList(MyTreeWidget): +class ChannelsList(MyTreeView): update_rows = QtCore.pyqtSignal() update_single_row = QtCore.pyqtSignal(Channel) def __init__(self, parent): - MyTreeWidget.__init__(self, parent, self.create_menu, [_('Node ID'), _('Balance'), _('Remote'), _('Status')], 0) + super().__init__(parent, self.create_menu, 0) + self.setModel(QtGui.QStandardItemModel(self)) self.main_window = parent self.update_rows.connect(self.do_update_rows) self.update_single_row.connect(self.do_update_single_row) @@ -46,10 +47,11 @@ class ChannelsList(MyTreeWidget): network = self.parent.network lnworker = self.parent.wallet.lnworker menu = QMenu() - item = self.currentItem() + idx = self.selectionModel().currentIndex() + item = self.model().itemFromIndex(idx) if not item: return - channel_id = item.data(0, QtCore.Qt.UserRole) + channel_id = idx.sibling(idx.row(), 0).data(QtCore.Qt.UserRole) def on_success(txid): self.main_window.show_error('Channel closed' + '\n' + txid) def on_failure(exc_info): @@ -77,19 +79,20 @@ class ChannelsList(MyTreeWidget): @QtCore.pyqtSlot(Channel) def do_update_single_row(self, chan): - for i in range(self.topLevelItemCount()): - item = self.topLevelItem(i) - if item.data(0, QtCore.Qt.UserRole) == chan.channel_id: - for i, v in enumerate(self.format_fields(chan)): - item.setData(i, QtCore.Qt.DisplayRole, v) + for row in range(self.model().rowCount()): + item = self.model().item(row,0) + if item.data(QtCore.Qt.UserRole) == chan.channel_id: + for column, v in enumerate(self.format_fields(chan)): + self.model().item(row, column).setData(v, QtCore.Qt.DisplayRole) @QtCore.pyqtSlot() def do_update_rows(self): - self.clear() + self.model().clear() + self.update_headers([_('Node ID'), _('Balance'), _('Remote'), _('Status')]) for chan in self.parent.wallet.lnworker.channels.values(): - item = SortableTreeWidgetItem(self.format_fields(chan)) - item.setData(0, QtCore.Qt.UserRole, chan.channel_id) - self.insertTopLevelItem(0, item) + items = [QtGui.QStandardItem(x) for x in self.format_fields(chan)] + items[0].setData(chan.channel_id, QtCore.Qt.UserRole) + self.model().insertRow(0, items) def get_toolbar(self): b = QPushButton(_('Open Channel')) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -1070,8 +1070,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.address_list.update() self.clear_receive_tab() self.request_list.update() - items = self.request_list.findItems(key, Qt.UserRole|Qt.MatchContains|Qt.MatchRecursive, column=0) - self.request_list.setCurrentItem(items[0]) def create_bitcoin_request(self, amount, message, expiration): addr = self.wallet.get_unused_address() diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py @@ -26,7 +26,7 @@ from enum import IntEnum from PyQt5.QtGui import QStandardItemModel, QStandardItem -from PyQt5.QtWidgets import QMenu +from PyQt5.QtWidgets import QMenu, QHeaderView from PyQt5.QtCore import Qt from electrum.i18n import _ @@ -35,12 +35,17 @@ from electrum.plugin import run_hook from electrum.paymentrequest import PR_UNKNOWN from electrum.wallet import InternalAddressCorruption from electrum.bitcoin import COIN +from electrum.lnaddr import lndecode +import electrum.constants as constants from .util import MyTreeView, pr_tooltips, pr_icons, read_QIcon REQUEST_TYPE_BITCOIN = 0 REQUEST_TYPE_LN = 1 +ROLE_REQUEST_TYPE = Qt.UserRole +ROLE_RHASH_OR_ADDR = Qt.UserRole + 1 + class RequestList(MyTreeView): class Columns(IntEnum): @@ -67,9 +72,9 @@ class RequestList(MyTreeView): editable_columns=[]) self.setModel(QStandardItemModel(self)) self.setSortingEnabled(True) - self.setColumnWidth(self.Columns.DATE, 180) self.update() self.selectionModel().currentRowChanged.connect(self.item_changed) + self.setColumnWidth(self.Columns.ADDRESS, 250) def item_changed(self, idx): # TODO use siblingAtColumn when min Qt version is >=5.11 @@ -79,12 +84,13 @@ class RequestList(MyTreeView): self.update() return item = self.model().itemFromIndex(idx.sibling(idx.row(), 0)) - request_type = item.data(Qt.UserRole) - key = str(item.data(Qt.UserRole + 1)) + request_type = item.data(ROLE_REQUEST_TYPE) + key = item.data(ROLE_RHASH_OR_ADDR) if request_type == REQUEST_TYPE_BITCOIN: req = self.parent.get_request_URI(key) elif request_type == REQUEST_TYPE_LN: preimage, req = self.wallet.lnworker.invoices.get(key) + print(key, req) self.parent.receive_address_e.setText(req) def update(self): @@ -98,8 +104,6 @@ class RequestList(MyTreeView): self.parent.expires_label.hide() self.parent.expires_combo.show() - # update the receive address if necessary - #current_address = self.parent.receive_address_e.text() domain = self.wallet.get_receiving_addresses() try: addr = self.wallet.get_unused_address() @@ -113,6 +117,7 @@ class RequestList(MyTreeView): self.model().clear() self.update_headers(self.__class__.headers) + self.header().setSectionResizeMode(self.Columns.ADDRESS, QHeaderView.Interactive) # override resizemode in update_headers for req in self.wallet.get_sorted_requests(self.config): address = req['address'] if address not in domain: @@ -134,15 +139,12 @@ class RequestList(MyTreeView): items[self.Columns.SIGNATURE].setToolTip(f'signed by {requestor}') if status is not PR_UNKNOWN: items[self.Columns.STATUS].setIcon(read_QIcon(pr_icons.get(status))) - items[self.Columns.DESCRIPTION].setData(address, Qt.UserRole) self.model().insertRow(self.model().rowCount(), items) - items[0].setData(REQUEST_TYPE_BITCOIN, Qt.UserRole) - items[0].setData(address, Qt.UserRole+1) + items[0].setData(REQUEST_TYPE_BITCOIN, ROLE_REQUEST_TYPE) + items[0].setData(address, ROLE_RHASH_OR_ADDR) self.filter() # lightning for payreq_key, (preimage_hex, invoice) in self.wallet.lnworker.invoices.items(): - from electrum.lnaddr import lndecode - import electrum.constants as constants lnaddr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP) amount_sat = lnaddr.amount*COIN if lnaddr.amount else None amount_str = self.parent.format_amount(amount_sat) if amount_sat else '' @@ -152,60 +154,51 @@ class RequestList(MyTreeView): description = v break date = format_time(lnaddr.date) - labels = [date, r, '', description, amount_str, ''] + labels = [date, invoice, '', description, amount_str, ''] items = [QStandardItem(e) for e in labels] - items.setIcon(2, QIcon(":icons/lightning.png")) - items[0].setData(REQUEST_TYPE_LN, Qt.UserRole) - items[0].setData(payreq_key, Qt.UserRole+1) + items[2].setIcon(self.icon_cache.get(":icons/lightning.png")) + items[0].setData(REQUEST_TYPE_LN, ROLE_REQUEST_TYPE) + items[0].setData(payreq_key, ROLE_RHASH_OR_ADDR) self.model().insertRow(self.model().rowCount(), items) def create_menu(self, position): idx = self.indexAt(position) item = self.model().itemFromIndex(idx) # TODO use siblingAtColumn when min Qt version is >=5.11 - item_addr = self.model().itemFromIndex(idx.sibling(idx.row(), self.Columns.ADDRESS)) - if not item_addr: + item = self.model().itemFromIndex(idx.sibling(idx.row(), self.Columns.DATE)) + if not item: return - addr = item_addr.text() - request_type = self.model().itemFromIndex(idx.sibling(idx.row(), 0)).data(Qt.UserRole) + addr = item.data(ROLE_RHASH_OR_ADDR) + request_type = item.data(ROLE_REQUEST_TYPE) menu = None + assert request_type in [REQUEST_TYPE_BITCOIN, REQUEST_TYPE_LN] if request_type == REQUEST_TYPE_BITCOIN: - menu = self.create_menu_bitcoin_payreq(idx, addr) + req = self.wallet.receive_requests.get(addr) elif request_type == REQUEST_TYPE_LN: - menu = self.create_menu_ln_payreq(idx, addr) - if menu: - menu.exec_(self.viewport().mapToGlobal(position)) - - def create_menu_bitcoin_payreq(self, idx, addr): - req = self.wallet.receive_requests.get(addr) + preimage, req = self.wallet.lnworker.invoices.get(addr) if req is None: self.update() return column = idx.column() column_title = self.model().horizontalHeaderItem(column).text() - column_data = item.text() + column_data = self.model().itemFromIndex(idx).text() menu = QMenu(self) if column != self.Columns.SIGNATURE: if column == self.Columns.AMOUNT: column_data = column_data.strip() menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data)) + if request_type == REQUEST_TYPE_BITCOIN: + self.create_menu_bitcoin_payreq(menu, addr) + elif request_type == REQUEST_TYPE_LN: + self.create_menu_ln_payreq(menu, addr, req) + menu.exec_(self.viewport().mapToGlobal(position)) + + def create_menu_bitcoin_payreq(self, menu, addr): menu.addAction(_("Copy URI"), lambda: self.parent.view_and_paste('URI', '', self.parent.get_request_URI(addr))) menu.addAction(_("Save as BIP70 file"), lambda: self.parent.export_payment_request(addr)) menu.addAction(_("Delete"), lambda: self.parent.delete_payment_request(addr)) run_hook('receive_list_menu', menu, addr) - return menu - def create_menu_ln_payreq(self, idx, payreq_key): - preimage, req = self.wallet.lnworker.invoices.get(payreq_key) - if req is None: - self.update() - return - column = idx.column() - column_title = self.model().horizontalHeaderItem(column).text() - column_data = self.model().itemFromIndex(idx).text() - menu = QMenu(self) - if column != 2: - menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data)) + def create_menu_ln_payreq(self, menu, payreq_key, req): menu.addAction(_("Copy BOLT-11 Lightning invoice"), lambda: self.parent.view_and_paste('Invoice', '', req)) menu.addAction(_("Delete"), lambda: self.parent.delete_lightning_payreq(payreq_key)) - return menu