[tracks] add control buttons widget

This commit is contained in:
Jan Grewe 2025-01-28 10:56:03 +01:00
parent c14b729881
commit 17b907619c

View File

@ -3,10 +3,10 @@ import pathlib
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from PySide6.QtCore import Qt, QThreadPool, Signal, QAbstractTableModel, QSortFilterProxyModel, QItemSelectionModel from PySide6.QtCore import Qt, QThreadPool, Signal, QAbstractTableModel, QSortFilterProxyModel, QItemSelectionModel, QSize
from PySide6.QtGui import QImage, QBrush, QColor, QFont from PySide6.QtGui import QImage, QBrush, QColor, QFont
from PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QSizePolicy, QComboBox from PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QSizePolicy, QComboBox
from PySide6.QtWidgets import QSpinBox, QSpacerItem, QProgressBar, QTableView, QSplitter from PySide6.QtWidgets import QSpinBox, QSpacerItem, QProgressBar, QTableView, QSplitter, QGridLayout
from fixtracks.utils.reader import PickleLoader from fixtracks.utils.reader import PickleLoader
from fixtracks.widgets.detectionview import DetectionView from fixtracks.widgets.detectionview import DetectionView
@ -81,6 +81,93 @@ class FilterProxyModel(QSortFilterProxyModel):
def filterAcceptsColumn(self, source_column, source_parent): def filterAcceptsColumn(self, source_column, source_parent):
return True return True
class SelectionControls(QWidget):
next = Signal()
previous = Signal()
assignOne = Signal()
assignTwo = Signal()
assignOther = Signal()
def __init__(self, parent = None,):
super().__init__(parent)
font = QFont()
font.setBold(True)
font.setPointSize(10)
previousBtn = QPushButton("previous")
previousBtn.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
previousBtn.setToolTip("Go back to previous window (right-arrow)")
previousBtn.setEnabled(False)
previousBtn.setShortcut(Qt.Key.Key_Right)
previousBtn.clicked.connect(self.on_Previous)
previousBtn.setFont(font)
nextBtn = QPushButton("next")
nextBtn.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
nextBtn.setToolTip("Proceed to next window (left-arrow)")
nextBtn.setEnabled(False)
nextBtn.clicked.connect(self.on_Next)
nextBtn.setShortcut(Qt.Key.Key_Left)
nextBtn.setFont(font)
assignOneBtn = QPushButton("Track One")
assignOneBtn.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
assignOneBtn.setStyleSheet("QPushButton { background-color: orange; }")
assignOneBtn.setShortcut("Ctrl+1")
assignOneBtn.setToolTip("Assign current selection to Track One (Ctrl+1)")
assignOneBtn.setFont(font)
assignOneBtn.clicked.connect(self.on_TrackOne)
assignTwoBtn = QPushButton("Track Two")
assignTwoBtn.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
assignTwoBtn.setStyleSheet("QPushButton { background-color: green; }")
assignTwoBtn.setToolTip("Assign current selection to Track Two (Ctrl+2)")
assignTwoBtn.setFont(font)
assignTwoBtn.setShortcut("Ctrl+2")
assignTwoBtn.clicked.connect(self.on_TrackTwo)
assignOtherBtn = QPushButton("Other")
assignOtherBtn.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
assignOtherBtn.setStyleSheet("QPushButton { background-color: red; }")
assignOtherBtn.setToolTip("Assign current selection to Unassigned (Ctrl+0)")
assignOtherBtn.setFont(font)
assignOtherBtn.setShortcut("Ctrl+0")
assignOtherBtn.clicked.connect(self.on_TrackOther)
grid = QGridLayout()
grid.addWidget(previousBtn, 0, 0, 4, 2)
grid.addWidget(QLabel("Current selection:"), 0, 2, 1, 4)
grid.addWidget(QLabel("Track One:"), 1, 2, 1, 4)
grid.addWidget(QLabel("Track Two:"), 2, 2, 1, 4)
grid.addWidget(QLabel("Unassigned:"), 3, 2, 1, 4)
grid.addWidget(nextBtn, 0, 5, 4, 2)
grid.addWidget(assignOneBtn, 4, 0, 4, 3)
grid.addWidget(assignOtherBtn, 4, 3, 4, 2)
grid.addWidget(assignTwoBtn, 4, 5, 4, 3)
self.setLayout(grid)
self.setMaximumSize(QSize(400, 200))
def on_Next(self):
self.next.emit()
def on_Previous(self):
self.previous.emit()
def on_TrackOne(self):
self.assignOne.emit()
def on_TrackTwo(self):
self.assignTwo.emit()
def on_TrackOther(self):
self.assignOther.emit()
def setSelection(self, selection):
pass
class FixTracks(QWidget): class FixTracks(QWidget):
back = Signal() back = Signal()
@ -120,6 +207,8 @@ class FixTracks(QWidget):
timelinebox.addWidget(QLabel("Window")) timelinebox.addWidget(QLabel("Window"))
timelinebox.addWidget(self._windowspinner) timelinebox.addWidget(self._windowspinner)
# self._controls_widget = SelectionControls()
self._trackone_table = QTableView() self._trackone_table = QTableView()
font = QFont() font = QFont()
font.setBold(True) font.setBold(True)
@ -141,7 +230,7 @@ class FixTracks(QWidget):
track1_box = QVBoxLayout() track1_box = QVBoxLayout()
track1_box.addWidget(trackone_label) track1_box.addWidget(trackone_label)
track1_box.addWidget(self._trackone_table) track1_box.addWidget(self._trackone_table)
tracktwo_label = QLabel("Track 2") tracktwo_label = QLabel("Track 2")
tracktwo_label.setStyleSheet("QLabel { color : green; }") tracktwo_label.setStyleSheet("QLabel { color : green; }")
tracktwo_box = QVBoxLayout() tracktwo_box = QVBoxLayout()
@ -207,6 +296,7 @@ class FixTracks(QWidget):
layout.addWidget(splitter) layout.addWidget(splitter)
self.setLayout(layout) self.setLayout(layout)
def on_dataSelection(self): def on_dataSelection(self):
filename = self._data_combo.currentText() filename = self._data_combo.currentText()
if "please select" in filename.lower(): if "please select" in filename.lower():
@ -290,8 +380,8 @@ class FixTracks(QWidget):
self._data_combo.addItems(self.fileList) self._data_combo.addItems(self.fileList)
self._data_combo.setCurrentIndex(0) self._data_combo.setCurrentIndex(0)
self._data_combo.currentIndexChanged.connect(self.on_rightDataSelection) # self._data_combo.currentIndexChanged.connect(self.on_dataSelection)
self._image_combo.currentIndexChanged.connect(self.on_rightvideoSelection) # self._image_combo.currentIndexChanged.connect(self.on_imageSelection)
def _on_dataOpenend(self, state): def _on_dataOpenend(self, state):
logging.info("Finished loading data with state %s", state) logging.info("Finished loading data with state %s", state)
@ -340,9 +430,10 @@ class FixTracks(QWidget):
self._timeline.setWindowWidth(value) self._timeline.setWindowWidth(value)
def on_detectionsSelected(self, detections): def on_detectionsSelected(self, detections):
logging.debug("Tracks: Detections selected")
selection_model = self._unassigned_table.selectionModel() selection_model = self._unassigned_table.selectionModel()
selection = selection_model.selection() selection = selection_model.selection()
logging.debug("Tracks: Get selection model")
for d in detections: for d in detections:
id = d.data(1) id = d.data(1)
row = self._unassignedmodel.mapIdToRow(id) row = self._unassignedmodel.mapIdToRow(id)
@ -350,6 +441,23 @@ class FixTracks(QWidget):
continue continue
index = self._unassigned_table.model().index(row, 0) index = self._unassigned_table.model().index(row, 0)
selection.select(index, index) selection.select(index, index)
logging.debug("Tracks: Detections selected")
mode = QItemSelectionModel.Select | QItemSelectionModel.Rows mode = QItemSelectionModel.Select | QItemSelectionModel.Rows
selection_model.select(selection, mode) selection_model.select(selection, mode)
def main():
from PySide6.QtWidgets import QApplication
app = QApplication([])
window = QWidget()
window.setMinimumSize(200, 200)
layout = QVBoxLayout()
controls = SelectionControls()
layout.addWidget(controls)
window.setLayout(layout)
window.show()
app.exec()
if __name__ == "__main__":
main()