Skip to content

Commit

Permalink
Fix VideoSlider initialization and video loading flow
Browse files Browse the repository at this point in the history
- Properly remove the previous seekbar from the status bar before re-initializing it.
- Ensure the seekbar is fully set up after the video file is loaded, and update its properties accordingly.
- Moved frame loading and UI setup after seekbar initialization to ensure proper video processing and UI synchronization.
- Adjusted the threading and frame worker initialization to align with the new flow.
  • Loading branch information
healthonrails committed Dec 14, 2024
1 parent d47373a commit b97d77a
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions annolid/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2177,8 +2177,6 @@ def openVideo(self, _value=False,

video_filename = str(video_filename)
self.stepSizeWidget.setEnabled(True)
if self.seekbar:
self.statusBar().removeWidget(self.seekbar)

if video_filename:
cur_video_folder = Path(video_filename).parent
Expand All @@ -2200,37 +2198,21 @@ def openVideo(self, _value=False,
self.video_loader = None
return
self.fps = self.video_loader.get_fps()

self.num_frames = self.video_loader.total_frames()
if self.seekbar:
self.statusBar().removeWidget(self.seekbar)
self.seekbar = VideoSlider()
self.seekbar.input_value.returnPressed.connect(self.jump_to_frame)
self.seekbar.keyPress.connect(self.keyPressEvent)
self.seekbar.keyRelease.connect(self.keyReleaseEvent)
logger.info(f"Working on video:{self.video_file}.")
logger.info(
f"FPS: {self.fps}, Total number of frames: {self.num_frames}")
# load the first frame
self.set_frame_number(self.frame_number)

self.actions.openNextImg.setEnabled(True)

self.actions.openPrevImg.setEnabled(True)

self.seekbar.valueChanged.connect(lambda f: self.set_frame_number(
self.seekbar.value()
))

self.frame_loader.video_loader = self.video_loader

self.frame_loader.moveToThread(self.frame_worker)

self.frame_worker.start(priority=QtCore.QThread.IdlePriority)

self.frame_loader.res_frame.connect(
lambda qimage: self.image_to_canvas(
qimage, self.filename, self.frame_number)
)

self.seekbar.setMinimum(0)
self.seekbar.setMaximum(self.num_frames-1)
self.seekbar.setEnabled(True)
Expand All @@ -2248,6 +2230,24 @@ def openVideo(self, _value=False,
self.statusBar().addWidget(self.playButton)
self.statusBar().addWidget(self.seekbar, stretch=1)
self.statusBar().addWidget(self.saveButton)

# load the first frame
self.set_frame_number(self.frame_number)

self.actions.openNextImg.setEnabled(True)

self.actions.openPrevImg.setEnabled(True)

self.frame_loader.video_loader = self.video_loader

self.frame_loader.moveToThread(self.frame_worker)

self.frame_worker.start(priority=QtCore.QThread.IdlePriority)

self.frame_loader.res_frame.connect(
lambda qimage: self.image_to_canvas(
qimage, self.filename, self.frame_number)
)
# go over all the tracking csv files
# use the first matched file with video name
# and segmentation
Expand Down

0 comments on commit b97d77a

Please sign in to comment.