Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor of sayAllHandler into speech #12251

Merged
merged 3 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/NVDAHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ def nvdaControllerInternal_inputLangChangeNotify(threadID,hkl,layoutString):
#But threadIDs for console windows are always wrong so don't ignore for those.
if not isinstance(focus,NVDAObjects.window.Window) or (threadID!=focus.windowThreadID and focus.windowClassName!="ConsoleWindowClass"):
return 0
import sayAllHandler
from speech import sayAll
#Never announce changes while in sayAll (#1676)
if sayAllHandler.isRunning():
if sayAll.SayAllHandler.isRunning():
return 0
import queueHandler
import ui
Expand Down
8 changes: 5 additions & 3 deletions source/NVDAObjects/IAccessible/winword.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
from NVDAObjects.window import DisplayModelEditableText
from ..behaviors import EditableTextWithoutAutoSelectDetection
from NVDAObjects.window.winword import *
from NVDAObjects.window.winword import WordDocumentTreeInterceptor
from speech import sayAll


class WordDocument(IAccessible,EditableTextWithoutAutoSelectDetection,WordDocument):

Expand Down Expand Up @@ -362,15 +365,15 @@ def script_nextParagraph(self,gesture):
info._rangeObj.move(wdParagraph,1)
info.updateCaret()
self._caretScriptPostMovedHelper(textInfos.UNIT_PARAGRAPH,gesture,None)
script_nextParagraph.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_nextParagraph.resumeSayAllMode = sayAll.CURSOR.CARET

def script_previousParagraph(self,gesture):
info=self.makeTextInfo(textInfos.POSITION_CARET)
# #4375: keeping cemetrical with nextParagraph script.
info._rangeObj.move(wdParagraph,-1)
info.updateCaret()
self._caretScriptPostMovedHelper(textInfos.UNIT_PARAGRAPH,gesture,None)
script_previousParagraph.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_previousParagraph.resumeSayAllMode = sayAll.CURSOR.CARET

def focusOnActiveDocument(self, officeChartObject):
rangeStart=officeChartObject.Parent.Range.Start
Expand Down Expand Up @@ -462,4 +465,3 @@ def event_gainFocus(self):
ctypes.windll.user32.AttachThreadInput(curThreadID,document.windowThreadID,False)
if not document.WinwordWindowObject.active:
document.WinwordWindowObject.activate()

3 changes: 1 addition & 2 deletions source/NVDAObjects/window/winword.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import locale
import collections
import colorsys
import sayAllHandler
import eventHandler
import braille
from scriptHandler import script
Expand Down Expand Up @@ -946,7 +945,7 @@ def collapse(self,end=False):
newEndOffset = self._rangeObj.end
# the new endOffset should not have become smaller than the old endOffset, this could cause an infinite loop in
# a case where you called move end then collapse until the size of the range is no longer being reduced.
# For an example of this see sayAll (specifically readTextHelper_generator in sayAllHandler.py)
# For an example of this see sayAll (specifically readTextHelper_generator in sayAll.py)
if newEndOffset < oldEndOffset :
raise RuntimeError

Expand Down
4 changes: 2 additions & 2 deletions source/appModules/eclipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import braille
import ui
import api
import sayAllHandler
from speech import sayAll
import eventHandler
import keyboardHandler
from scriptHandler import script
Expand Down Expand Up @@ -98,7 +98,7 @@ def script_readDocumentation(self, gesture):
if documentObj.role == controlTypes.ROLE_DOCUMENT:
api.setNavigatorObject(documentObj)
braille.handler.handleReviewMove()
sayAllHandler.readText(sayAllHandler.CURSOR_REVIEW)
sayAll.SayAllHandler.readText(sayAll.CURSOR.REVIEW)

elif documentObj.role == controlTypes.ROLE_EDITABLETEXT:
ui.message(documentObj.value)
Expand Down
6 changes: 3 additions & 3 deletions source/appModules/kindle.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from comtypes.hresult import S_OK
import appModuleHandler
import speech
import sayAllHandler
from speech import sayAll
import api
from scriptHandler import willSayAllResume, isScriptWaiting
import controlTypes
Expand Down Expand Up @@ -106,11 +106,11 @@ def _changePageScriptHelper(self,gesture,previous=False):

def script_moveByPage_forward(self,gesture):
self._changePageScriptHelper(gesture)
script_moveByPage_forward.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_moveByPage_forward.resumeSayAllMode = sayAll.CURSOR.CARET

def script_moveByPage_back(self,gesture):
self._changePageScriptHelper(gesture,previous=True)
script_moveByPage_back.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_moveByPage_back.resumeSayAllMode = sayAll.CURSOR.CARET

