summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--calendar_gui.py204
2 files changed, 108 insertions, 97 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ed8ebf5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+__pycache__ \ No newline at end of file
diff --git a/calendar_gui.py b/calendar_gui.py
index 8102a36..7aeb159 100644
--- a/calendar_gui.py
+++ b/calendar_gui.py
@@ -3,125 +3,81 @@ from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QH
QLabel, QLineEdit, QPushButton, QDateEdit, QTableWidget,
QTableWidgetItem, QHeaderView, QDialog, QFormLayout, QComboBox,
QMessageBox, QSpinBox, QAction, QFileDialog, QMenuBar)
-from PyQt5.QtCore import Qt, QDate
-from PyQt5.QtGui import QFont
+from PyQt5.QtCore import Qt, QDate, QLocale
+from PyQt5.QtGui import QFont, QFontDatabase
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from calendar_manager import CalendarManager
from date_calculator import DateCalculator
from prediction_controller import PredictionController
-class AddEventDialog(QDialog):
- def __init__(self, keyword_list, parent=None):
+class EventDialog(QDialog):
+ def __init__(self, keyword_list, entry=None, parent=None):
super().__init__(parent)
- self.setWindowTitle("Neuer Eintrag")
+
self.keyword_list = keyword_list
+ self.entry = entry
+
+ # Set title based on mode
+ self.setWindowTitle("Neuer Eintrag" if not entry else "Eintrag editieren")
self.init_ui()
def init_ui(self):
layout = QFormLayout()
+ # Apply Arial font
+ font = QFont("Arial", 12)
+ self.setFont(font)
+
# Start date selector
self.start_date = QDateEdit()
self.start_date.setCalendarPopup(True)
- self.start_date.setDate(QDate.currentDate())
- layout.addRow("Startdatum:", self.start_date)
-
- # End date selector
- self.end_date = QDateEdit()
- self.end_date.setCalendarPopup(True)
- self.end_date.setDate(QDate.currentDate().addDays(1))
- layout.addRow("Enddatum:", self.end_date)
-
- # Keyword selector
- self.keyword = QComboBox()
- self.keyword.addItems(self.keyword_list)
- self.keyword.currentTextChanged.connect(self.on_keyword_changed)
- layout.addRow("Art:", self.keyword)
-
- # Store layout for later access
- self.layout = layout
- self.end_date_row = 1 # Index of end date row in the form layout
- # Buttons
- button_layout = QHBoxLayout()
- self.save_button = QPushButton("Speichern")
- self.save_button.clicked.connect(self.accept)
- self.cancel_button = QPushButton("Abbrechen")
- self.cancel_button.clicked.connect(self.reject)
-
- button_layout.addWidget(self.save_button)
- button_layout.addWidget(self.cancel_button)
- layout.addRow("", button_layout)
-
- self.setLayout(layout)
-
- # Handle initial keyword selection
- self.on_keyword_changed(self.keyword.currentText())
-
- def on_keyword_changed(self, keyword):
- """Handle visibility of the end_date field based on keyword"""
- # Get the widgets from the form layout
- end_date_label = self.layout.itemAt(self.end_date_row, QFormLayout.LabelRole).widget()
- end_date_field = self.layout.itemAt(self.end_date_row, QFormLayout.FieldRole).widget()
-
- if keyword == "EZ pauschal":
- # Hide end date field for EZ pauschals since they have fixed 4-week duration
- end_date_label.setVisible(False)
- end_date_field.setVisible(False)
+ self.start_date.setFont(font)
+
+ # Set initial date based on mode
+ if self.entry:
+ entry_start = QDate(self.entry.start_date.year,
+ self.entry.start_date.month,
+ self.entry.start_date.day)
+ self.start_date.setDate(entry_start)
else:
- # Show end date field for other event types
- end_date_label.setVisible(True)
- end_date_field.setVisible(True)
- def get_data(self):
- start_date = self.start_date.date().toString("yyyy-MM-dd")
- keyword = self.keyword.currentText()
-
- if keyword == "EZ pauschal":
- # For EZ pauschals, calculate end date as start + 4 weeks
- start_dt = datetime.fromisoformat(start_date)
- end_dt = start_dt + relativedelta(years = 2, days = -1)
- 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
-
-
-class ModifyEventDialog(QDialog):
- def __init__(self, entry, keyword_list, parent=None):
- super().__init__(parent)
- self.setWindowTitle("Eintrag editieren")
- self.entry = entry
- self.keyword_list = keyword_list
- self.init_ui()
+ self.start_date.setDate(QDate.currentDate())
+
- def init_ui(self):
- layout = QFormLayout()
+ # Connect start date change to validate end date
+ self.start_date.dateChanged.connect(self.validate_end_date)
- # Start date selector
- self.start_date = QDateEdit()
- self.start_date.setCalendarPopup(True)
- entry_start = QDate(self.entry.start_date.year,
- self.entry.start_date.month,
- self.entry.start_date.day)
- self.start_date.setDate(entry_start)
layout.addRow("Startdatum:", self.start_date)
# End date selector
self.end_date = QDateEdit()
self.end_date.setCalendarPopup(True)
- entry_end = QDate(self.entry.end_date.year,
- self.entry.end_date.month,
- self.entry.end_date.day)
- self.end_date.setDate(entry_end)
+ self.end_date.setFont(font)
+
+ # Set initial date based on mode
+ if self.entry:
+ entry_end = QDate(self.entry.end_date.year,
+ self.entry.end_date.month,
+ self.entry.end_date.day)
+ self.end_date.setDate(entry_end)
+ else:
+ self.end_date.setDate(QDate.currentDate().addDays(1))
+
layout.addRow("Enddatum:", self.end_date)
# Keyword selector
self.keyword = QComboBox()
+ self.keyword.setFont(font)
self.keyword.addItems(self.keyword_list)
- current_index = self.keyword_list.index(self.entry.keyword) if self.entry.keyword in self.keyword_list else 0
- self.keyword.setCurrentIndex(current_index)
+
+ # Set initial keyword based on mode
+ if self.entry and self.entry.keyword in self.keyword_list:
+ current_index = self.keyword_list.index(self.entry.keyword)
+ self.keyword.setCurrentIndex(current_index)
+
self.keyword.currentTextChanged.connect(self.on_keyword_changed)
layout.addRow("Art:", self.keyword)
+
# Store layout for later access
self.layout = layout
self.end_date_row = 1 # Index of end date row in the form layout
@@ -129,8 +85,11 @@ class ModifyEventDialog(QDialog):
# Buttons
button_layout = QHBoxLayout()
self.save_button = QPushButton("Speichern")
+ self.save_button.setFont(font)
self.save_button.clicked.connect(self.accept)
+
self.cancel_button = QPushButton("Abbrechen")
+ self.cancel_button.setFont(font)
self.cancel_button.clicked.connect(self.reject)
button_layout.addWidget(self.save_button)
@@ -161,6 +120,11 @@ class ModifyEventDialog(QDialog):
# Show end date field for other event types
end_date_label.setVisible(True)
end_date_field.setVisible(True)
+
+ def validate_end_date(self):
+ """Ensure end date is not before start date"""
+ if self.end_date.date() < self.start_date.date():
+ self.end_date.setDate(self.start_date.date())
def get_data(self):
start_date = self.start_date.date().toString("yyyy-MM-dd")
keyword = self.keyword.currentText()
@@ -181,6 +145,13 @@ class CalendarManagerGUI(QMainWindow):
self.setWindowTitle("Ausfallzeitenrechner")
self.setMinimumSize(800, 600)
+ # Set application font
+ self.app_font = QFont("Arial", 12)
+ QApplication.setFont(self.app_font)
+
+ # Get system locale for consistent date formatting
+ self.locale = QLocale.system()
+
# Initialize backend components
self.keyword_list = ["EZ 100%", "EZ 50%", "EZ pauschal", "Sonstige"]
self.calendar_manager = CalendarManager()
@@ -197,6 +168,7 @@ class CalendarManagerGUI(QMainWindow):
def create_menus(self):
# Create menu bar
menubar = self.menuBar()
+ menubar.setFont(self.app_font)
# File menu
file_menu = menubar.addMenu('File')
@@ -234,7 +206,9 @@ class CalendarManagerGUI(QMainWindow):
# Launch date input
launch_date_layout = QVBoxLayout()
launch_date_label = QLabel("Promotionsdatum:")
+ launch_date_label.setFont(self.app_font)
self.launch_date_edit = QDateEdit()
+ self.launch_date_edit.setFont(self.app_font)
self.launch_date_edit.setCalendarPopup(True) # Enable calendar popup
self.launch_date_edit.setDate(QDate.currentDate())
self.launch_date_edit.dateChanged.connect(self.update_prediction) # Auto-update on change
@@ -245,7 +219,9 @@ class CalendarManagerGUI(QMainWindow):
# Duration input
duration_layout = QVBoxLayout()
duration_label = QLabel("Bewerbungszeitraum (Jahre):")
+ duration_label.setFont(self.app_font)
self.duration_spin = QSpinBox()
+ self.duration_spin.setFont(self.app_font)
self.duration_spin.setRange(1, 99)
self.duration_spin.setValue(1)
self.duration_spin.valueChanged.connect(self.update_prediction) # Auto-update on change
@@ -256,7 +232,9 @@ class CalendarManagerGUI(QMainWindow):
# Prediction result
prediction_result_layout = QVBoxLayout()
prediction_result_label = QLabel("Bewerbungsfrist:")
+ prediction_result_label.setFont(self.app_font)
self.prediction_result = QDateEdit()
+ self.prediction_result.setFont(self.app_font)
self.prediction_result.setReadOnly(True)
self.prediction_result.setButtonSymbols(QDateEdit.ButtonSymbols.NoButtons)
prediction_result_layout.addWidget(prediction_result_label)
@@ -269,18 +247,22 @@ class CalendarManagerGUI(QMainWindow):
# Events section
events_layout = QVBoxLayout()
events_title = QLabel("<h3>Ausfallzeiten</h3>")
+ events_title.setFont(self.app_font)
events_layout.addWidget(events_title)
# Add event button
add_event_button = QPushButton("Eintrag hinzufügen")
+ add_event_button.setFont(self.app_font)
add_event_button.clicked.connect(self.add_event)
events_layout.addWidget(add_event_button)
# 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.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
+ self.events_table.horizontalHeader().setFont(self.app_font)
self.events_table.setColumnHidden(0, True) # Hide ID column
events_layout.addWidget(self.events_table)
@@ -314,7 +296,7 @@ class CalendarManagerGUI(QMainWindow):
print(f"Error calculating prediction: {str(e)}")
def add_event(self):
- dialog = AddEventDialog(self.keyword_list, self)
+ dialog = EventDialog(self.keyword_list, parent=self)
if dialog.exec_():
start_date, end_date, keyword = dialog.get_data()
try:
@@ -327,7 +309,7 @@ class CalendarManagerGUI(QMainWindow):
def modify_event(self, event_id):
entry = self.calendar_manager.get_entry_by_id(event_id)
if entry:
- dialog = ModifyEventDialog(entry, self.keyword_list, self)
+ dialog = EventDialog(self.keyword_list, entry=entry, parent=self)
if dialog.exec_():
start_date, end_date, keyword = dialog.get_data()
try:
@@ -363,15 +345,39 @@ class CalendarManagerGUI(QMainWindow):
# Set item data
self.events_table.setItem(i, 0, QTableWidgetItem(entry.id))
- self.events_table.setItem(i, 1, QTableWidgetItem(entry.start_date.strftime("%Y-%m-%d")))
- self.events_table.setItem(i, 2, QTableWidgetItem(entry.end_date.strftime("%Y-%m-%d")))
+
+ # Format dates using system locale for display
+ start_date_qdate = QDate(entry.start_date.year, entry.start_date.month, entry.start_date.day)
+ end_date_qdate = QDate(entry.end_date.year, entry.end_date.month, entry.end_date.day)
+
+ start_date_text = self.locale.toString(start_date_qdate, QLocale.ShortFormat)
+ end_date_text = self.locale.toString(end_date_qdate, QLocale.ShortFormat)
+ self.events_table.setItem(i, 1, QTableWidgetItem(start_date_text))
+ self.events_table.setItem(i, 2, QTableWidgetItem(end_date_text))
self.events_table.setItem(i, 3, QTableWidgetItem(entry.keyword))
- # Corrected dates
- corrected_start = entry.corrected_start_date.strftime("%Y-%m-%d") if entry.corrected_start_date else ""
- corrected_end = entry.corrected_end_date.strftime("%Y-%m-%d") if entry.corrected_end_date else ""
- self.events_table.setItem(i, 4, QTableWidgetItem(corrected_start))
- self.events_table.setItem(i, 5, QTableWidgetItem(corrected_end))
+ # Corrected dates with system locale formatting
+ 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 = self.locale.toString(corrected_start_qdate, QLocale.ShortFormat)
+ 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 = self.locale.toString(corrected_end_qdate, QLocale.ShortFormat)
+ else:
+ corrected_end_text = ""
+ self.events_table.setItem(i, 4, QTableWidgetItem(corrected_start_text))
+ self.events_table.setItem(i, 5, QTableWidgetItem(corrected_end_text))
# Action buttons
actions_widget = QWidget()
@@ -379,7 +385,9 @@ class CalendarManagerGUI(QMainWindow):
actions_layout.setContentsMargins(0, 0, 0, 0)
modify_button = QPushButton("Editieren")
+ modify_button.setFont(self.app_font)
delete_button = QPushButton("Löschen")
+ delete_button.setFont(self.app_font)
# Use lambda with default argument to capture the correct event_id
modify_button.clicked.connect(lambda checked, eid=entry.id: self.modify_event(eid))
@@ -437,6 +445,8 @@ class CalendarManagerGUI(QMainWindow):
def main():
app = QApplication(sys.argv)
app.setStyle('Fusion')
+ # Ensure Arial is available
+ QFontDatabase.addApplicationFont("Arial")
window = CalendarManagerGUI()
window.show()
sys.exit(app.exec_())