[tracks] support new buttons
This commit is contained in:
parent
dbd5b380ba
commit
33b46af8d0
@ -14,166 +14,7 @@ from fixtracks.widgets.detectionview import DetectionView, DetectionData
|
||||
from fixtracks.widgets.detectiontimeline import DetectionTimeline
|
||||
from fixtracks.widgets.skeleton import SkeletonWidget
|
||||
from fixtracks.widgets.classifier import ClassifierWidget
|
||||
|
||||
|
||||
class SelectionControls(QWidget):
|
||||
fwd = Signal(float)
|
||||
back = Signal(float)
|
||||
assignOne = Signal()
|
||||
assignTwo = Signal()
|
||||
assignOther = Signal()
|
||||
|
||||
def __init__(self, parent = None,):
|
||||
super().__init__(parent)
|
||||
font = QFont()
|
||||
font.setBold(True)
|
||||
font.setPointSize(10)
|
||||
fullstep = 1.0
|
||||
halfstep = 0.5
|
||||
quarterstep = 0.25
|
||||
|
||||
backBtn = QPushButton("|<<")
|
||||
backBtn.setFont(font)
|
||||
backBtn.setShortcut(Qt.Key.Key_Left)
|
||||
backBtn.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||
backBtn.setToolTip(f"Go back to previous window ({backBtn.shortcut().toString()})")
|
||||
backBtn.clicked.connect(lambda: self.on_Back(fullstep))
|
||||
halfstepBackBtn = QPushButton("<<")
|
||||
halfstepBackBtn.setFont(font)
|
||||
halfstepBackBtn.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||
halfstepBackBtn.setShortcut(Qt.KeyboardModifier.AltModifier | Qt.Key.Key_Left)
|
||||
halfstepBackBtn.setToolTip(f"Go back by half a window ({halfstepBackBtn.shortcut().toString()})")
|
||||
halfstepBackBtn.clicked.connect(lambda: self.on_Back(halfstep))
|
||||
quarterstepBackBtn = QPushButton("<")
|
||||
quarterstepBackBtn.setFont(font)
|
||||
quarterstepBackBtn.setShortcut(Qt.KeyboardModifier.ShiftModifier | Qt.Key.Key_Left)
|
||||
quarterstepBackBtn.setToolTip(f"Go back by a quarter window ({quarterstepBackBtn.shortcut().toString()})")
|
||||
quarterstepBackBtn.clicked.connect(lambda: self.on_Back(quarterstep))
|
||||
|
||||
fwdBtn = QPushButton(">>|")
|
||||
fwdBtn.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||
fwdBtn.setShortcut(Qt.Key.Key_Right)
|
||||
fwdBtn.setFont(font)
|
||||
fwdBtn.setToolTip(f"Proceed to next window ({fwdBtn.shortcut().toString()})")
|
||||
fwdBtn.clicked.connect(lambda: self.on_Fwd(fullstep))
|
||||
halfstepFwdBtn = QPushButton(">>")
|
||||
halfstepFwdBtn.setFont(font)
|
||||
halfstepFwdBtn.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||
halfstepFwdBtn.setShortcut(Qt.KeyboardModifier.AltModifier | Qt.Key.Key_Right)
|
||||
halfstepFwdBtn.setToolTip(f"Proceed by half a window ({halfstepFwdBtn.shortcut().toString()})")
|
||||
halfstepFwdBtn.clicked.connect(lambda: self.on_Fwd(halfstep))
|
||||
quarterstepFwdBtn = QPushButton(">")
|
||||
quarterstepFwdBtn.setFont(font)
|
||||
quarterstepFwdBtn.setShortcut(Qt.KeyboardModifier.ShiftModifier | Qt.Key.Key_Right)
|
||||
quarterstepFwdBtn.setToolTip(f"Proceed by a quarter window ({quarterstepFwdBtn.shortcut().toString()})")
|
||||
quarterstepFwdBtn.clicked.connect(lambda: self.on_Fwd(quarterstep))
|
||||
|
||||
assignOneBtn = QPushButton("Track One")
|
||||
assignOneBtn.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||
assignOneBtn.setStyleSheet("QPushButton { background-color: orange; }")
|
||||
assignOneBtn.setShortcut("Ctrl+1")
|
||||
assignOneBtn.setToolTip(f"Assign current selection to Track One ({assignOneBtn.shortcut().toString()})")
|
||||
assignOneBtn.setFont(font)
|
||||
assignOneBtn.clicked.connect(self.on_TrackOne)
|
||||
|
||||
assignTwoBtn = QPushButton("Track Two")
|
||||
assignTwoBtn.setShortcut("Ctrl+2")
|
||||
assignTwoBtn.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||
assignTwoBtn.setStyleSheet("QPushButton { background-color: green; }")
|
||||
assignTwoBtn.setToolTip(f"Assign current selection to Track Two ({assignTwoBtn.shortcut().toString()})")
|
||||
assignTwoBtn.setFont(font)
|
||||
assignTwoBtn.clicked.connect(self.on_TrackTwo)
|
||||
|
||||
assignOtherBtn = QPushButton("Other")
|
||||
assignOtherBtn.setShortcut("Ctrl+0")
|
||||
assignOtherBtn.setFont(font)
|
||||
assignOtherBtn.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||
assignOtherBtn.setStyleSheet("QPushButton { background-color: red; }")
|
||||
assignOtherBtn.setToolTip(f"Assign current selection to Unassigned ({assignOtherBtn.shortcut().toString()})")
|
||||
assignOtherBtn.clicked.connect(self.on_TrackOther)
|
||||
|
||||
self.tone_selection = QLabel("0")
|
||||
self.ttwo_selection = QLabel("0")
|
||||
self.tother_selection = QLabel("0")
|
||||
self.startframe = QLabel("0")
|
||||
self.endframe = QLabel("0")
|
||||
self._total = 0
|
||||
|
||||
grid = QGridLayout()
|
||||
grid.addWidget(backBtn, 0, 0, 3, 2)
|
||||
grid.addWidget(halfstepBackBtn, 3, 0, 2, 2)
|
||||
grid.addWidget(quarterstepBackBtn, 5, 0, 2, 2)
|
||||
grid.addWidget(fwdBtn, 0, 6, 3, 2)
|
||||
grid.addWidget(halfstepFwdBtn, 3, 6, 2, 2)
|
||||
grid.addWidget(quarterstepFwdBtn, 5, 6, 2, 2)
|
||||
|
||||
grid.addWidget(QLabel("Current window:"), 0, 2, 1, 4)
|
||||
grid.addWidget(QLabel("start:"), 1, 3, 1, 1)
|
||||
grid.addWidget(self.startframe, 1, 4, 1, 2, Qt.AlignmentFlag.AlignRight)
|
||||
grid.addWidget(QLabel("end:"), 2, 3, 1, 1)
|
||||
grid.addWidget(self.endframe, 2, 4, 1, 2, Qt.AlignmentFlag.AlignRight)
|
||||
grid.addWidget(QLabel("Current selection:"), 3, 2, 1, 4)
|
||||
grid.addWidget(QLabel("Track One:"), 4, 3, 1, 2)
|
||||
grid.addWidget(self.tone_selection, 4, 5, 1, 1, Qt.AlignmentFlag.AlignRight)
|
||||
grid.addWidget(QLabel("Track Two:"), 5, 3, 1, 2)
|
||||
grid.addWidget(self.ttwo_selection, 5, 5, 1, 1, Qt.AlignmentFlag.AlignRight)
|
||||
grid.addWidget(QLabel("Unassigned:"), 6, 3, 1, 2)
|
||||
grid.addWidget(self.tother_selection, 6, 5, 1, 1, Qt.AlignmentFlag.AlignRight)
|
||||
|
||||
grid.addWidget(assignOneBtn, 7, 0, 4, 3)
|
||||
grid.addWidget(assignOtherBtn, 7, 3, 4, 2)
|
||||
grid.addWidget(assignTwoBtn, 7, 5, 4, 3)
|
||||
grid.setColumnStretch(0, 1)
|
||||
grid.setColumnStretch(7, 1)
|
||||
self.setLayout(grid)
|
||||
self.setMaximumSize(QSize(400, 200))
|
||||
|
||||
def setWindow(self, start:int=0, end:int=0):
|
||||
self.startframe.setText(f"{start:.0f}")
|
||||
self.endframe.setText(f"{end:g}")
|
||||
|
||||
def _updateNumbers(self, track):
|
||||
labels = {1: self.tone_selection, 2: self.ttwo_selection, 3: self.tother_selection}
|
||||
for k in labels:
|
||||
if k == track:
|
||||
labels[k].setText(str(self._total))
|
||||
else:
|
||||
labels[k].setText("0")
|
||||
|
||||
def on_Fwd(self, stepsize):
|
||||
logging.debug("SelectionControls: forward step by %.2f", stepsize)
|
||||
self.fwd.emit(stepsize)
|
||||
|
||||
def on_Back(self, stepsize):
|
||||
logging.debug("SelectionControls: backward step by %.2f", stepsize)
|
||||
self.back.emit(stepsize)
|
||||
|
||||
def on_TrackOne(self):
|
||||
self.assignOne.emit()
|
||||
self._updateNumbers(1)
|
||||
|
||||
def on_TrackTwo(self):
|
||||
self.assignTwo.emit()
|
||||
self._updateNumbers(2)
|
||||
|
||||
def on_TrackOther(self):
|
||||
self.assignOther.emit()
|
||||
self._updateNumbers(3)
|
||||
|
||||
def setSelectedTracks(self, tracks):
|
||||
logging.debug("SelectionControl: setSelectedTracks")
|
||||
if tracks is not None:
|
||||
tone = np.sum(tracks == 1)
|
||||
ttwo = np.sum(tracks == 2)
|
||||
else:
|
||||
tone = 0
|
||||
ttwo = 0
|
||||
|
||||
self.tone_selection.setText(str(tone))
|
||||
self.ttwo_selection.setText(str(ttwo))
|
||||
self.tother_selection.setText(str(len(tracks) - tone - ttwo if tracks is not None else 0))
|
||||
self._total = len(tracks) if tracks is not None else 0
|
||||
|
||||
from fixtracks.widgets.selection_control import SelectionControls
|
||||
|
||||
class FixTracks(QWidget):
|
||||
back = Signal()
|
||||
@ -239,6 +80,10 @@ class FixTracks(QWidget):
|
||||
self._controls_widget.assignOther.connect(self.on_assignOther)
|
||||
self._controls_widget.fwd.connect(self.on_forward)
|
||||
self._controls_widget.back.connect(self.on_backward)
|
||||
self._controls_widget.accept.connect(self.on_setUserFlag)
|
||||
self._controls_widget.unaccept.connect(self.on_unsetUserFlag)
|
||||
self._controls_widget.delete.connect(self.on_deleteDetection)
|
||||
self._controls_widget.revertall.connect(self.on_revertUserFlags)
|
||||
|
||||
self._saveBtn = QPushButton("Save")
|
||||
self._saveBtn.setShortcut("Ctrl+S")
|
||||
@ -446,12 +291,31 @@ class FixTracks(QWidget):
|
||||
|
||||
def on_assignOther(self):
|
||||
logging.debug("Assigning user selection to track Other")
|
||||
self._data.assignUserSelection(self.trackother_id)
|
||||
self._data.assignUserSelection(self.trackother_id, False)
|
||||
self._timeline.setDetectionData(self._data.data)
|
||||
self.update()
|
||||
|
||||
def on_setUserFlag(self):
|
||||
self._data.setAssignmentStatus(True)
|
||||
self.update()
|
||||
|
||||
def on_unsetUserFlag(self):
|
||||
logging.debug("Tracks:unsetUserFlag")
|
||||
self._data.setAssignmentStatus(False)
|
||||
self.update()
|
||||
|
||||
def on_revertUserFlags(self):
|
||||
logging.debug("Tracks:revert ALL UserFlags")
|
||||
self._data.revertAssignmentStatus()
|
||||
self.update()
|
||||
|
||||
def on_deleteDetection(self):
|
||||
logging.debug("Tracks:delete detections")
|
||||
# self._data.deleteDetections()
|
||||
self.update()
|
||||
|
||||
def on_windowChanged(self):
|
||||
logging.info("Timeline reports window change ")
|
||||
logging.debug("Tracks:Timeline reports window change ")
|
||||
self._currentWindowPos = np.round(self._timeline.rangeStart * self._maxframes)
|
||||
self.update()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user