fix(main.py): release video capture before moving files to prevent errors
This commit is contained in:
11
main.py
11
main.py
@@ -92,6 +92,7 @@ class MediaGrader:
|
||||
for file in media_files:
|
||||
# Check if file is not in a grade directory (1-5)
|
||||
if not any(part in ["1", "2", "3", "4", "5"] for part in file.parts):
|
||||
print("Adding file: ", file)
|
||||
filtered_files.append(file)
|
||||
|
||||
return sorted(filtered_files)
|
||||
@@ -375,6 +376,11 @@ class MediaGrader:
|
||||
# Track this move for undo functionality BEFORE making changes
|
||||
self.undo_history.append((str(destination), str(current_file), self.current_index))
|
||||
|
||||
# Release video capture to unlock the file before moving
|
||||
if self.current_cap:
|
||||
self.current_cap.release()
|
||||
self.current_cap = None
|
||||
|
||||
try:
|
||||
shutil.move(str(current_file), str(destination))
|
||||
print(f"Moved {current_file.name} to grade {grade}")
|
||||
@@ -404,6 +410,11 @@ class MediaGrader:
|
||||
# Get the last action
|
||||
moved_file_path, original_file_path, original_index = self.undo_history.pop()
|
||||
|
||||
# Release video capture to unlock any current file before moving
|
||||
if self.current_cap:
|
||||
self.current_cap.release()
|
||||
self.current_cap = None
|
||||
|
||||
try:
|
||||
# Move the file back to its original location
|
||||
shutil.move(moved_file_path, original_file_path)
|
||||
|
Reference in New Issue
Block a user