From a410dc62c3b3b1ba14794c7bb13471cf3d9457f9 Mon Sep 17 00:00:00 2001 From: Chidi Williams Date: Sun, 9 Apr 2023 13:18:42 +0100 Subject: [PATCH] Drag and drop to import files --- buzz/gui.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/buzz/gui.py b/buzz/gui.py index b7237fd80..4cc902ddc 100644 --- a/buzz/gui.py +++ b/buzz/gui.py @@ -936,6 +936,8 @@ def __init__(self, tasks_cache=TasksCache()): self.setWindowIcon(QIcon(BUZZ_ICON_PATH)) self.setMinimumSize(450, 400) + self.setAcceptDrops(True) + self.tasks_cache = tasks_cache self.tasks = {} @@ -979,6 +981,17 @@ def __init__(self, tasks_cache=TasksCache()): self.load_tasks_from_cache() + def dragEnterEvent(self, event): + # Accept file drag events + if event.mimeData().hasUrls(): + event.accept() + else: + event.ignore() + + def dropEvent(self, event): + file_paths = [url.toLocalFile() for url in event.mimeData().urls()] + self.open_file_transcriber_widget(file_paths=file_paths) + def on_file_transcriber_triggered(self, options: Tuple[TranscriptionOptions, FileTranscriptionOptions, str]): transcription_options, file_transcription_options, model_path = options for file_path in file_transcription_options.file_paths: @@ -1028,6 +1041,9 @@ def on_new_transcription_action_triggered(self): if len(file_paths) == 0: return + self.open_file_transcriber_widget(file_paths) + + def open_file_transcriber_widget(self, file_paths: List[str]): file_transcriber_window = FileTranscriberWidget( file_paths, self.openai_access_token, self, flags=Qt.WindowType.Window) file_transcriber_window.triggered.connect(