refactor(main.py): update last seek time on key press to prevent auto-repeat timeout and handle different key presses

This commit is contained in:
2025-09-07 22:50:48 +02:00
parent 161b221992
commit 7f08f38457

View File

@@ -525,6 +525,8 @@ class VideoEditor:
self.auto_repeat_direction == direction and self.auto_repeat_direction == direction and
self.auto_repeat_shift == shift_pressed and self.auto_repeat_shift == shift_pressed and
self.auto_repeat_ctrl == ctrl_pressed): self.auto_repeat_ctrl == ctrl_pressed):
# Just update the last seek time to prevent timeout
self.last_seek_time = time.time()
return return
self.auto_repeat_active = True self.auto_repeat_active = True
@@ -533,7 +535,7 @@ class VideoEditor:
self.auto_repeat_shift = shift_pressed self.auto_repeat_shift = shift_pressed
self.auto_repeat_ctrl = ctrl_pressed self.auto_repeat_ctrl = ctrl_pressed
self.key_first_press_time = time.time() self.key_first_press_time = time.time()
self.last_seek_time = 0 self.last_seek_time = time.time() # Initialize to current time
# Do initial seek immediately # Do initial seek immediately
self.seek_video_with_modifier(direction, shift_pressed, ctrl_pressed) self.seek_video_with_modifier(direction, shift_pressed, ctrl_pressed)
@@ -1816,14 +1818,17 @@ class VideoEditor:
delay = self.calculate_frame_delay() if self.is_playing else 30 delay = self.calculate_frame_delay() if self.is_playing else 30
key = cv2.waitKey(delay) & 0xFF key = cv2.waitKey(delay) & 0xFF
# Handle auto-repeat timeout - only stop if no key is pressed for a longer period # Handle auto-repeat - stop if a different key is pressed or no key for too long
if key == 255 and self.auto_repeat_active: # 255 means no key pressed if key == 255 and self.auto_repeat_active: # 255 means no key pressed
# Check if enough time has passed since last key press # Check if enough time has passed since last key press
if time.time() - self.last_seek_time > 0.3: # 300ms timeout (increased) if time.time() - self.last_seek_time > 1.0: # 1 second timeout
self.stop_auto_repeat_seek() self.stop_auto_repeat_seek()
elif key != 255 and self.auto_repeat_active: elif key != 255 and self.auto_repeat_active:
# A key is pressed, update the last seek time to prevent timeout # A key is pressed, update the last seek time to prevent timeout
self.last_seek_time = time.time() self.last_seek_time = time.time()
# If it's a different key, stop auto-repeat
if key != self.auto_repeat_key:
self.stop_auto_repeat_seek()
# Get modifier key states # Get modifier key states
window_title = "Image Editor" if self.is_image_mode else "Video Editor" window_title = "Image Editor" if self.is_image_mode else "Video Editor"