Skip to content

Commit

Permalink
Drag and drop to import file (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
chidiwilliams authored Apr 9, 2023
1 parent 010b89f commit 7474ad4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions buzz/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7474ad4

Please sign in to comment.