Skip to content

Commit 3073ea0

Browse files
authored
Merge 5c16112 into b880d36
2 parents b880d36 + 5c16112 commit 3073ea0

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

source/contentRecog/recogUi.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2017-2023 NV Access Limited, James Teh, Leonard de RUijter
2+
# Copyright (C) 2017-2025 NV Access Limited, James Teh, Leonard de Ruijter, Cyrille Bougot
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

@@ -10,7 +10,7 @@
1010
NVDA scripts or GUI call the L{recognizeNavigatorObject} function with the recognizer they wish to use.
1111
"""
1212

13-
from typing import Optional, Union
13+
from typing import Optional, Union, TYPE_CHECKING
1414
import api
1515
import ui
1616
import screenBitmap
@@ -24,8 +24,12 @@
2424
from logHandler import log
2525
import queueHandler
2626
import core
27+
from scriptHandler import script
2728
from . import RecogImageInfo, ContentRecognizer, RecognitionResult, onRecognizeResultCallbackT
2829

30+
if TYPE_CHECKING:
31+
import inputCore
32+
2933

3034
class RecogResultNVDAObject(cursorManager.CursorManager, NVDAObjects.window.Window):
3135
"""Fake NVDAObject used to present a recognition result in a cursor manager.
@@ -109,7 +113,7 @@ def script_findPrevious(self, gesture):
109113

110114
class RefreshableRecogResultNVDAObject(RecogResultNVDAObject, LiveText):
111115
"""NVDA Object that itself is responsible for fetching the recognizition result.
112-
It is also able to refresh the result at intervals whenthe recognizer supports it.
116+
It is also able to refresh the result at intervals or on demand when the recognizer supports it.
113117
"""
114118

115119
def __init__(
@@ -162,17 +166,30 @@ def _onFirstResult(self, result: Union[RecognitionResult, Exception]):
162166
def _scheduleRecognize(self):
163167
core.callLater(self.recognizer.autoRefreshInterval, self._recognize, self._onResult)
164168

169+
@script(
170+
# Translators: Describes a command.
171+
description=_("Refresh the recognition result"),
172+
gesture="kb:f5",
173+
)
174+
def script_refreshRecogContent(self, gesture: "inputCore.InputGesture") -> None:
175+
if self.recognizer.allowAutoRefresh:
176+
# Translators: Reported when a manual update of a content recognition result (e.g. OCR result) is
177+
# requested, but the content is already updated automatically.
178+
ui.message(_("The result of content recognition is already automatically updated"))
179+
return
180+
core.callLater(0, self._recognize, self._onResult)
181+
165182
def _onResult(self, result: Union[RecognitionResult, Exception]):
166183
if not self.hasFocus:
167184
# The user has dismissed the recognition result.
168185
return
169186
if isinstance(result, Exception):
170-
log.error(f"Subsequent recognition failed: {result}")
187+
log.error(f"Refresh recognition failed: {result}")
171188
queueHandler.queueFunction(
172189
queueHandler.eventQueue,
173190
ui.message,
174191
# Translators: Reported when recognition (e.g. OCR) fails during automatic refresh.
175-
_("Automatic refresh of recognition result failed"),
192+
_("Refresh of recognition result failed"),
176193
)
177194
self.stopMonitoring()
178195
return
@@ -182,7 +199,8 @@ def _onResult(self, result: Union[RecognitionResult, Exception]):
182199
self.selection = self.makeTextInfo(self._selection.bookmark)
183200
# Tell LiveText that our text has changed.
184201
self.event_textChange()
185-
self._scheduleRecognize()
202+
if self.recognizer.allowAutoRefresh:
203+
self._scheduleRecognize()
186204

187205
def event_gainFocus(self):
188206
super().event_gainFocus()

user_docs/en/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ As a consequence, announcement of first line indent is now supported for LibreOf
4040
This option is enabled by default, but can possibly result in shorter battery life.
4141
If you suspect this option is negatively impacting your battery life, you're advised to disable it. (#17649@LeonarddeR)
4242
* Rate boost is now supported when using Microsoft Speech API version 5 (SAPI5) and Microsoft Speech Platform voices, which supports up to 6X speed. (#17606, @gexgd0419)
43+
* In a recognition result, `f5` allows to manually refresh the recognized content. (#17715, @CyrilleB79)
4344

4445
### Changes
4546

user_docs/en/userGuide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,7 @@ However, you may wish to use object navigation directly to, for example, recogni
14301430
Once recognition is complete, the result will be presented in a document similar to browse mode, allowing you to read the information with cursor keys, etc.
14311431
Pressing enter or space will activate (normally click) the text at the cursor if possible.
14321432
Pressing escape dismisses the recognition result.
1433+
Pressing `f5` refreshes the recognition result.
14331434

14341435
### Windows OCR {#Win10Ocr}
14351436

0 commit comments

Comments
 (0)