Skip to content

Commit 8ec6fb9

Browse files
committed
Supresses repeated announcements of 'ruta'.
1 parent 98150a8 commit 8ec6fb9

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

addon/appModules/vismaAdmin/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ctypes import *
77
import config
88
import gui
9+
from gui.settingsDialogs import SettingsPanel
910
import appModuleHandler
1011
import addonHandler
1112
import locale
@@ -189,7 +190,7 @@ def getCurrentVismaModule(self, ctrl):
189190
global module_lines
190191
lines = [k for k in module_lines if ("%s\t" % wndtxt) in k]
191192
if len(lines ) == 0:
192-
log.info("Ny modul: %s" % module)
193+
#log.info("Ny modul: %s" % module)
193194
return module
194195
lineparts = lines[0].split('\t')
195196
module = lineparts[1]
@@ -454,7 +455,7 @@ def GetCurrentRow(self):
454455
return None
455456

456457

457-
class VismaAdministrationSettingsPanel(gui.SettingsPanel):
458+
class VismaAdministrationSettingsPanel(SettingsPanel):
458459
# Translators: the label/title for the Visma Administration settings panel.
459460
title = _('Visma Administration')
460461

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,81 @@
11
import appModuleHandler
2+
import os
23
import globalPluginHandler
4+
import api
5+
from typing import Iterable, List, Any
6+
import speech
7+
from logHandler import log
8+
9+
10+
TARGET_EXE = "spcsadm.exe"
11+
TEXT_TO_SUPPRESS = "ruta"
12+
13+
14+
def _is_target_context() -> bool:
15+
f = api.getFocusObject()
16+
if not f:
17+
return False
18+
# App check
19+
am = getattr(f, "appModule", None)
20+
app_ok = False
21+
if am:
22+
appPath = (getattr(am, "appPath", "") or "")
23+
app_ok = os.path.basename(appPath).lower() == TARGET_EXE.lower()
24+
if not app_ok:
25+
appName = (getattr(am, "appName", "") or "").lower()
26+
app_ok = appName in {TARGET_EXE.lower(), TARGET_EXE.lower().removesuffix(".exe")}
27+
return app_ok
28+
29+
30+
def _item_text(item: Any) -> str | None:
31+
"""Best-effort: speech sequences can contain strings and command objects."""
32+
if isinstance(item, str):
33+
return item
34+
# Many speech command objects expose .text (e.g. TextCommand).
35+
txt = getattr(item, "text", None)
36+
return txt if isinstance(txt, str) else None
37+
38+
def _filter_sequence(seq: Iterable[Any]) -> List[Any]:
39+
if not _is_target_context():
40+
return list(seq)
41+
out: List[Any] = []
42+
suppress = TEXT_TO_SUPPRESS.lower()
43+
for item in seq:
44+
txt = _item_text(item)
45+
if txt is not None and txt.strip().lower() == suppress:
46+
# Skip this piece entirely.
47+
continue
48+
49+
50+
out.append(item)
51+
return out
352

453

554
class GlobalPlugin(globalPluginHandler.GlobalPlugin):
655

756
def __init__(self, *args, **kwargs):
857
super().__init__(*args, **kwargs)
58+
# Defensive: confirm we're bound to NVDA's real module
59+
try:
60+
modpath = getattr(speech, "__file__", "")
61+
if not modpath or "nvda" not in modpath.lower():
62+
raise RuntimeError(f"Unexpected 'speech' module import: {modpath}")
63+
except Exception:
64+
# If this triggers, there’s still a name collision.
65+
pass
66+
self._reg = speech.filter_speechSequence.register(_filter_sequence)
967
appModuleHandler.registerExecutableWithAppModule("spcsadm", "vismaAdmin")
1068
appModuleHandler.registerExecutableWithAppModule("spcsfkt", "vismaAdmin")
1169
appModuleHandler.registerExecutableWithAppModule("spcsfor", "vismaAdmin")
1270

71+
1372
def terminate(self, *args, **kwargs):
1473
super().terminate(*args, **kwargs)
1574
appModuleHandler.unregisterExecutable("spcsadm")
1675
appModuleHandler.unregisterExecutable("spcsfkt")
1776
appModuleHandler.unregisterExecutable("spcsfor")
77+
try:
78+
self._reg.remove()
79+
except:
80+
pass
81+

buildVars.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def _(arg):
2525
# Translators: Long description to be shown for this add-on on add-on information from add-ons manager
2626
"addon_description": _("""Fixes accessibility issues in Visma Administration/Fakturering/forening."""),
2727
# version
28-
"addon_version": "2025.1.4",
28+
"addon_version": "2025.1.5",
2929
# Brief changelog for this version
3030
# Translators: what's new content for the add-on version to be shown in the add-on store
31-
"addon_changelog": _("""Kortvyn för beställningar har fått tillgängliga etiketter.."""),
31+
"addon_changelog": _("""Irriterande upprepning av texten 'ruta' filtreras bort."""),
3232
# Author(s)
3333
"addon_author": "Karl-Otto Rosenqvist <karl-otto@mawingu.se>",
3434
# URL for the add-on documentation support

0 commit comments

Comments
 (0)