Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions deeplabcut/gui/tracklet_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
import matplotlib.transforms as mtransforms
import numpy as np
import pandas as pd
from threading import Event, Thread
from threading import Event
from deeplabcut.gui.utils import move_to_separate_thread
from deeplabcut.refine_training_dataset.tracklets import TrackletManager
from deeplabcut.utils.auxfun_videos import VideoReader
from deeplabcut.utils.auxiliaryfunctions import attempttomakefolder
from matplotlib.path import Path
from matplotlib.widgets import Slider, LassoSelector, Button, CheckButtons
from PySide6.QtWidgets import QMessageBox
from PySide6.QtCore import QMutex


class DraggablePoint:
Expand Down Expand Up @@ -203,10 +205,10 @@ def run(self):
i -= 1
else:
i -= 2 * (len(self.speed) - 1)
if i > self.viz.manager.nframes:
if i >= self.viz.manager.nframes:
i = 0
elif i < 0:
i = self.viz.manager.nframes
i = self.viz.manager.nframes - 1
self.viz.slider.set_val(i)

def pause(self):
Expand Down Expand Up @@ -248,6 +250,7 @@ def rewind(self):
self.resume()

def terminate(self, *args):
self.can_run.set()
self.running = False


Expand Down Expand Up @@ -318,8 +321,9 @@ def __init__(self, manager, videoname, trail_len=50):
self.picked_pair = []
self.cuts = []

self.mutex = QMutex()
self.player = BackgroundPlayer(self)
self.thread_player = Thread(target=self.player.run, daemon=True)
self.worker, self.thread_player = move_to_separate_thread(self.player.run)
self.thread_player.start()

self.dps = []
Expand Down Expand Up @@ -436,7 +440,7 @@ def _prepare_canvas(self, manager, fig):
self.lasso_toggle.on_clicked(self.selector.toggle)
self.display_traces(only_picked=False)
self.ax1_background = self.fig.canvas.copy_from_bbox(self.ax1.bbox)
plt.show()
self.fig.show()

def show(self, fig=None):
self._prepare_canvas(self.manager, fig)
Expand Down Expand Up @@ -785,9 +789,11 @@ def update_vlines(self, val):
self.vline_y.set_xdata([val, val])

def on_change(self, val):
self.mutex.lock() # Make video frame retrieval thread-safe
self.curr_frame = int(val)
self.video.set_to_frame(self.curr_frame)
img = self.video.read_frame()
self.mutex.unlock()
if img is not None:
# Automatically disable the draggable points
if self.draggable:
Expand Down