Skip to content

Commit

Permalink
Add reset settings to default (chidiwilliams#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
chidiwilliams authored Nov 21, 2022
1 parent 1869c71 commit 60e586b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ omit =
directory = coverage/html

[report]
fail_under = 75
fail_under = 78
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version := $$(poetry version -s)
version_escaped := $$(echo ${version} | sed -e 's/\./\\./g')

mac_app_path := ./dist/Buzz.app
mac_zip_path := ./dist/Buzz-${version}-mac.zip
Expand Down Expand Up @@ -54,6 +55,7 @@ dist/Buzz dist/Buzz.app: whisper_cpp.py
version:
poetry version ${version}
echo "VERSION = \"${version}\"" > __version__.py
sed -i "s/version=.*,/version=\'${version_escaped}\',/" Buzz.spec

CMAKE_FLAGS=
ifeq ($(UNAME_S),Darwin)
Expand Down
34 changes: 25 additions & 9 deletions gui.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import enum
import logging
import os
import platform
import sys
from datetime import datetime
from typing import Dict, List, Optional, Tuple
from typing import Any, Dict, List, Optional, Tuple

import humanize
import sounddevice
Expand Down Expand Up @@ -469,7 +470,7 @@ def on_click_run(self):
if output_file == '':
return

use_whisper_cpp = self.settings.enable_ggml_inference(
use_whisper_cpp = self.settings.get_enable_ggml_inference(
) and self.selected_language is not None

self.run_button.setDisabled(True)
Expand Down Expand Up @@ -547,15 +548,30 @@ def on_word_level_timings_changed(self, value: int):


class Settings(QSettings):
ENABLE_GGML_INFERENCE = 'enable_ggml_inference'
_ENABLE_GGML_INFERENCE = 'enable_ggml_inference'

def __init__(self, parent: Optional[QWidget], *args):
def __init__(self, parent: Optional[QWidget] = None, *args):
super().__init__('Buzz', 'Buzz', parent, *args)
logging.debug('Loaded settings from path = %s', self.fileName())

def enable_ggml_inference(self):
def get_enable_ggml_inference(self) -> bool:
if LOADED_WHISPER_DLL is False:
return False
return self.value(self.ENABLE_GGML_INFERENCE, False)
return self._value_to_bool(self.value(self._ENABLE_GGML_INFERENCE, False))

def set_enable_ggml_inference(self, value: bool) -> None:
self.setValue(self._ENABLE_GGML_INFERENCE, value)

# Convert QSettings value to boolean: https://forum.qt.io/topic/108622/how-to-get-a-boolean-value-from-qsettings-correctly
@staticmethod
def _value_to_bool(value: Any) -> bool:
if isinstance(value, bool):
return value

if isinstance(value, str):
return value.lower() == 'true'

return bool(value)


class RecordingTranscriberWidget(QWidget):
Expand Down Expand Up @@ -642,7 +658,7 @@ def on_task_changed(self, task: Task):
def start_recording(self):
self.record_button.setDisabled(True)

use_whisper_cpp = self.settings.enable_ggml_inference(
use_whisper_cpp = self.settings.get_enable_ggml_inference(
) and self.selected_language is not None

model_name = get_model_name(self.selected_quality)
Expand Down Expand Up @@ -803,7 +819,7 @@ def __init__(self, title: str, w: int, h: int, parent: Optional[QWidget], *args)
'&Enable GGML Inference', self)
enable_ggml_inference_action.setCheckable(True)
enable_ggml_inference_action.setChecked(
bool(self.settings.enable_ggml_inference()))
bool(self.settings.get_enable_ggml_inference()))
enable_ggml_inference_action.triggered.connect(
self.on_toggle_enable_ggml_inference)
enable_ggml_inference_action.setDisabled(LOADED_WHISPER_DLL is False)
Expand All @@ -822,7 +838,7 @@ def on_import_audio_file_action(self):
self.new_import_window_triggered.emit((file_path, self.geometry()))

def on_toggle_enable_ggml_inference(self, state: bool):
self.settings.setValue(Settings.ENABLE_GGML_INFERENCE, state)
self.settings.set_enable_ggml_inference(state)

def on_trigger_about_action(self):
about_dialog = AboutDialog(self)
Expand Down
16 changes: 15 additions & 1 deletion gui_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from gui import (Application, AudioDevicesComboBox,
DownloadModelProgressDialog, FileTranscriberWidget,
LanguagesComboBox, MainWindow, OutputFormatsComboBox, Quality,
LanguagesComboBox, MainWindow, OutputFormatsComboBox, Quality, Settings,
QualityComboBox, TranscriberProgressDialog)
from transcriber import OutputFormat

Expand Down Expand Up @@ -190,3 +190,17 @@ def test_should_transcribe(self):

output_file = open(output_file_path, 'r', encoding='utf-8')
assert 'Bienvenue dans Passe-Relle, un podcast' in output_file.read()


class TestSettings:
def test_should_enable_ggml_inference(self):
settings = Settings()
settings.clear()

assert settings.get_enable_ggml_inference() is False

settings.set_enable_ggml_inference(True)
assert settings.get_enable_ggml_inference() is True

settings.set_enable_ggml_inference(False)
assert settings.get_enable_ggml_inference() is False

0 comments on commit 60e586b

Please sign in to comment.