From 07c8905f470f7ae94f95bbf740f7ab130382dde0 Mon Sep 17 00:00:00 2001 From: webfarben Date: Thu, 26 Feb 2026 10:33:53 +0100 Subject: [PATCH] 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 --- gui_wxpython.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/gui_wxpython.py b/gui_wxpython.py index 6581338..7690298 100644 --- a/gui_wxpython.py +++ b/gui_wxpython.py @@ -19,6 +19,34 @@ from update_checker import check_for_updates, get_current_version 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): def __init__(self): 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 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) # Buttons für PDF-Verwaltung