From 3054eb8c0de880655a3a01bf4c2da154e6c3ab42 Mon Sep 17 00:00:00 2001 From: matin Date: Tue, 30 Sep 2025 15:13:08 +0200 Subject: save + load includes the launch date and duration. also, increased readability of the json output --- calendar_gui.py | 61 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 20 deletions(-) (limited to 'calendar_gui.py') diff --git a/calendar_gui.py b/calendar_gui.py index 75f77fb..8863b8e 100644 --- a/calendar_gui.py +++ b/calendar_gui.py @@ -13,7 +13,6 @@ from date_calculator import DateCalculator from prediction_controller import PredictionController from event_type_handler import EventTypeHandler from date_service import DateService -from file_service import FileService from config import EventConfig class EventDialog(QDialog): @@ -200,6 +199,8 @@ class CalendarManagerGUI(QMainWindow): load_action.triggered.connect(self.load_file) file_menu.addAction(load_action) + # Note: Saving/Loading now operate on complete prediction state + # Clear action clear_action = QAction('Einträge löschen', self) clear_action.setShortcut('Ctrl+N') @@ -408,38 +409,58 @@ class CalendarManagerGUI(QMainWindow): self.events_table.setCellWidget(i, 6, actions_widget) def save_file(self): - """Save calendar entries to a JSON file""" - file_path, _ = QFileDialog.getSaveFileName(self, "Einträge speichern", "", EventConfig.FILE_FILTER) + """Save the complete prediction state to a .prediction.json file""" + file_path, _ = QFileDialog.getSaveFileName( + self, + "Zustand speichern", + "", + "Prediction State (*.prediction.json)" + ) if not file_path: return - - # Ensure .json extension - file_path = FileService.ensure_json_extension(file_path) - self.calendar_manager.switch_file(file_path) - + try: - if self.calendar_manager.save_entries(): - QMessageBox.information(self, "Speichern erfolgreich", f"Einträge gespeichert in {self.calendar_manager.filename}") + if self.prediction_controller.save_complete_state(file_path): + target = file_path if file_path.endswith('.prediction.json') else file_path + '.prediction.json' + QMessageBox.information(self, "Speichern erfolgreich", f"Komplettzustand gespeichert in {target}") else: - QMessageBox.critical(self, "Error", "Failed to save calendar entries") + QMessageBox.critical(self, "Error", "Speichern des Komplettzustands fehlgeschlagen") except Exception as e: - QMessageBox.critical(self, "Error", f"Failed to save calendar: {str(e)}") + QMessageBox.critical(self, "Error", f"Fehler beim Speichern des Komplettzustands: {str(e)}") def load_file(self): - """Load calendar entries from a JSON file""" - file_path, _ = QFileDialog.getOpenFileName(self, "Einträge laden", "", EventConfig.FILE_FILTER) + """Load the complete prediction state from a .prediction.json file""" + file_path, _ = QFileDialog.getOpenFileName( + self, + "Zustand laden", + "", + "Prediction State (*.prediction.json)" + ) if not file_path: return - + try: - if self.calendar_manager.load_file(file_path): + success = self.prediction_controller.load_complete_state(file_path) + if success: + # Reflect restored parameters into UI + launch_dt = self.prediction_controller.get_launch_date() + duration = self.prediction_controller.get_duration() + if launch_dt: + self.launch_date_edit.setDate(launch_dt) + if duration is not None and hasattr(duration, 'years'): + self.duration_spin.setValue(max(1, duration.years)) + + # Update views self.update_events_table() - self.update_prediction() # Auto-update prediction - QMessageBox.information(self, "Laden erfolgreich", f"Einträge erfolgreich von {file_path} geladen") + prediction_date = self.prediction_controller.get_prediction() + if prediction_date: + self.prediction_result.setDate(prediction_date) + QMessageBox.information(self, "Laden erfolgreich", f"Komplettzustand von {file_path} geladen") else: - QMessageBox.warning(self, "Warning", "No entries loaded from file") + QMessageBox.warning(self, "Warnung", "Komplettzustand konnte nicht geladen werden") except Exception as e: - QMessageBox.critical(self, "Error", f"Failed to load calendar: {str(e)}") + QMessageBox.critical(self, "Error", f"Fehler beim Laden des Komplettzustands: {str(e)}") + def clear_entries(self): """Clear all calendar entries""" -- cgit v1.1