Skip to content

Commit

Permalink
Add sound notifications for processing events and add version to star…
Browse files Browse the repository at this point in the history
…t and end messages

Introduced a checkbox to play sounds on completion. Implemented sound notifications for various processing error events and successful completions.
  • Loading branch information
cbusillo committed Jun 28, 2024
1 parent fe131e6 commit abe9674
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions bd_to_avp/gui/main_window.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from datetime import datetime
from pathlib import Path
from typing import Callable
Expand Down Expand Up @@ -191,9 +192,10 @@ def create_misc_options(self, config_layout: QVBoxLayout) -> None:
config_layout.addWidget(self.remove_extra_languages_checkbox)

def create_processing_options(self, config_layout: QVBoxLayout) -> None:
self.keep_awake_checkbox = self.create_checkbox("Keep Awake", config.keep_awake)
self.start_stage_combobox = LabeledComboBox("Start Stage", Stage.list())
self.language_combobox = LabeledComboBox("Language", get_common_language_options())
self.keep_awake_checkbox = self.create_checkbox("Keep Awake", config.keep_awake)
self.play_sound_checkbox = self.create_checkbox("Play sound on completion", True)

config_layout.setSpacing(0)
config_layout.addWidget(self.start_stage_combobox)
Expand All @@ -202,6 +204,7 @@ def create_processing_options(self, config_layout: QVBoxLayout) -> None:
spacer_label.setFixedHeight(5)
config_layout.addWidget(spacer_label)
config_layout.addWidget(self.keep_awake_checkbox)
config_layout.addWidget(self.play_sound_checkbox)
config_layout.addWidget(spacer_label)
self.create_processing_button(config_layout)

Expand Down Expand Up @@ -255,15 +258,22 @@ def create_menu_bar(self) -> None:
help_menu.addAction(update_action)
# self.setMenuBar(menu_bar)

def notify_user_with_sound(self, sound_name: str) -> None:
if self.play_sound_checkbox.isChecked():
sound_path = Path("/System/Library/Sounds") / f"{sound_name}.aiff"
if sound_path.exists():
os.system(f"afplay /System/Library/Sounds/{sound_name}.aiff")

def handle_processing_error(self, error: Exception) -> None:
self.notify_user_with_sound("Sosumi")
QMessageBox.warning(self, "Warning", "Failure in processing.\n\n" + str(error))
time_elapsed = formatted_time_elapsed(self.process_start_time)
self.update_processing_output(str(error) + f"\n❌ Processing failed in {time_elapsed} ❌")
self.stop_processing()
self.process_button.setText(self.START_PROCESSING_TEXT)

def handle_mkv_creation_error(self, error: MKVCreationError) -> None:

self.notify_user_with_sound("Sosumi")
result = QMessageBox.critical(
self,
"MKV Creation Error",
Expand All @@ -280,6 +290,7 @@ def handle_mkv_creation_error(self, error: MKVCreationError) -> None:
self.handle_processing_error(error)

def handle_file_exists_error(self, error: FileExistsError) -> None:
self.notify_user_with_sound("Sosumi")
result = QMessageBox.critical(
self,
"File Exists Error",
Expand All @@ -295,6 +306,7 @@ def handle_file_exists_error(self, error: FileExistsError) -> None:
self.handle_processing_error(error)

def handle_srt_creation_error(self, error: SRTCreationError) -> None:
self.notify_user_with_sound("Sosumi")
result = QMessageBox.critical(
self,
"SRT Creation Error",
Expand Down Expand Up @@ -348,10 +360,10 @@ def load_config_and_update_ui(self) -> None:
self.continue_on_error.setChecked(config.continue_on_error)
self.skip_subtitles_checkbox.setChecked(config.skip_subtitles)
self.start_stage_combobox.set_current_text(str(config.start_stage))
self.keep_awake_checkbox.setChecked(config.keep_awake)
language_name = Language.fromalpha3b(config.language_code).name
self.language_combobox.set_current_text(language_name)
self.remove_extra_languages_checkbox.setChecked(config.remove_extra_languages)
self.keep_awake_checkbox.setChecked(config.keep_awake)

def toggle_processing(self) -> None:
if self.process_button.text() == self.START_PROCESSING_TEXT:
Expand All @@ -378,18 +390,21 @@ def toggle_processing(self) -> None:
def start_processing(self, is_continuing: bool = False) -> None:
if not is_continuing:
start_time = format_timestamp(datetime.now())
self.processing_output_textedit.append(f"🟢 Processing started at {start_time} 🟢")
self.processing_output_textedit.append(
f"🟢 Processing started at {start_time} with version {config.app.code_version}. 🟢"
)
self.save_config()
self.process_start_time = datetime.now()
self.processing_thread.start()
self.process_button.setText(self.STOP_PROCESSING_TEXT)

def finished_processing(self) -> None:
time_elapsed = formatted_time_elapsed(self.process_start_time)
self.processing_output_textedit.append(
f"✅ Processing completed in {time_elapsed}. You can now play from the Files app on the AVP ✅"
)
message = f"✅ Processing completed in {time_elapsed} with version {config.app.code_version}. You can now play from the Files app on the AVP ✅"
self.processing_output_textedit.append(message)
self.process_button.setText(self.START_PROCESSING_TEXT)
self.notify_user_with_sound("Glass")
QMessageBox.information(self, "Processing Complete", message)

def save_config_to_file(self) -> None:
self.save_config()
Expand Down Expand Up @@ -425,9 +440,9 @@ def save_config(self) -> None:
config.continue_on_error = self.continue_on_error.isChecked()
config.skip_subtitles = self.skip_subtitles_checkbox.isChecked()
config.start_stage = Stage.get_stage(selected_stage)
config.keep_awake = self.keep_awake_checkbox.isChecked()
config.language_code = Language.fromname(self.language_combobox.current_text()).alpha3b
config.remove_extra_languages = self.remove_extra_languages_checkbox.isChecked()
config.keep_awake = self.keep_awake_checkbox.isChecked()

def stop_processing(self) -> None:
time_elapsed = formatted_time_elapsed(self.process_start_time)
Expand Down

0 comments on commit abe9674

Please sign in to comment.