Refactor template navigation methods in VideoEditor for improved functionality

This commit renames and updates the template navigation methods in the VideoEditor to enhance user experience. The methods now allow users to jump directly to the previous or next template markers, improving frame handling and feedback. Debug messages have been added to provide clearer insights during navigation, ensuring users are informed about the current actions and template positions.
This commit is contained in:
2025-09-26 17:39:02 +02:00
parent b9c60ffc25
commit f5b8656bc2

View File

@@ -2533,65 +2533,44 @@ class VideoEditor:
print(f"Error recreating template {template_id}: {e}")
return False
def navigate_to_next_template(self):
"""Navigate to next template (: key) - jump to template's start frame"""
if not self.templates:
def jump_to_previous_template(self):
"""Jump to the previous template marker (frame where template was created)."""
if self.is_image_mode:
return
template_ids = sorted(self.templates.keys())
if self.current_template_id is None:
# Find first template
if template_ids:
template_id = template_ids[0]
start_frame = self.templates[template_id]['start_frame']
self.current_frame = start_frame
self.current_template_id = template_id
self._select_best_template_for_frame(self.current_frame)
self.show_feedback_message(f"Template {template_id} (frame {start_frame})")
self.stop_auto_repeat_seek()
template_frames = sorted([data['start_frame'] for data in self.templates.values()])
if not template_frames:
print("DEBUG: No template markers; prev jump ignored")
return
current = self.current_frame
candidates = [f for f in template_frames if f < current]
if candidates:
target = candidates[-1]
print(f"DEBUG: Jump prev template from {current} -> {target}; template_frames={template_frames}")
self.seek_to_frame(target)
else:
# Find next template
current_idx = template_ids.index(self.current_template_id)
if current_idx + 1 < len(template_ids):
template_id = template_ids[current_idx + 1]
start_frame = self.templates[template_id]['start_frame']
self.current_frame = start_frame
self.current_template_id = template_id
self._select_best_template_for_frame(self.current_frame)
self.show_feedback_message(f"Template {template_id} (frame {start_frame})")
return
target = template_frames[0]
print(f"DEBUG: Jump prev template to first marker from {current} -> {target}; template_frames={template_frames}")
self.seek_to_frame(target)
self.show_feedback_message("No next template found")
def navigate_to_previous_template(self):
"""Navigate to previous template (; key) - jump to template's start frame"""
if not self.templates:
def jump_to_next_template(self):
"""Jump to the next template marker (frame where template was created)."""
if self.is_image_mode:
return
template_ids = sorted(self.templates.keys())
if self.current_template_id is None:
# Find last template
if template_ids:
template_id = template_ids[-1]
start_frame = self.templates[template_id]['start_frame']
self.current_frame = start_frame
self.current_template_id = template_id
self._select_best_template_for_frame(self.current_frame)
self.show_feedback_message(f"Template {template_id} (frame {start_frame})")
self.stop_auto_repeat_seek()
template_frames = sorted([data['start_frame'] for data in self.templates.values()])
if not template_frames:
print("DEBUG: No template markers; next jump ignored")
return
else:
# Find previous template
current_idx = template_ids.index(self.current_template_id)
if current_idx - 1 >= 0:
template_id = template_ids[current_idx - 1]
start_frame = self.templates[template_id]['start_frame']
self.current_frame = start_frame
self.current_template_id = template_id
self._select_best_template_for_frame(self.current_frame)
self.show_feedback_message(f"Template {template_id} (frame {start_frame})")
current = self.current_frame
for f in template_frames:
if f > current:
print(f"DEBUG: Jump next template from {current} -> {f}; template_frames={template_frames}")
self.seek_to_frame(f)
return
self.show_feedback_message("No previous template found")
target = template_frames[-1]
print(f"DEBUG: Jump next template to last marker from {current} -> {target}; template_frames={template_frames}")
self.seek_to_frame(target)
def apply_rotation(self, frame):
"""Apply rotation to frame"""
@@ -4784,10 +4763,10 @@ class VideoEditor:
print(f"DEBUG: Multi-scale template matching toggled to {self.multi_scale_template_matching}")
self.show_feedback_message(f"Multi-scale template matching {'ON' if self.multi_scale_template_matching else 'OFF'}")
self.save_state()
elif key == ord(";"): # Semicolon - Navigate to previous template
self.navigate_to_previous_template()
elif key == ord(":"): # Colon - Navigate to next template
self.navigate_to_next_template()
elif key == ord(";"): # Semicolon - Jump to previous template marker
self.jump_to_previous_template()
elif key == ord(":"): # Colon - Jump to next template marker
self.jump_to_next_template()
elif key == ord("t"):
# Marker looping only for videos
if not self.is_image_mode: