mirror of
https://github.com/chidiwilliams/buzz.git
synced 2026-03-14 22:55:46 +01:00
Shut down file transcription gracefully on window close (#119)
This commit is contained in:
parent
6edd6ee95a
commit
68aff48be6
2 changed files with 22 additions and 15 deletions
28
gui.py
28
gui.py
|
|
@ -325,6 +325,7 @@ class FileTranscriberWidget(QWidget):
|
|||
model_download_progress_dialog: Optional[DownloadModelProgressDialog] = None
|
||||
transcriber_progress_dialog: Optional[TranscriberProgressDialog] = None
|
||||
transcribe_progress = pyqtSignal(tuple)
|
||||
file_transcriber: Optional[FileTranscriber] = None
|
||||
|
||||
def __init__(self, file_path: str, parent: Optional[QWidget]) -> None:
|
||||
super().__init__(parent)
|
||||
|
|
@ -393,10 +394,6 @@ class FileTranscriberWidget(QWidget):
|
|||
self.selected_output_format = format
|
||||
|
||||
def on_click_run(self):
|
||||
base_path = getattr(sys, '_MEIPASS', os.path.dirname(
|
||||
os.path.abspath(__file__)))
|
||||
logging.debug(base_path)
|
||||
|
||||
default_path = FileTranscriber.get_default_output_file_path(
|
||||
task=self.selected_task, input_file_path=self.file_path,
|
||||
output_format=self.selected_output_format)
|
||||
|
|
@ -452,7 +449,7 @@ class FileTranscriberWidget(QWidget):
|
|||
(current_size, total_size) = progress
|
||||
|
||||
if current_size == total_size:
|
||||
self.end_transcription()
|
||||
self.reset_transcription()
|
||||
return
|
||||
|
||||
# In the middle of transcription...
|
||||
|
|
@ -462,18 +459,19 @@ class FileTranscriberWidget(QWidget):
|
|||
self.transcriber_progress_dialog = TranscriberProgressDialog(
|
||||
file_path=self.file_path, total_size=total_size, parent=self)
|
||||
self.transcriber_progress_dialog.canceled.connect(
|
||||
self.on_cancel_transcriber_progress_dialog)
|
||||
self.stop_transcription)
|
||||
|
||||
# Update the progress of the dialog unless it has
|
||||
# been canceled before this progress update arrived
|
||||
if self.transcriber_progress_dialog != None and self.transcriber_progress_dialog.wasCanceled() == False:
|
||||
self.transcriber_progress_dialog.update_progress(current_size)
|
||||
|
||||
def on_cancel_transcriber_progress_dialog(self):
|
||||
self.file_transcriber.stop()
|
||||
self.end_transcription()
|
||||
def stop_transcription(self):
|
||||
if self.file_transcriber != None:
|
||||
self.file_transcriber.stop()
|
||||
self.reset_transcription()
|
||||
|
||||
def end_transcription(self):
|
||||
def reset_transcription(self):
|
||||
self.run_button.setDisabled(False)
|
||||
if self.transcriber_progress_dialog != None:
|
||||
self.transcriber_progress_dialog.destroy()
|
||||
|
|
@ -718,9 +716,13 @@ class FileTranscriberMainWindow(MainWindow):
|
|||
super().__init__(title=get_short_file_path(
|
||||
file_path), w=400, h=210, parent=parent, *args)
|
||||
|
||||
central_widget = FileTranscriberWidget(file_path, self)
|
||||
central_widget.setContentsMargins(10, 10, 10, 10)
|
||||
self.setCentralWidget(central_widget)
|
||||
self.central_widget = FileTranscriberWidget(file_path, self)
|
||||
self.central_widget.setContentsMargins(10, 10, 10, 10)
|
||||
self.setCentralWidget(self.central_widget)
|
||||
|
||||
def closeEvent(self, event: QCloseEvent) -> None:
|
||||
self.central_widget.stop_transcription()
|
||||
return super().closeEvent(event)
|
||||
|
||||
|
||||
class Application(QApplication):
|
||||
|
|
|
|||
|
|
@ -141,9 +141,9 @@ class RecordingTranscriber:
|
|||
self.is_running = False
|
||||
|
||||
if self.current_thread != None:
|
||||
logging.debug('Waiting for processing thread to terminate')
|
||||
logging.debug('Waiting for recording thread to terminate')
|
||||
self.current_thread.join()
|
||||
logging.debug('Processing thread terminated')
|
||||
logging.debug('Recording thread terminated')
|
||||
|
||||
|
||||
def more_data(fd: int):
|
||||
|
|
@ -315,6 +315,11 @@ class FileTranscriber:
|
|||
def stop(self):
|
||||
self.stopped = True
|
||||
|
||||
if self.current_thread != None:
|
||||
logging.debug('Waiting for file transcription thread to terminate')
|
||||
self.current_thread.join()
|
||||
logging.debug('File transcription thread terminated')
|
||||
|
||||
def check_stopped(self):
|
||||
return self.stopped
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue