Skip to content

Commit 73fdb7b

Browse files
authored
Merge 21f0a9f into 8938ca4
2 parents 8938ca4 + 21f0a9f commit 73fdb7b

5 files changed

Lines changed: 48 additions & 21 deletions

File tree

source/core.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,12 @@ def main():
353353
speech.initialize()
354354
from speech import sayAll
355355
log.debug("Initializing sayAllHandler")
356-
sayAll.initialize()
356+
sayAll.initialize(
357+
speech.speak,
358+
speech.speakObject,
359+
speech.getTextInfoSpeech,
360+
speech.SpeakTextInfoState,
361+
)
357362
if not globalVars.appArgs.minimal and (time.time()-globalVars.startTime)>5:
358363
log.debugWarning("Slow starting core (%.2f sec)" % (time.time()-globalVars.startTime))
359364
# Translators: This is spoken when NVDA is starting.

source/documentBase.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#See the file COPYING for more details.
55

66
from baseObject import AutoPropertyObject, ScriptableObject
7-
from scriptHandler import isScriptWaiting
87
import config
98
import textInfos
109
import speech
@@ -141,6 +140,10 @@ def _getNearestTableCell(self, tableID, startPos, origRow, origCol, origRowSpan,
141140
raise LookupError
142141

143142
def _tableMovementScriptHelper(self, movement="next", axis=None):
143+
# documentBase shouldn't depend on scriptHandler
144+
# documentBase is a core module and should not depend on UI classes
145+
# this function should be somewhere else or dependency injected
146+
from scriptHandler import isScriptWaiting
144147
if isScriptWaiting():
145148
return
146149
formatConfig=config.conf["documentFormatting"].copy()
@@ -205,5 +208,3 @@ def script_toggleIncludeLayoutTables(self,gesture):
205208
"kb:control+alt+rightArrow": "nextColumn",
206209
"kb:control+alt+leftArrow": "previousColumn",
207210
}
208-
209-

source/scriptHandler.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@
66
from typing import List, Optional
77
import time
88
import weakref
9-
import inspect
109
import types
1110
import config
12-
import speech
1311
from speech import sayAll
14-
import appModuleHandler
1512
import api
1613
import queueHandler
1714
from logHandler import log
1815
import inputCore
1916
import globalPluginHandler
2017
import braille
2118
import vision
22-
import keyLabels
2319
import baseObject
2420

2521
_numScriptsQueued=0 #Number of scripts that are queued to be executed

source/speech/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
speakSpelling,
5656
speakText,
5757
speakTextInfo,
58+
SpeakTextInfoState,
5859
speakTextSelected,
5960
speakTypedCharacters,
6061
SpeechMode,
@@ -132,6 +133,7 @@
132133
"speakSpelling",
133134
"speakText",
134135
"speakTextInfo",
136+
"SpeakTextInfoState",
135137
"speakTextSelected",
136138
"speakTypedCharacters",
137139
"SpeechMode",

source/speech/sayAll.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@
55
# Julien Cochuyt
66

77
from enum import IntEnum
8-
from typing import TYPE_CHECKING
8+
from typing import Callable, TYPE_CHECKING
99
import weakref
1010
import garbageHandler
11-
from .speech import (
12-
speak,
13-
getTextInfoSpeech,
14-
SpeakTextInfoState,
15-
speakObject,
16-
)
1711
from logHandler import log
1812
import config
1913
import controlTypes
@@ -26,11 +20,17 @@
2620
from .speechWithoutPauses import SpeechWithoutPauses
2721

2822
from .types import (
23+
SpeechSequence,
2924
_flattenNestedSequences,
3025
)
3126

3227
if TYPE_CHECKING:
3328
import NVDAObjects
29+
from .speech import (
30+
getTextInfoSpeech,
31+
SpeakTextInfoState,
32+
speakObject,
33+
)
3434

3535

3636
class CURSOR(IntEnum):
@@ -41,18 +41,37 @@ class CURSOR(IntEnum):
4141
SayAllHandler = None
4242

4343

44-
def initialize():
44+
def initialize(
45+
speakFunc: Callable[[SpeechSequence], None],
46+
speakObject: 'speakObject',
47+
getTextInfoSpeech: 'getTextInfoSpeech',
48+
SpeakTextInfoState: 'SpeakTextInfoState',
49+
):
4550
global SayAllHandler
46-
SayAllHandler = _SayAllHandler(SpeechWithoutPauses(speakFunc=speak))
51+
SayAllHandler = _SayAllHandler(
52+
SpeechWithoutPauses(speakFunc=speakFunc),
53+
speakObject,
54+
getTextInfoSpeech,
55+
SpeakTextInfoState,
56+
)
4757

4858

4959
class _SayAllHandler:
50-
def __init__(self, speechWithoutPausesInstance: SpeechWithoutPauses):
60+
def __init__(
61+
self,
62+
speechWithoutPausesInstance: SpeechWithoutPauses,
63+
speakObject: 'speakObject',
64+
getTextInfoSpeech: 'getTextInfoSpeech',
65+
SpeakTextInfoState: 'SpeakTextInfoState',
66+
):
5167
self.lastSayAllMode = None
5268
self.speechWithoutPausesInstance = speechWithoutPausesInstance
5369
#: The active say all manager.
5470
#: This is a weakref because the manager should be allowed to die once say all is complete.
5571
self._getActiveSayAll = lambda: None # noqa: Return None when called like a dead weakref.
72+
self._speakObject = speakObject
73+
self._getTextInfoSpeech = getTextInfoSpeech
74+
self._makeSpeakTextInfoState = SpeakTextInfoState
5675

5776
def stop(self):
5877
'''
@@ -115,7 +134,11 @@ def next(self):
115134
return
116135
# Call this method again when we start speaking this object.
117136
callbackCommand = CallbackCommand(self.next, name="say-all:next")
118-
speakObject(obj, reason=controlTypes.OutputReason.SAYALL, _prefixSpeechCommand=callbackCommand)
137+
SayAllHandler._speakObject(
138+
obj,
139+
reason=controlTypes.OutputReason.SAYALL,
140+
_prefixSpeechCommand=callbackCommand
141+
)
119142

120143
def stop(self):
121144
self.walker = None
@@ -158,7 +181,7 @@ def __init__(self, handler: _SayAllHandler, cursor: CURSOR):
158181
self.reader = api.getReviewPosition()
159182
# #10899: SayAll profile can't be activated earlier because they may not be anything to read
160183
self.trigger.enter()
161-
self.speakTextInfoState = SpeakTextInfoState(self.reader.obj)
184+
self.speakTextInfoState = SayAllHandler._makeSpeakTextInfoState(self.reader.obj)
162185
self.numBufferedLines = 0
163186

164187
def nextLine(self):
@@ -207,7 +230,7 @@ def _onLineReached(obj=self.reader.obj, state=state):
207230
# and insert the lineReached callback at the very beginning of the sequence.
208231
# _linePrefix on speakTextInfo cannot be used here
209232
# As it would be inserted in the sequence after all initial control starts which is too late.
210-
speechGen = getTextInfoSpeech(
233+
speechGen = SayAllHandler._getTextInfoSpeech(
211234
self.reader,
212235
unit=textInfos.UNIT_READINGCHUNK,
213236
reason=controlTypes.OutputReason.SAYALL,

0 commit comments

Comments
 (0)