Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fixing sayAll in BookWorm
  • Loading branch information
mltony committed Aug 26, 2022
commit eeb86dadc806fed96013ac0d73bc99684e435914
30 changes: 21 additions & 9 deletions source/speech/sayAll.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,6 @@ def nextLineImpl(self) -> bool:
Advances cursor to the next reading chunk (e.g. paragraph).
@return: C{True} if advanced successfully, C{False} otherwise.
"""
# Collapse to the end of this line, ready to read the next.
try:
self.reader.collapse(end=True)
except RuntimeError:
# This occurs in Microsoft Word when the range covers the end of the document.
# without this exception to indicate that further collapsing is not possible,
# say all could enter an infinite loop.

return False
# Expand to the current line.
# We use move end rather than expand
# because the user might start in the middle of a line
Expand All @@ -239,6 +230,21 @@ def nextLineImpl(self) -> bool:
return False
return True

def collapseLineImpl(self) -> bool:
"""
Collapses to the end of this line, ready to read the next.
@return: C{True} if collapsed successfully, C{False} otherwise.
"""
try:
self.reader.collapse(end=True)
return True
except RuntimeError:
# This occurs in Microsoft Word when the range covers the end of the document.
# without this exception to indicate that further collapsing is not possible,
# say all could enter an infinite loop.
self.finish()
return False

def nextLine(self):
if not self.reader:
log.debug("no self.reader")
Expand Down Expand Up @@ -286,6 +292,9 @@ def _onLineReached(obj=self.reader.obj, state=state):
# Update the textInfo state ready for when speaking the next line.
self.speakTextInfoState = state.copy()

if not self.collapseLineImpl():
return

if not spoke:
# This line didn't include a natural pause, so nothing was spoken.
self.numBufferedLines += 1
Expand Down Expand Up @@ -391,6 +400,9 @@ def nextLineImpl(self) -> bool:
except StopIteration:
return False

def collapseLineImpl(self) -> bool:
return True

def shouldReadInitialPosition(self) -> bool:
return True

Expand Down