def _tabOverride(self,direction):
return False
Expand Down
4 changes: 2 additions & 2 deletions source/appModules/powerpnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import colors
import api
import speech
import sayAllHandler
from speech import sayAll
import NVDAHelper
import winUser
import msoAutoShapeTypes
Expand Down Expand Up @@ -1097,7 +1097,7 @@ def makeTextInfo(self,position):

def reportNewSlide(self):
self.makeTextInfo(textInfos.POSITION_FIRST).updateCaret()
sayAllHandler.readText(sayAllHandler.CURSOR_CARET)
sayAll.SayAllHandler.readText(sayAll.CURSOR.CARET)

def script_toggleNotesMode(self,gesture):
self.rootNVDAObject.notesMode=not self.rootNVDAObject.notesMode
Expand Down
14 changes: 7 additions & 7 deletions source/browseMode.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import braille
import vision
import speech
import sayAllHandler
from speech import sayAll
import treeInterceptorHandler
import inputCore
import api
Expand Down Expand Up @@ -470,7 +470,7 @@ def addQuickNav(
script = lambda self,gesture: self._quickNavScript(gesture, itemType, "next", nextError, readUnit)
script.__doc__ = nextDoc
script.__name__ = funcName
script.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script.resumeSayAllMode = sayAll.CURSOR.CARET
setattr(cls, funcName, script)
if key is not None:
cls.__gestures["kb:%s" % key] = scriptName
Expand All @@ -479,7 +479,7 @@ def addQuickNav(
script = lambda self,gesture: self._quickNavScript(gesture, itemType, "previous", prevError, readUnit)
script.__doc__ = prevDoc
script.__name__ = funcName
script.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script.resumeSayAllMode = sayAll.CURSOR.CARET
setattr(cls, funcName, script)
if key is not None:
cls.__gestures["kb:shift+%s" % key] = scriptName
Expand Down Expand Up @@ -1287,7 +1287,7 @@ def event_treeInterceptor_gainFocus(self):
if not self.passThrough:
if doSayAll:
speech.speakObjectProperties(self.rootNVDAObject, name=True, states=True, reason=OutputReason.FOCUS)
sayAllHandler.readText(sayAllHandler.CURSOR_CARET)
sayAll.SayAllHandler.readText(sayAll.CURSOR.CARET)
else:
# Speak it like we would speak focus on any other document object.
# This includes when entering the treeInterceptor for the first time:
Expand Down Expand Up @@ -1590,7 +1590,7 @@ def event_gainFocus(self, obj, nextHandler):
# The virtual caret is not within the focus node.
oldPassThrough=self.passThrough
passThrough = self.shouldPassThrough(obj, reason=OutputReason.FOCUS)
if not oldPassThrough and (passThrough or sayAllHandler.isRunning()):
if not oldPassThrough and (passThrough or sayAll.SayAllHandler.isRunning()):
# If pass-through is disabled, cancel speech, as a focus change should cause page reading to stop.
# This must be done before auto-pass-through occurs, as we want to stop page reading even if pass-through will be automatically enabled by this focus change.
speech.cancelSpeech()
Expand Down Expand Up @@ -1821,7 +1821,7 @@ def script_moveToStartOfContainer(self,gesture):
if not willSayAllResume(gesture):
container.expand(textInfos.UNIT_LINE)
speech.speakTextInfo(container, reason=OutputReason.FOCUS)
script_moveToStartOfContainer.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_moveToStartOfContainer.resumeSayAllMode = sayAll.CURSOR.CARET
# Translators: Description for the Move to start of container command in browse mode.
script_moveToStartOfContainer.__doc__=_("Moves to the start of the container element, such as a list or table")

Expand All @@ -1846,7 +1846,7 @@ def script_movePastEndOfContainer(self,gesture):
if not willSayAllResume(gesture):
container.expand(textInfos.UNIT_LINE)
speech.speakTextInfo(container, reason=OutputReason.FOCUS)
script_movePastEndOfContainer.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_movePastEndOfContainer.resumeSayAllMode = sayAll.CURSOR.CARET
# Translators: Description for the Move past end of container command in browse mode.
script_movePastEndOfContainer.__doc__=_("Moves past the end of the container element, such as a list or table")

Expand Down
3 changes: 3 additions & 0 deletions source/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ def main():
import speech
log.debug("Initializing speech")
speech.initialize()
from speech import sayAll
log.debug("Initializing sayAllHandler")
sayAll.initialize()
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
22 changes: 11 additions & 11 deletions source/cursorManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import gui
from gui import guiHelper
import gui.contextHelp
import sayAllHandler
from speech import sayAll
import review
from scriptHandler import willSayAllResume, script
import textInfos
Expand Down Expand Up @@ -197,7 +197,7 @@ def run():
"find the next occurrence of the previously entered text string from the current cursor's position"
),
gesture="kb:NVDA+f3",
resumeSayAllMode=sayAllHandler.CURSOR_CARET,
resumeSayAllMode=sayAll.CURSOR.CARET,
)
def script_findNext(self,gesture):
if not self._lastFindText:
Expand All @@ -215,7 +215,7 @@ def script_findNext(self,gesture):
"find the previous occurrence of the previously entered text string from the current cursor's position"
),
gesture="kb:NVDA+shift+f3",
resumeSayAllMode=sayAllHandler.CURSOR_CARET,
resumeSayAllMode=sayAll.CURSOR.CARET,
)
def script_findPrevious(self,gesture):
if not self._lastFindText:
Expand All @@ -230,11 +230,11 @@ def script_findPrevious(self,gesture):

