Skip to content

Commit

Permalink
Merge 21f0a9f into 8938ca4
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbudd authored May 12, 2021
2 parents 8938ca4 + 21f0a9f commit 73fdb7b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
7 changes: 6 additions & 1 deletion source/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,12 @@ def main():
speech.initialize()
from speech import sayAll
log.debug("Initializing sayAllHandler")
sayAll.initialize()
sayAll.initialize(
speech.speak,
speech.speakObject,
speech.getTextInfoSpeech,
speech.SpeakTextInfoState,
)
if not globalVars.appArgs.minimal and (time.time()-globalVars.startTime)>5:
log.debugWarning("Slow starting core (%.2f sec)" % (time.time()-globalVars.startTime))
# Translators: This is spoken when NVDA is starting.
Expand Down
7 changes: 4 additions & 3 deletions source/documentBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#See the file COPYING for more details.

from baseObject import AutoPropertyObject, ScriptableObject
from scriptHandler import isScriptWaiting
import config
import textInfos
import speech
Expand Down Expand Up @@ -141,6 +140,10 @@ def _getNearestTableCell(self, tableID, startPos, origRow, origCol, origRowSpan,
raise LookupError

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


4 changes: 0 additions & 4 deletions source/scriptHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@
from typing import List, Optional
import time
import weakref
import inspect
import types
import config
import speech
from speech import sayAll
import appModuleHandler
import api
import queueHandler
from logHandler import log
import inputCore
import globalPluginHandler
import braille
import vision
import keyLabels
import baseObject

_numScriptsQueued=0 #Number of scripts that are queued to be executed
Expand Down
2 changes: 2 additions & 0 deletions source/speech/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
speakSpelling,
speakText,
speakTextInfo,
SpeakTextInfoState,
speakTextSelected,
speakTypedCharacters,
SpeechMode,
Expand Down Expand Up @@ -132,6 +133,7 @@
"speakSpelling",
"speakText",
"speakTextInfo",
"SpeakTextInfoState",
"speakTextSelected",
"speakTypedCharacters",
"SpeechMode",
Expand Down
49 changes: 36 additions & 13 deletions source/speech/sayAll.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
# Julien Cochuyt

from enum import IntEnum
from typing import TYPE_CHECKING
from typing import Callable, TYPE_CHECKING
import weakref
import garbageHandler
from .speech import (
speak,
getTextInfoSpeech,
SpeakTextInfoState,
speakObject,
)
from logHandler import log
import config
import controlTypes
Expand All @@ -26,11 +20,17 @@
from .speechWithoutPauses import SpeechWithoutPauses

from .types import (
SpeechSequence,
_flattenNestedSequences,
)

if TYPE_CHECKING:
import NVDAObjects
from .speech import (
getTextInfoSpeech,
SpeakTextInfoState,
speakObject,
)


class CURSOR(IntEnum):
Expand All @@ -41,18 +41,37 @@ class CURSOR(IntEnum):
SayAllHandler = None


def initialize():
def initialize(
speakFunc: Callable[[SpeechSequence], None],
speakObject: 'speakObject',
getTextInfoSpeech: 'getTextInfoSpeech',
SpeakTextInfoState: 'SpeakTextInfoState',
):
global SayAllHandler
SayAllHandler = _SayAllHandler(SpeechWithoutPauses(speakFunc=speak))
SayAllHandler = _SayAllHandler(
SpeechWithoutPauses(speakFunc=speakFunc),
speakObject,
getTextInfoSpeech,
SpeakTextInfoState,
)


class _SayAllHandler:
def __init__(self, speechWithoutPausesInstance: SpeechWithoutPauses):
def __init__(
self,
speechWithoutPausesInstance: SpeechWithoutPauses,
speakObject: 'speakObject',
getTextInfoSpeech: 'getTextInfoSpeech',
SpeakTextInfoState: 'SpeakTextInfoState',
):
self.lastSayAllMode = None
self.speechWithoutPausesInstance = speechWithoutPausesInstance
#: The active say all manager.
#: This is a weakref because the manager should be allowed to die once say all is complete.
self._getActiveSayAll = lambda: None # noqa: Return None when called like a dead weakref.
self._speakObject = speakObject
self._getTextInfoSpeech = getTextInfoSpeech
self._makeSpeakTextInfoState = SpeakTextInfoState

def stop(self):
'''
Expand Down Expand Up @@ -115,7 +134,11 @@ def next(self):
return
# Call this method again when we start speaking this object.
callbackCommand = CallbackCommand(self.next, name="say-all:next")
speakObject(obj, reason=controlTypes.OutputReason.SAYALL, _prefixSpeechCommand=callbackCommand)
SayAllHandler._speakObject(
obj,
reason=controlTypes.OutputReason.SAYALL,
_prefixSpeechCommand=callbackCommand
)

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

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

0 comments on commit 73fdb7b

Please sign in to comment.