refactor(main.py): add state saving on crop and marker changes to ensure consistent state management

This commit is contained in:
2025-09-08 00:30:21 +02:00
parent 4651ba51f1
commit 0dbf82f76b

View File

@@ -206,11 +206,11 @@ class VideoEditor:
# Restore state values
if 'current_frame' in state:
self.current_frame = state['current_frame']
if 'crop_rect' in state and state['crop_rect']:
if 'crop_rect' in state and state['crop_rect'] is not None:
self.crop_rect = tuple(state['crop_rect'])
if 'zoom_factor' in state:
self.zoom_factor = state['zoom_factor']
if 'zoom_center' in state and state['zoom_center']:
if 'zoom_center' in state and state['zoom_center'] is not None:
self.zoom_center = tuple(state['zoom_center'])
if 'rotation_angle' in state:
self.rotation_angle = state['rotation_angle']
@@ -1373,6 +1373,7 @@ class VideoEditor:
if self.crop_rect:
self.crop_history.append(self.crop_rect)
self.crop_rect = (original_x, original_y, original_w, original_h)
self.save_state() # Save state when crop is set
def seek_to_timeline_position(self, mouse_x, bar_x_start, bar_width):
"""Seek to position based on mouse click on timeline"""
@@ -1387,6 +1388,7 @@ class VideoEditor:
self.crop_rect = self.crop_history.pop()
else:
self.crop_rect = None
self.save_state() # Save state when crop is undone
def toggle_marker_looping(self):
"""Toggle looping between cut markers"""
@@ -1407,7 +1409,8 @@ class VideoEditor:
self.seek_to_frame(self.cut_start_frame)
else:
print("Marker looping DISABLED")
self.save_state() # Save state when looping is toggled
return True
@@ -1481,6 +1484,8 @@ class VideoEditor:
new_x = x + amount
new_w = w - amount
self.crop_rect = (new_x, y, new_w, h)
self.save_state() # Save state when crop is adjusted
def render_video(self, output_path: str):
"""Render video or save image with current edits applied"""
@@ -1965,16 +1970,19 @@ class VideoEditor:
if self.crop_rect:
self.crop_history.append(self.crop_rect)
self.crop_rect = None
self.save_state() # Save state when crop is cleared
elif key == ord("1"):
# Cut markers only for videos
if not self.is_image_mode:
self.cut_start_frame = self.current_frame
print(f"Set cut start at frame {self.current_frame}")
self.save_state() # Save state when cut start is set
elif key == ord("2"):
# Cut markers only for videos
if not self.is_image_mode:
self.cut_end_frame = self.current_frame
print(f"Set cut end at frame {self.current_frame}")
self.save_state() # Save state when cut end is set
elif key == ord("N"):
if len(self.video_files) > 1:
self.previous_video()