Save all points to JSON file
(self)
| 522 | self.all_points_by_frame[self.current_video_idx] = self.points_by_frame.copy() |
| 523 | |
| 524 | def save_points(self): |
| 525 | """Save all points to JSON file""" |
| 526 | if not self.config_path: |
| 527 | messagebox.showerror("Error", "No config loaded") |
| 528 | return |
| 529 | |
| 530 | # Save current video first |
| 531 | self.save_current_points() |
| 532 | |
| 533 | # Build output |
| 534 | output_videos = [] |
| 535 | for i, video_info in enumerate(self.videos): |
| 536 | video_data = video_info.copy() |
| 537 | |
| 538 | points_by_frame = self.all_points_by_frame[i] |
| 539 | |
| 540 | # Convert to serializable format (int keys → string keys for JSON) |
| 541 | video_data["primary_points_by_frame"] = { |
| 542 | str(frame_idx): points for frame_idx, points in points_by_frame.items() |
| 543 | } |
| 544 | |
| 545 | # Also save list of frames for easy access |
| 546 | video_data["primary_frames"] = sorted(points_by_frame.keys()) |
| 547 | |
| 548 | # Backwards compatibility: if only one frame, save as before |
| 549 | if len(points_by_frame) == 1: |
| 550 | frame_idx = list(points_by_frame.keys())[0] |
| 551 | video_data["first_appears_frame"] = frame_idx |
| 552 | video_data["primary_points"] = points_by_frame[frame_idx] |
| 553 | elif len(points_by_frame) > 1: |
| 554 | # Multiple frames - use first frame as "first_appears_frame" |
| 555 | video_data["first_appears_frame"] = min(points_by_frame.keys()) |
| 556 | # Flatten all points for backwards compat (not ideal but helps) |
| 557 | all_points = [] |
| 558 | for frame_idx in sorted(points_by_frame.keys()): |
| 559 | all_points.extend(points_by_frame[frame_idx]) |
| 560 | video_data["primary_points"] = all_points |
| 561 | |
| 562 | output_videos.append(video_data) |
| 563 | |
| 564 | # Match input format |
| 565 | if isinstance(self.config_data, list): |
| 566 | output_data = output_videos |
| 567 | else: |
| 568 | output_data = {"videos": output_videos} |
| 569 | |
| 570 | # Save |
| 571 | output_path = self.config_path.parent / f"{self.config_path.stem}_points.json" |
| 572 | |
| 573 | try: |
| 574 | with open(output_path, 'w') as f: |
| 575 | json.dump(output_data, f, indent=2) |
| 576 | |
| 577 | self.status_label.config(text=f"Saved to {output_path.name}", foreground="green") |
| 578 | messagebox.showinfo("Success", f"Points saved to:\n{output_path}") |
| 579 | except Exception as e: |
| 580 | messagebox.showerror("Error", f"Failed to save: {e}") |
| 581 |
nothing calls this directly
no test coverage detected