From 1eb2fe1c7aedd80636b0011b70271585d74e5e87 Mon Sep 17 00:00:00 2001 From: DavidHruby1 Date: Wed, 4 Nov 2026 10:34:27 +0100 Subject: [PATCH 1/2] feat: show where vocabulary is sent and warn when unused in Raw (#55) --- docs/IMPLEMENTATION.md | 6 +++ src/config.py | 25 ++++++++++ src/settings_dialog.py | 72 +++++++++++++++++++++++++++- tests/test_settings_dialog.py | 89 +++++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+), 1 deletion(-) diff --git a/docs/IMPLEMENTATION.md b/docs/IMPLEMENTATION.md index 3967af8..94ef4ff 100644 --- a/docs/IMPLEMENTATION.md +++ b/docs/IMPLEMENTATION.md @@ -795,6 +795,12 @@ ruff format --check src/ tests/ .github/scripts/ and 8,000 rendered characters. `rewrite()` adds quoted spelling guidance; STT adds multipart `prompt` only when that provider's own opt-in is enabled and vocabulary is nonempty. These are hints, not guarantees. + `vocabulary_delivery(cfg) -> set[str]` (`config.py`, pure) reports where a nonempty + vocabulary goes: `"stt"` when the primary (or an enabled fallback) provider prompt is on, + `"rewrite"` when the manual profile (Automatic: the default profile) is not Raw. App mappings + to other profiles do not count. When the set is empty the Vocabulary page shows a warning + pointing at Replacements and a "Turn on provider prompt" button (enables the primary toggle + and opens the Speech page); it is recomputed on the dialog's working copy as inputs change. - Replacements are JSON `[heard, write]` pairs applied by the worker to the raw transcript after STT and to the rewritten text after the LLM, so they also work with Raw. Matching is whole-word, case-insensitive, longest first, in one pass. diff --git a/src/config.py b/src/config.py index 6380002..7728979 100644 --- a/src/config.py +++ b/src/config.py @@ -213,6 +213,31 @@ def _validated_rewrite_selection( return profiles, mappings +def vocabulary_delivery(cfg: AppConfig) -> set[str]: + """Where the vocabulary is sent: a subset of {"stt", "rewrite"}. + + Pure and Qt-free so the settings dialog can evaluate it on its working copy. + "rewrite" means the profile that applies when no app mapping matches (the manual + choice, or the default in Automatic mode) is not Raw; app mappings to other profiles + are deliberately ignored. An empty vocabulary is never sent anywhere. + """ + if not cfg.vocabulary_entries: + return set() + delivery: set[str] = set() + if cfg.stt_prompt_primary_enabled or ( + cfg.stt_fallback_enabled and cfg.stt_prompt_fallback_enabled + ): + delivery.add("stt") + profile_id = ( + cfg.rewrite_default_profile_id + if cfg.rewrite_selection_mode == "automatic" + else cfg.rewrite_manual_profile_id + ) + if profile_id != "raw": + delivery.add("rewrite") + return delivery + + def resolve_rewrite_profile(cfg: AppConfig, executable_path: str | None) -> RewriteProfile: """Pure resolution on a session snapshot: manual choice, or Auto mapping -> default.""" profiles, mappings = _validated_rewrite_selection(cfg) diff --git a/src/settings_dialog.py b/src/settings_dialog.py index f820df8..5c39d3d 100644 --- a/src/settings_dialog.py +++ b/src/settings_dialog.py @@ -7,6 +7,7 @@ from __future__ import annotations import copy +import dataclasses import logging import threading import uuid @@ -70,6 +71,7 @@ ) import httpx +import shiboken6 from src.config import ( COMMON_LANGUAGES, @@ -101,6 +103,7 @@ reset_config, save_config, validate_config, + vocabulary_delivery, ) from src import http_client, theme from src.audio import resolve_device @@ -815,6 +818,7 @@ def _build_ui(self) -> None: bottom.addStretch() bottom.addWidget(self._button_box) main.addWidget(footer) + self._connect_vocabulary_delivery() # --- General tab --------------------------------------------------- @@ -1020,6 +1024,7 @@ def _build_stt_tab(self) -> None: _section(form, "Provider", first=True) advanced = Collapsible("Advanced") + self._stt_advanced = advanced self._stt_provider = ProviderFields( form, STT_PRESETS, @@ -1511,9 +1516,19 @@ def _build_audio_tab(self) -> None: def _build_vocabulary_tab(self) -> None: tab = QWidget() form = QFormLayout(tab) + self._vocabulary_warning = _hint(QLabel(), "warning") + self._vocabulary_warning.setWordWrap(True) + self._vocabulary_warning.setVisible(False) + form.addRow(self._vocabulary_warning) + self._vocabulary_enable_btn = QPushButton("Turn on provider prompt") + self._vocabulary_enable_btn.clicked.connect(self._on_enable_provider_prompt) + self._vocabulary_enable_btn.setVisible(False) + form.addRow("", _button_row(self._vocabulary_enable_btn)) _section(form, "Preferred spellings", first=True) hint = QLabel( - "Names, acronyms and project terms. The AI rewrite uses them as spelling hints." + "Names, acronyms and project terms. Terms are sent as hints to (1) the " + "speech-to-text provider when “Send vocabulary to this provider” is on " + "(Speech → Advanced), and (2) the AI rewrite in every profile except Raw." ) hint.setWordWrap(True) form.addRow(_hint(hint)) @@ -1566,6 +1581,60 @@ def _build_vocabulary_tab(self) -> None: _style_form(form) self._tabs.addTab(tab, "Vocabulary") + def _connect_vocabulary_delivery(self) -> None: + """Re-evaluate the "vocabulary unused" warning whenever its inputs change.""" + model = self._vocabulary_list.model() + for signal in (model.rowsInserted, model.rowsRemoved, model.modelReset): + signal.connect(self._refresh_vocabulary_warning) + for toggle in ( + self._stt_prompt_primary_check, + self._stt_prompt_fallback_check, + self._stt_fb_check, + ): + toggle.toggled.connect(self._refresh_vocabulary_warning) + for combo in (self._rewrite_active_combo, self._rewrite_default_combo): + combo.currentIndexChanged.connect(self._refresh_vocabulary_warning) + self._refresh_vocabulary_warning() + + def _refresh_vocabulary_warning(self, *_args) -> None: + if self._profile_loading or not shiboken6.isValid(self._rewrite_active_combo): + return # mid-repopulation, or the dialog is being torn down + automatic = self._rewrite_active_combo.currentData() == "__automatic__" + profile_id = ( + self._rewrite_default_combo.currentData() + if automatic + else self._rewrite_active_combo.currentData() + ) + snapshot = dataclasses.replace( + self._working, + vocabulary_entries=self._vocabulary_values(), + stt_prompt_primary_enabled=self._stt_prompt_primary_check.isChecked(), + stt_prompt_fallback_enabled=self._stt_prompt_fallback_check.isChecked(), + stt_fallback_enabled=self._stt_fb_check.isChecked(), + rewrite_selection_mode="automatic" if automatic else "manual", + rewrite_default_profile_id=profile_id, + rewrite_manual_profile_id=profile_id, + ) + unused = bool(snapshot.vocabulary_entries) and not vocabulary_delivery(snapshot) + if unused: + text = ( + "Your vocabulary isn't used right now: the Raw profile skips AI rewrite " + "and the Speech provider prompt is off. For guaranteed fixes use " + "Replacements below." + ) + if automatic: + text += " Apps mapped to other profiles still use the vocabulary." + self._vocabulary_warning.setText(text) + self._vocabulary_warning.setVisible(unused) + self._vocabulary_enable_btn.setVisible(unused) + + def _on_enable_provider_prompt(self) -> None: + """Switch the primary provider prompt on and show it on the Speech page.""" + self._stt_advanced.toggle.setChecked(True) + self._stt_prompt_primary_check.setChecked(True) + self._tabs.setCurrentIndex(1) # STT page + self._stt_prompt_primary_check.setFocus() + def _vocabulary_values(self) -> list[str]: return [self._vocabulary_list.item(i).text() for i in range(self._vocabulary_list.count())] @@ -1697,6 +1766,7 @@ def _populate(self, cfg: AppConfig) -> None: self._vocabulary_input.clear() self._replacements = list(cfg.replacements) self._refresh_replacement_list() + self._refresh_vocabulary_warning() def _collect(self) -> None: """Write widget values back into self._working.""" diff --git a/tests/test_settings_dialog.py b/tests/test_settings_dialog.py index 9c49079..60fea4b 100644 --- a/tests/test_settings_dialog.py +++ b/tests/test_settings_dialog.py @@ -611,3 +611,92 @@ def test_toggle_switch_keeps_checkbox_behavior(self) -> None: dlg._sound_check.click() self.assertTrue(dlg._sound_check.isChecked()) self.assertFalse(dlg._llm_group.isHidden()) + + +class VocabularyDeliveryTests(unittest.TestCase): + def test_delivery_by_profile_and_provider_prompt(self) -> None: + from src.config import vocabulary_delivery + + def cfg(**kw) -> AppConfig: + base = {"vocabulary_entries": ["PySide6"], "rewrite_manual_profile_id": "raw"} + return AppConfig(**{**base, **kw}) + + self.assertEqual(vocabulary_delivery(cfg()), set()) + self.assertEqual(vocabulary_delivery(cfg(stt_prompt_primary_enabled=True)), {"stt"}) + self.assertEqual(vocabulary_delivery(cfg(rewrite_manual_profile_id="clean")), {"rewrite"}) + self.assertEqual( + vocabulary_delivery( + cfg(rewrite_manual_profile_id="clean", stt_prompt_primary_enabled=True) + ), + {"stt", "rewrite"}, + ) + # A fallback prompt only counts while the fallback itself is enabled. + self.assertEqual(vocabulary_delivery(cfg(stt_prompt_fallback_enabled=True)), set()) + self.assertEqual( + vocabulary_delivery(cfg(stt_prompt_fallback_enabled=True, stt_fallback_enabled=True)), + {"stt"}, + ) + # Automatic mode follows the default profile, not the hidden manual choice. + self.assertEqual( + vocabulary_delivery( + cfg( + rewrite_selection_mode="automatic", + rewrite_default_profile_id="raw", + rewrite_manual_profile_id="clean", + ) + ), + set(), + ) + empty = cfg(vocabulary_entries=[], stt_prompt_primary_enabled=True) + self.assertEqual(vocabulary_delivery(empty), set()) + + +class VocabularyWarningTests(unittest.TestCase): + def setUp(self) -> None: + tmp = self.enterContext(tempfile.TemporaryDirectory()) + self.enterContext(patch("src.config.APP_DIR", tmp)) + self.enterContext(patch("src.config._dpapi_available", return_value=False)) + self.enterContext(patch("src.settings_dialog.is_supported", return_value=False)) + + def _dialog(self, **kw) -> SettingsDialog: + cfg = AppConfig( + stt_api_key="key", + stt_base_url="https://example.test/v1", + stt_model="stt", + llm_api_key="test", + llm_base_url="https://example.test/v1", + llm_model="test", + **kw, + ) + dlg = SettingsDialog(cfg, devices=[]) + self.addCleanup(dlg.deleteLater) + return dlg + + @staticmethod + def _shown(dlg: SettingsDialog) -> bool: + return not dlg._vocabulary_warning.isHidden() + + def test_warning_shows_for_raw_without_prompt_and_clears_on_toggle(self) -> None: + dlg = self._dialog(vocabulary_entries=["PySide6"], rewrite_manual_profile_id="raw") + self.assertTrue(self._shown(dlg)) + dlg._stt_prompt_primary_check.setChecked(True) + self.assertFalse(self._shown(dlg)) + dlg._stt_prompt_primary_check.setChecked(False) + self.assertTrue(self._shown(dlg)) + + def test_warning_clears_on_profile_change_and_button_enables_prompt(self) -> None: + dlg = self._dialog(vocabulary_entries=["PySide6"], rewrite_manual_profile_id="raw") + dlg._rewrite_active_combo.setCurrentIndex(dlg._rewrite_active_combo.findData("clean")) + self.assertFalse(self._shown(dlg)) + dlg._rewrite_active_combo.setCurrentIndex(dlg._rewrite_active_combo.findData("raw")) + self.assertTrue(self._shown(dlg)) + dlg._on_enable_provider_prompt() + self.assertTrue(dlg._stt_prompt_primary_check.isChecked()) + self.assertFalse(self._shown(dlg)) + + def test_no_warning_for_empty_vocabulary_and_it_follows_edits(self) -> None: + dlg = self._dialog(rewrite_manual_profile_id="raw") + self.assertFalse(self._shown(dlg)) + dlg._vocabulary_input.setText("PySide6") + dlg._on_vocabulary_add() + self.assertTrue(self._shown(dlg)) From b05b830554905d4d19f3f8ff0f579dd49d95352a Mon Sep 17 00:00:00 2001 From: DavidHruby1 Date: Wed, 4 Nov 2026 10:38:21 +0100 Subject: [PATCH 2/2] fix: hide vocabulary enable-button row fully and make Auto caveat conditional The empty form label next to the hidden 'Turn on provider prompt' button kept reserving a row; hide the whole row via setRowVisible. The 'apps mapped to other profiles' caveat now only appears when a non-Raw app mapping exists. Co-Authored-By: Claude --- src/settings_dialog.py | 10 ++++++---- tests/test_settings_dialog.py | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/settings_dialog.py b/src/settings_dialog.py index 5c39d3d..80e3a06 100644 --- a/src/settings_dialog.py +++ b/src/settings_dialog.py @@ -1522,8 +1522,10 @@ def _build_vocabulary_tab(self) -> None: form.addRow(self._vocabulary_warning) self._vocabulary_enable_btn = QPushButton("Turn on provider prompt") self._vocabulary_enable_btn.clicked.connect(self._on_enable_provider_prompt) - self._vocabulary_enable_btn.setVisible(False) - form.addRow("", _button_row(self._vocabulary_enable_btn)) + self._vocabulary_enable_row = _button_row(self._vocabulary_enable_btn) + form.addRow("", self._vocabulary_enable_row) + form.setRowVisible(self._vocabulary_enable_row, False) # hides the empty label too + self._vocabulary_form = form _section(form, "Preferred spellings", first=True) hint = QLabel( "Names, acronyms and project terms. Terms are sent as hints to (1) the " @@ -1622,11 +1624,11 @@ def _refresh_vocabulary_warning(self, *_args) -> None: "and the Speech provider prompt is off. For guaranteed fixes use " "Replacements below." ) - if automatic: + if automatic and any(m.profile_id != "raw" for m in self._rewrite_app_mappings): text += " Apps mapped to other profiles still use the vocabulary." self._vocabulary_warning.setText(text) self._vocabulary_warning.setVisible(unused) - self._vocabulary_enable_btn.setVisible(unused) + self._vocabulary_form.setRowVisible(self._vocabulary_enable_row, unused) def _on_enable_provider_prompt(self) -> None: """Switch the primary provider prompt on and show it on the Speech page.""" diff --git a/tests/test_settings_dialog.py b/tests/test_settings_dialog.py index 60fea4b..3c9f518 100644 --- a/tests/test_settings_dialog.py +++ b/tests/test_settings_dialog.py @@ -12,7 +12,7 @@ from PySide6.QtGui import QFocusEvent from PySide6.QtWidgets import QApplication, QLineEdit, QDialog -from src.config import AppConfig, load_config, save_config +from src.config import AppConfig, AppMapping, load_config, save_config from src.utils import AppError, ScreamerError from src.settings_dialog import PasswordField, SettingsDialog @@ -700,3 +700,21 @@ def test_no_warning_for_empty_vocabulary_and_it_follows_edits(self) -> None: dlg._vocabulary_input.setText("PySide6") dlg._on_vocabulary_add() self.assertTrue(self._shown(dlg)) + + def test_automatic_caveat_only_with_non_raw_app_mapping(self) -> None: + dlg = self._dialog( + vocabulary_entries=["PySide6"], + rewrite_selection_mode="automatic", + rewrite_default_profile_id="raw", + ) + self.assertTrue(self._shown(dlg)) + self.assertNotIn("Apps mapped", dlg._vocabulary_warning.text()) + dlg._rewrite_app_mappings = [AppMapping("code.exe", "clean")] + dlg._refresh_vocabulary_warning() + self.assertIn("Apps mapped", dlg._vocabulary_warning.text()) + + def test_enable_button_row_follows_warning(self) -> None: + dlg = self._dialog(vocabulary_entries=["PySide6"], rewrite_manual_profile_id="raw") + self.assertTrue(dlg._vocabulary_form.isRowVisible(dlg._vocabulary_enable_row)) + dlg._stt_prompt_primary_check.setChecked(True) + self.assertFalse(dlg._vocabulary_form.isRowVisible(dlg._vocabulary_enable_row))