Compare commits
	
		
			1 Commits
		
	
	
		
			47c1e6040a
			...
			review
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 02edb186bb | 
| @@ -19,6 +19,10 @@ class MainController: | |||||||
|         self.media_repo = MediaRepository() |         self.media_repo = MediaRepository() | ||||||
|         self.camera_manager = CameraManager() |         self.camera_manager = CameraManager() | ||||||
|  |  | ||||||
|  |         # --- State --- | ||||||
|  |         self.selected_color_name: str | None = None | ||||||
|  |         self._latest_pixmap: QPixmap | None = None | ||||||
|  |  | ||||||
|         # --- UI Widgets --- |         # --- UI Widgets --- | ||||||
|         self.color_list: ColorListWidget = view.color_list_widget |         self.color_list: ColorListWidget = view.color_list_widget | ||||||
|         self.thumbnail_list: ThumbnailListWidget = view.thumbnail_widget |         self.thumbnail_list: ThumbnailListWidget = view.thumbnail_widget | ||||||
| @@ -33,6 +37,9 @@ class MainController: | |||||||
|         self.db.connect() |         self.db.connect() | ||||||
|         self.media_repo.sync_media() |         self.media_repo.sync_media() | ||||||
|  |  | ||||||
|  |         # Disable button by default | ||||||
|  |         self.photo_button.setEnabled(False) | ||||||
|  |  | ||||||
|         # Initialize state machine |         # Initialize state machine | ||||||
|         self.state: CameraState = NoCamerasState() |         self.state: CameraState = NoCamerasState() | ||||||
|         self.state.enter_state(self) |         self.state.enter_state(self) | ||||||
| @@ -77,6 +84,9 @@ class MainController: | |||||||
|  |  | ||||||
|     @Slot(str) |     @Slot(str) | ||||||
|     def on_color_selected(self, color_name: str): |     def on_color_selected(self, color_name: str): | ||||||
|  |         self.selected_color_name = color_name | ||||||
|  |         self.photo_button.setEnabled(True) | ||||||
|  |  | ||||||
|         color_id = self.db.get_color_id(color_name) |         color_id = self.db.get_color_id(color_name) | ||||||
|         if color_id is not None: |         if color_id is not None: | ||||||
|             media_items = self.db.get_media_for_color(color_id) |             media_items = self.db.get_media_for_color(color_id) | ||||||
| @@ -109,7 +119,8 @@ class MainController: | |||||||
|  |  | ||||||
|     @Slot(QPixmap) |     @Slot(QPixmap) | ||||||
|     def on_frame_ready(self, pixmap: QPixmap): |     def on_frame_ready(self, pixmap: QPixmap): | ||||||
|         """Displays a new frame from the camera.""" |         """Displays a new frame from the camera and stores it.""" | ||||||
|  |         self._latest_pixmap = pixmap | ||||||
|         self.split_view.set_live_image(pixmap) |         self.split_view.set_live_image(pixmap) | ||||||
|  |  | ||||||
|     @Slot(str) |     @Slot(str) | ||||||
| @@ -151,7 +162,6 @@ class MainController: | |||||||
|             self.on_camera_error("No cameras detected.") |             self.on_camera_error("No cameras detected.") | ||||||
|             return |             return | ||||||
|          |          | ||||||
|         # For now, just start the first detected camera. |  | ||||||
|         camera_id = detected_cameras[0]['id'] |         camera_id = detected_cameras[0]['id'] | ||||||
|         self.camera_manager.start_camera(camera_id) |         self.camera_manager.start_camera(camera_id) | ||||||
|  |  | ||||||
| @@ -161,7 +171,17 @@ class MainController: | |||||||
|  |  | ||||||
|     def take_photo(self): |     def take_photo(self): | ||||||
|         """Takes a photo with the active camera.""" |         """Takes a photo with the active camera.""" | ||||||
|         print("Taking photo...") # Placeholder |         if self.selected_color_name is None: | ||||||
|         # This needs to be implemented in CameraManager and called here. |             print("Cannot take photo: No color selected.") | ||||||
|         # e.g., self.camera_manager.take_photo() |             # Optionally: show a message to the user in the UI | ||||||
|         self.split_view.toggle_live_view() # This seems like a UI toggle, maybe rename? |             return | ||||||
|  |  | ||||||
|  |         if self._latest_pixmap is None or self._latest_pixmap.isNull(): | ||||||
|  |             print("Cannot take photo: No frame available.") | ||||||
|  |             return | ||||||
|  |  | ||||||
|  |         print(f"Taking photo for color: {self.selected_color_name}") | ||||||
|  |         self.media_repo.save_photo(self._latest_pixmap, self.selected_color_name) | ||||||
|  |          | ||||||
|  |         # Refresh thumbnail list | ||||||
|  |         self.on_color_selected(self.selected_color_name) | ||||||
| @@ -1,5 +1,7 @@ | |||||||
| from pathlib import Path | from pathlib import Path | ||||||
| import shutil | import shutil | ||||||
|  | from datetime import datetime | ||||||
|  | from PySide6.QtGui import QPixmap | ||||||
| from core.database import db_manager | from core.database import db_manager | ||||||
|  |  | ||||||
| MEDIA_DIR = Path("media") | MEDIA_DIR = Path("media") | ||||||
| @@ -9,6 +11,31 @@ class MediaRepository: | |||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         self.db = db_manager |         self.db = db_manager | ||||||
|  |  | ||||||
|  |     def save_photo(self, pixmap: QPixmap, color_name: str): | ||||||
|  |         """Saves a pixmap to the media directory for the given color.""" | ||||||
|  |         color_id = self.db.get_color_id(color_name) | ||||||
|  |         if color_id is None: | ||||||
|  |             print(f"Error: Could not find color ID for {color_name}") | ||||||
|  |             return | ||||||
|  |  | ||||||
|  |         # Create directory if it doesn't exist | ||||||
|  |         color_dir = MEDIA_DIR / color_name | ||||||
|  |         color_dir.mkdir(parents=True, exist_ok=True) | ||||||
|  |  | ||||||
|  |         # Generate unique filename | ||||||
|  |         timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f") | ||||||
|  |         filename = f"photo_{timestamp}.jpg" | ||||||
|  |         file_path = color_dir / filename | ||||||
|  |  | ||||||
|  |         # Save the pixmap | ||||||
|  |         if not pixmap.save(str(file_path), "JPG", 95): | ||||||
|  |             print(f"Error: Failed to save pixmap to {file_path}") | ||||||
|  |             return | ||||||
|  |  | ||||||
|  |         # Add to database | ||||||
|  |         self.db.add_media(color_id, str(file_path), 'photo') | ||||||
|  |         print(f"Saved photo to {file_path}") | ||||||
|  |  | ||||||
|     def sync_media(self): |     def sync_media(self): | ||||||
|         disk_colors = {d.name for d in MEDIA_DIR.iterdir() if d.is_dir()} |         disk_colors = {d.name for d in MEDIA_DIR.iterdir() if d.is_dir()} | ||||||
|         db_colors = {c["name"] for c in self.db.get_all_colors()} |         db_colors = {c["name"] for c in self.db.get_all_colors()} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user