def script_moveByPage_back(self,gesture):
self._caretMovementScriptHelper(gesture,textInfos.UNIT_LINE,-config.conf["virtualBuffers"]["linesPerPage"],extraDetail=False)
script_moveByPage_back.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_moveByPage_back.resumeSayAllMode = sayAll.CURSOR.CARET

def script_moveByPage_forward(self,gesture):
self._caretMovementScriptHelper(gesture,textInfos.UNIT_LINE,config.conf["virtualBuffers"]["linesPerPage"],extraDetail=False)
script_moveByPage_forward.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_moveByPage_forward.resumeSayAllMode = sayAll.CURSOR.CARET

def script_moveByCharacter_back(self,gesture):
self._caretMovementScriptHelper(gesture,textInfos.UNIT_CHARACTER,-1,extraDetail=True,handleSymbols=True)
Expand All @@ -250,27 +250,27 @@ def script_moveByWord_forward(self,gesture):

def script_moveByLine_back(self,gesture):
self._caretMovementScriptHelper(gesture,textInfos.UNIT_LINE,-1)
script_moveByLine_back.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_moveByLine_back.resumeSayAllMode = sayAll.CURSOR.CARET

def script_moveByLine_forward(self,gesture):
self._caretMovementScriptHelper(gesture,textInfos.UNIT_LINE,1)
script_moveByLine_forward.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_moveByLine_forward.resumeSayAllMode = sayAll.CURSOR.CARET

def script_moveBySentence_back(self,gesture):
self._caretMovementScriptHelper(gesture,textInfos.UNIT_SENTENCE,-1)
script_moveBySentence_back.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_moveBySentence_back.resumeSayAllMode = sayAll.CURSOR.CARET

def script_moveBySentence_forward(self,gesture):
self._caretMovementScriptHelper(gesture,textInfos.UNIT_SENTENCE,1)
script_moveBySentence_forward.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_moveBySentence_forward.resumeSayAllMode = sayAll.CURSOR.CARET

def script_moveByParagraph_back(self,gesture):
self._caretMovementScriptHelper(gesture,textInfos.UNIT_PARAGRAPH,-1)
script_moveByParagraph_back.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_moveByParagraph_back.resumeSayAllMode = sayAll.CURSOR.CARET

def script_moveByParagraph_forward(self,gesture):
self._caretMovementScriptHelper(gesture,textInfos.UNIT_PARAGRAPH,1)
script_moveByParagraph_forward.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_moveByParagraph_forward.resumeSayAllMode = sayAll.CURSOR.CARET

def script_startOfLine(self,gesture):
self._caretMovementScriptHelper(gesture,textInfos.UNIT_CHARACTER,posUnit=textInfos.UNIT_LINE,extraDetail=True,handleSymbols=True)
Expand Down
12 changes: 6 additions & 6 deletions source/editableText.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

import time
import sayAllHandler
from speech import sayAll
import api
import review
from baseObject import ScriptableObject
Expand Down Expand Up @@ -222,7 +222,7 @@ def _caretMoveBySentenceHelper(self, gesture, direction):

def script_caret_moveByLine(self,gesture):
self._caretMovementScriptHelper(gesture, textInfos.UNIT_LINE)
script_caret_moveByLine.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_caret_moveByLine.resumeSayAllMode = sayAll.CURSOR.CARET

def script_caret_moveByCharacter(self,gesture):
self._caretMovementScriptHelper(gesture, textInfos.UNIT_CHARACTER)
Expand All @@ -232,15 +232,15 @@ def script_caret_moveByWord(self,gesture):

def script_caret_moveByParagraph(self,gesture):
self._caretMovementScriptHelper(gesture, textInfos.UNIT_PARAGRAPH)
script_caret_moveByParagraph.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_caret_moveByParagraph.resumeSayAllMode = sayAll.CURSOR.CARET

