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