Enhanced file upload interface with better error handling
(self)
| 232 | return input().strip().lower() |
| 233 | |
| 234 | def upload_file_gui(self) -> Optional[str]: |
| 235 | """Enhanced file upload interface with better error handling""" |
| 236 | if not self.tkinter_available: |
| 237 | self.print_status( |
| 238 | "GUI file dialog not available - using manual input", "warning" |
| 239 | ) |
| 240 | return self._get_manual_file_path() |
| 241 | |
| 242 | def select_file(): |
| 243 | try: |
| 244 | import tkinter as tk |
| 245 | from tkinter import filedialog |
| 246 | |
| 247 | root = tk.Tk() |
| 248 | root.withdraw() |
| 249 | root.attributes("-topmost", True) |
| 250 | |
| 251 | file_types = [ |
| 252 | ("Research Papers", "*.pdf;*.docx;*.doc"), |
| 253 | ("PDF Files", "*.pdf"), |
| 254 | ("Word Documents", "*.docx;*.doc"), |
| 255 | ("PowerPoint Files", "*.pptx;*.ppt"), |
| 256 | ("HTML Files", "*.html;*.htm"), |
| 257 | ("Text Files", "*.txt;*.md"), |
| 258 | ("All Files", "*.*"), |
| 259 | ] |
| 260 | |
| 261 | if platform.system() == "Darwin": |
| 262 | file_types = [ |
| 263 | ("Research Papers", ".pdf .docx .doc"), |
| 264 | ("PDF Files", ".pdf"), |
| 265 | ("Word Documents", ".docx .doc"), |
| 266 | ("PowerPoint Files", ".pptx .ppt"), |
| 267 | ("HTML Files", ".html .htm"), |
| 268 | ("Text Files", ".txt .md"), |
| 269 | ("All Files", ".*"), |
| 270 | ] |
| 271 | |
| 272 | file_path = filedialog.askopenfilename( |
| 273 | title="Select Research File - DeepCode CLI", |
| 274 | filetypes=file_types, |
| 275 | initialdir=os.getcwd(), |
| 276 | ) |
| 277 | |
| 278 | root.destroy() |
| 279 | return file_path |
| 280 | |
| 281 | except Exception as e: |
| 282 | self.print_status(f"File dialog error: {str(e)}", "error") |
| 283 | return self._get_manual_file_path() |
| 284 | |
| 285 | self.print_status("Opening file browser dialog...", "upload") |
| 286 | file_path = select_file() |
| 287 | |
| 288 | if file_path: |
| 289 | self.print_status( |
| 290 | f"File selected: {os.path.basename(file_path)}", "success" |
| 291 | ) |
no test coverage detected