def script_caret_previousSentence(self,gesture):
self._caretMoveBySentenceHelper(gesture, -1)
script_caret_previousSentence.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_caret_previousSentence.resumeSayAllMode = sayAll.CURSOR.CARET

def script_caret_nextSentence(self,gesture):
self._caretMoveBySentenceHelper(gesture, 1)
script_caret_nextSentence.resumeSayAllMode=sayAllHandler.CURSOR_CARET
script_caret_nextSentence.resumeSayAllMode = sayAll.CURSOR.CARET

def _backspaceScriptHelper(self,unit,gesture):
try:
Expand Down Expand Up @@ -394,7 +394,7 @@ def script_caret_changeSelection(self,gesture):
try:
self.reportSelectionChange(oldInfo)
except:
return
return

__changeSelectionGestures = (
"kb:shift+upArrow",
Expand Down
12 changes: 6 additions & 6 deletions source/globalCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import api
import textInfos
import speech
import sayAllHandler
from speech import sayAll
from NVDAObjects import NVDAObject, NVDAObjectTextInfo
import globalVars
from logHandler import log
Expand Down Expand Up @@ -1253,7 +1253,7 @@ def script_review_top(self,gesture):
@script(
# Translators: Input help mode message for move review cursor to previous line command.
description=_("Moves the review cursor to the previous line of the current navigator object and speaks it"),
resumeSayAllMode=sayAllHandler.CURSOR_REVIEW,
resumeSayAllMode=sayAll.CURSOR.REVIEW,
category=SCRCAT_TEXTREVIEW,
gestures=("kb:numpad7", "kb(laptop):NVDA+upArrow", "ts(text):flickUp")
)
Expand Down Expand Up @@ -1294,7 +1294,7 @@ def script_review_currentLine(self,gesture):
@script(
# Translators: Input help mode message for move review cursor to next line command.
description=_("Moves the review cursor to the next line of the current navigator object and speaks it"),
resumeSayAllMode=sayAllHandler.CURSOR_REVIEW,
resumeSayAllMode=sayAll.CURSOR.REVIEW,
category=SCRCAT_TEXTREVIEW,
gestures=("kb:numpad9", "kb(laptop):NVDA+downArrow", "ts(text):flickDown")
)
Expand Down Expand Up @@ -1675,7 +1675,7 @@ def script_showGui(self,gesture):
gestures=("kb:numpadPlus", "kb(laptop):NVDA+shift+a", "ts(text):3finger_flickDown")
)
def script_review_sayAll(self,gesture):
sayAllHandler.readText(sayAllHandler.CURSOR_REVIEW)
sayAll.SayAllHandler.readText(sayAll.CURSOR.REVIEW)

@script(
# Translators: Input help mode message for say all with system caret command.
Expand All @@ -1684,7 +1684,7 @@ def script_review_sayAll(self,gesture):
gestures=("kb(desktop):NVDA+downArrow", "kb(laptop):NVDA+a")
)
def script_sayAll(self,gesture):
sayAllHandler.readText(sayAllHandler.CURSOR_CARET)
sayAll.SayAllHandler.readText(sayAll.CURSOR.CARET)

def _reportFormattingHelper(self, info, browseable=False):
# Report all formatting-related changes regardless of user settings
Expand Down Expand Up @@ -1991,7 +1991,7 @@ def script_title(self,gesture):
def script_speakForeground(self,gesture):
obj=api.getForegroundObject()
if obj:
sayAllHandler.readObjects(obj)
sayAll.SayAllHandler.readObjects(obj)

@script(
gesture="kb(desktop):NVDA+control+f2"
Expand Down
6 changes: 3 additions & 3 deletions source/inputCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from typing import Dict, Any, Tuple, List, Union

import configobj
import sayAllHandler
from speech import sayAll
import baseObject
import scriptHandler
import queueHandler
Expand Down Expand Up @@ -455,12 +455,12 @@ def executeGesture(self, gesture):
wasInSayAll=False
if gesture.isModifier:
if not self.lastModifierWasInSayAll:
wasInSayAll=self.lastModifierWasInSayAll=sayAllHandler.isRunning()
wasInSayAll = self.lastModifierWasInSayAll = sayAll.SayAllHandler.isRunning()
elif self.lastModifierWasInSayAll:
wasInSayAll=True
self.lastModifierWasInSayAll=False
else:
wasInSayAll=sayAllHandler.isRunning()
wasInSayAll = sayAll.SayAllHandler.isRunning()
if wasInSayAll:
gesture.wasInSayAll=True

Expand Down
Loading