feat: Add Drag & Drop support to wxPython GUI

- Implement FileDropTarget class for native file drop handling
- Enable drag and drop for PDF files in the ListBox
- Filter to accept only PDF files with proper validation
- Add user feedback messages when files are dropped
- Store directory of dropped files for next file dialog
This commit is contained in:
2026-02-26 10:33:53 +01:00
parent e692983a02
commit 07c8905f47

View File

@@ -19,6 +19,34 @@ from update_checker import check_for_updates, get_current_version
CONFIG_FILE = Path.home() / '.pdf_to_ics_config.json' CONFIG_FILE = Path.home() / '.pdf_to_ics_config.json'
class FileDropTarget(wx.FileDropTarget):
"""Custom FileDropTarget für Drag & Drop von PDF-Dateien"""
def __init__(self, window):
wx.FileDropTarget.__init__(self)
self.window = window
def OnDropFiles(self, x, y, filenames):
"""Handle für Drag & Drop Events"""
pdf_count = 0
for filepath in filenames:
# Nur PDF-Dateien akzeptieren
if filepath.lower().endswith('.pdf'):
if filepath not in self.window.pdf_files:
self.window.pdf_files.append(filepath)
self.window.pdf_listbox.Append(Path(filepath).name)
pdf_count += 1
# Merke Verzeichnis
self.window.last_pdf_dir = str(Path(filepath).parent)
if pdf_count > 0:
self.window.log(f"{pdf_count} PDF-Datei(en) per Drag & Drop hinzugefügt")
elif filenames:
self.window.log("⚠ Nur PDF-Dateien können hinzugefügt werden")
return True
class PDFtoICSFrame(wx.Frame): class PDFtoICSFrame(wx.Frame):
def __init__(self): def __init__(self):
super().__init__(parent=None, title='PDF zu ICS Konverter - Dienstplan Importer', size=(800, 700)) super().__init__(parent=None, title='PDF zu ICS Konverter - Dienstplan Importer', size=(800, 700))
@@ -130,6 +158,8 @@ class PDFtoICSFrame(wx.Frame):
# ListBox für PDFs # ListBox für PDFs
self.pdf_listbox = wx.ListBox(panel, style=wx.LB_EXTENDED) self.pdf_listbox = wx.ListBox(panel, style=wx.LB_EXTENDED)
# Richte Drag & Drop ein
self.pdf_listbox.SetDropTarget(FileDropTarget(self))
content_sizer.Add(self.pdf_listbox, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 10) content_sizer.Add(self.pdf_listbox, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
# Buttons für PDF-Verwaltung # Buttons für PDF-Verwaltung