diff options
| author | matin <matin.kaufmann@gmail.com> | 2025-09-11 16:27:13 +0200 |
|---|---|---|
| committer | matin <matin.kaufmann@gmail.com> | 2025-09-11 16:27:13 +0200 |
| commit | c7fc1d523a80c2eddacadab97b195cbe60ff83e0 (patch) | |
| tree | 587d9d35f9fe95703324dfe58e03c6b7427244ef | |
| parent | 3489736a7ae2c2827452c0c23805becf41e1d2b9 (diff) | |
added commentary field. removed display of corrected start / end dates
| -rw-r--r-- | calendar_gui.py | 53 | ||||
| -rw-r--r-- | calendar_manager.py | 17 |
2 files changed, 33 insertions, 37 deletions
diff --git a/calendar_gui.py b/calendar_gui.py index 67ddaa2..9d89b7e 100644 --- a/calendar_gui.py +++ b/calendar_gui.py @@ -2,7 +2,7 @@ import sys from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton, QDateEdit, QTableWidget, QTableWidgetItem, QHeaderView, QDialog, QFormLayout, QComboBox, - QMessageBox, QSpinBox, QAction, QFileDialog, QMenuBar) + QMessageBox, QSpinBox, QAction, QFileDialog, QMenuBar, QTextEdit) from PyQt5.QtCore import Qt, QDate, QLocale from PyQt5.QtGui import QFont, QFontDatabase from datetime import datetime, timedelta @@ -83,6 +83,14 @@ class EventDialog(QDialog): self.keyword.currentTextChanged.connect(self.on_keyword_changed) layout.addRow("Art:", self.keyword) + # Commentary input + self.commentary_input = QTextEdit() + self.commentary_input.setFont(font) + self.commentary_input.setFixedHeight(80) + if self.entry and hasattr(self.entry, 'commentary') and self.entry.commentary: + self.commentary_input.setPlainText(self.entry.commentary) + layout.addRow("Kommentar:", self.commentary_input) + # Store layout for later access self.layout = layout self.end_date_row = 1 # Index of end date row in the form layout @@ -133,6 +141,7 @@ class EventDialog(QDialog): def get_data(self): start_date = self.start_date.date().toString("yyyy-MM-dd") keyword = self.keyword.currentText() + commentary = self.commentary_input.toPlainText().strip() if keyword == "EZ pauschal": # For EZ pauschals, calculate end date as start + 4 weeks @@ -141,7 +150,7 @@ class EventDialog(QDialog): end_date = end_dt.strftime("%Y-%m-%d") else: end_date = self.end_date.date().toString("yyyy-MM-dd") - return start_date, end_date, keyword + return start_date, end_date, keyword, commentary class CalendarManagerGUI(QMainWindow): @@ -267,8 +276,8 @@ class CalendarManagerGUI(QMainWindow): # Events table self.events_table = QTableWidget() self.events_table.setFont(self.app_font) - self.events_table.setColumnCount(7) # ID (hidden), Start, End, Keyword, CorrectedStart, CorrectedEnd, Actions - self.events_table.setHorizontalHeaderLabels(["ID", "Anfangsdatum", "Enddatum", "Art", "Korr. Start", "Korr. Ende", "Aktionen"]) + self.events_table.setColumnCount(6) # ID (hidden), Start, End, Keyword, Commentary, Actions + self.events_table.setHorizontalHeaderLabels(["ID", "Anfangsdatum", "Enddatum", "Art", "Kommentar", "Aktionen"]) self.events_table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.events_table.horizontalHeader().setFont(self.app_font) self.events_table.setColumnHidden(0, True) # Hide ID column @@ -306,9 +315,9 @@ class CalendarManagerGUI(QMainWindow): def add_event(self): dialog = EventDialog(self.keyword_list, parent=self, dateformat=self.dateformat) if dialog.exec_(): - start_date, end_date, keyword = dialog.get_data() + start_date, end_date, keyword, commentary = dialog.get_data() try: - self.calendar_manager.add_entry(start_date, end_date, keyword) + self.calendar_manager.add_entry(start_date, end_date, keyword, commentary) self.update_events_table() self.update_prediction() # Auto-update prediction except Exception as e: @@ -319,12 +328,13 @@ class CalendarManagerGUI(QMainWindow): if entry: dialog = EventDialog(self.keyword_list, entry=entry, parent=self, dateformat=self.dateformat) if dialog.exec_(): - start_date, end_date, keyword = dialog.get_data() + start_date, end_date, keyword, commentary = dialog.get_data() try: self.calendar_manager.modify_entry(event_id, datetime.fromisoformat(start_date), datetime.fromisoformat(end_date), - keyword) + keyword, + commentary) self.update_events_table() self.update_prediction() # Auto-update prediction except Exception as e: @@ -364,28 +374,9 @@ class CalendarManagerGUI(QMainWindow): self.events_table.setItem(i, 2, QTableWidgetItem(end_date_text)) self.events_table.setItem(i, 3, QTableWidgetItem(entry.keyword)) - # Corrected dates with unified display format - if entry.corrected_start_date: - corrected_start_qdate = QDate( - entry.corrected_start_date.year, - entry.corrected_start_date.month, - entry.corrected_start_date.day - ) - corrected_start_text = corrected_start_qdate.toString(self.dateformat) - else: - corrected_start_text = "" - - if entry.corrected_end_date: - corrected_end_qdate = QDate( - entry.corrected_end_date.year, - entry.corrected_end_date.month, - entry.corrected_end_date.day - ) - corrected_end_text = corrected_end_qdate.toString(self.dateformat) - else: - corrected_end_text = "" - self.events_table.setItem(i, 4, QTableWidgetItem(corrected_start_text)) - self.events_table.setItem(i, 5, QTableWidgetItem(corrected_end_text)) + # Commentary + commentary_text = getattr(entry, 'commentary', "") or "" + self.events_table.setItem(i, 4, QTableWidgetItem(commentary_text)) # Action buttons actions_widget = QWidget() @@ -405,7 +396,7 @@ class CalendarManagerGUI(QMainWindow): actions_layout.addWidget(delete_button) actions_widget.setLayout(actions_layout) - self.events_table.setCellWidget(i, 6, actions_widget) + self.events_table.setCellWidget(i, 5, actions_widget) def save_file(self): """Save calendar entries to a JSON file""" diff --git a/calendar_manager.py b/calendar_manager.py index b62cf5d..318eb83 100644 --- a/calendar_manager.py +++ b/calendar_manager.py @@ -4,7 +4,7 @@ import uuid from datetime import datetime class CalendarEntry: - def __init__(self, start_date, end_date, keyword, entry_id=None, corrected_start_date=None, corrected_end_date=None): + def __init__(self, start_date, end_date, keyword, entry_id=None, corrected_start_date=None, corrected_end_date=None, commentary: str = ""): self.id = entry_id if entry_id else str(uuid.uuid4()) # Convert string dates to datetime if necessary self.start_date = ( @@ -19,7 +19,8 @@ class CalendarEntry: ) self.keyword = keyword self.corrected_start_date = corrected_start_date - self.corrected_end_date = corrected_end_date + self.corrected_end_date = corrected_end_date + self.commentary = commentary def to_dict(self): return { 'id': self.id, @@ -27,7 +28,8 @@ class CalendarEntry: 'end_date': self.end_date.isoformat(), 'keyword': self.keyword, 'corrected_start_date': self.corrected_start_date.isoformat() if self.corrected_start_date else None, - 'corrected_end_date': self.corrected_end_date.isoformat() if self.corrected_end_date else None, + 'corrected_end_date': self.corrected_end_date.isoformat() if self.corrected_end_date else None, + 'commentary': self.commentary, } @classmethod @@ -39,6 +41,7 @@ class CalendarEntry: entry_id=data['id'], corrected_start_date=datetime.fromisoformat(data['corrected_start_date']) if data.get('corrected_start_date') else None, corrected_end_date=datetime.fromisoformat(data['corrected_end_date']) if data.get('corrected_end_date') else None, + commentary=data.get('commentary', ""), ) def __repr__(self): @@ -88,14 +91,14 @@ class CalendarManager: except Exception as e: print(f"Error writing to file {self.filename}: {e}") - def add_entry(self, start_date, end_date, keyword): + def add_entry(self, start_date, end_date, keyword, commentary: str = ""): """Add a new event to the calendar.""" - new_entry = CalendarEntry(start_date, end_date, keyword) + new_entry = CalendarEntry(start_date, end_date, keyword, commentary=commentary) self.entries.append(new_entry) self.save_entries() return new_entry - def modify_entry(self, entry_id, start_date=None, end_date=None, keyword=None): + def modify_entry(self, entry_id, start_date=None, end_date=None, keyword=None, commentary=None): """Modify an existing event by ID.""" entry = self.get_entry_by_id(entry_id) if entry: @@ -105,6 +108,8 @@ class CalendarManager: entry.end_date = end_date if keyword: entry.keyword = keyword + if commentary is not None: + entry.commentary = commentary self.save_entries() return entry return None |
