Skip to content

Commit 689b547

Browse files
authored
Merge pull request #245 from alejoe91/fix-order-mergeview
Fix order of units in mergeview
2 parents 50e02ee + a7048b9 commit 689b547

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

spikeinterface_gui/mergeview.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def _qt_make_layout(self):
270270

271271
def _qt_refresh(self):
272272
from .myqt import QT
273-
from .utils_qt import CustomItem
273+
from .utils_qt import CustomItem, CustomItemUnitID
274274

275275
self.table.clear()
276276
self.table.setSortingEnabled(False)
@@ -287,6 +287,7 @@ def _qt_refresh(self):
287287
self.table.setColumnCount(len(labels))
288288
self.table.setHorizontalHeaderLabels(labels)
289289
self.table.setRowCount(len(rows))
290+
unit_ids = self.controller.unit_ids
290291

291292
for r, row in enumerate(rows):
292293
for c, label in enumerate(labels):
@@ -298,7 +299,7 @@ def _qt_refresh(self):
298299
pix = QT.QPixmap(16, 16)
299300
pix.fill(color)
300301
icon = QT.QIcon(pix)
301-
item = QT.QTableWidgetItem(name)
302+
item = CustomItemUnitID(unit_ids, name)
302303
item.setData(QT.Qt.ItemDataRole.UserRole, unit_id)
303304
item.setFlags(QT.Qt.ItemIsEnabled | QT.Qt.ItemIsSelectable)
304305
self.table.setItem(r, c, item)

spikeinterface_gui/utils_qt.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,14 @@ def __init__(self, unit_ids, *args, **kwargs):
470470
self.unit_ids = [f"{u}" for u in unit_ids]
471471

472472
def __lt__(self, other):
473-
ind = self.unit_ids.index(self.text())
474-
other_ind = self.unit_ids.index(other.text())
473+
# since mergeview has "{unit_id} (n={n_spikes})" as name, we split and keep the first part
474+
unit_id = self.text().split(' ')[0]
475+
other_unit_id = other.text().split(' ')[0]
476+
ind = self.unit_ids.index(unit_id)
477+
other_ind = self.unit_ids.index(other_unit_id)
475478
return ind < other_ind
476479

480+
477481
class OrderableCheckItem(QT.QTableWidgetItem):
478482
# special case for checkbox
479483
def is_checked(self):

0 commit comments

Comments
 (0)