qt channels list: make selection more in line with other tabs

(allow selecting none, and allow multi-select)
This commit is contained in:
SomberNight 2020-03-26 02:54:21 +01:00
parent 7488cc91cd
commit 95979ba58d
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9

View file

@ -4,7 +4,8 @@ from enum import IntEnum
from PyQt5 import QtCore, QtGui
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMenu, QHBoxLayout, QLabel, QVBoxLayout, QGridLayout, QLineEdit, QPushButton
from PyQt5.QtWidgets import (QMenu, QHBoxLayout, QLabel, QVBoxLayout, QGridLayout, QLineEdit,
QPushButton, QAbstractItemView)
from PyQt5.QtGui import QFont
from electrum.util import bh2u, NotEnoughFunds, NoDynamicFeeEstimates
@ -46,6 +47,7 @@ class ChannelsList(MyTreeView):
super().__init__(parent, self.create_menu, stretch_column=self.Columns.NODE_ID,
editable_columns=[])
self.setModel(QtGui.QStandardItemModel(self))
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.main_window = parent
self.update_rows.connect(self.do_update_rows)
self.update_single_row.connect(self.do_update_single_row)
@ -121,7 +123,15 @@ class ChannelsList(MyTreeView):
def create_menu(self, position):
menu = QMenu()
menu.setSeparatorsCollapsible(True) # consecutive separators are merged together
idx = self.selectionModel().currentIndex()
selected = self.selected_in_column(self.Columns.NODE_ID)
if not selected:
return
multi_select = len(selected) > 1
if multi_select:
return
idx = self.indexAt(position)
if not idx.isValid():
return
item = self.model().itemFromIndex(idx)
if not item:
return
@ -153,7 +163,7 @@ class ChannelsList(MyTreeView):
menu.exec_(self.viewport().mapToGlobal(position))
@QtCore.pyqtSlot(Channel)
def do_update_single_row(self, chan):
def do_update_single_row(self, chan: Channel):
lnworker = self.parent.wallet.lnworker
if not lnworker:
return