Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Add names for callback commands to give context in logging.
  • Loading branch information
feerrenrut committed Jan 29, 2020
commit e7a18f52c9ca5674fa8726be60082493fc900c9d
11 changes: 7 additions & 4 deletions source/sayAllHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def next(self):
if not obj:
return
# Call this method again when we start speaking this object.
callbackCommand = speech.CallbackCommand(self.next)
callbackCommand = speech.CallbackCommand(self.next, name="say-all:next")
speech.speakObject(obj, reason=controlTypes.REASON_SAYALL, _prefixSpeechCommand=callbackCommand)

def stop(self):
Expand Down Expand Up @@ -135,14 +135,17 @@ def nextLine(self):
# No more text.
if isinstance(self.reader.obj, textInfos.DocumentWithPageTurns):
# Once the last line finishes reading, try turning the page.
cb = speech.CallbackCommand(self.turnPage)
cb = speech.CallbackCommand(self.turnPage, name="say-all:turnPage")
speech.speakWithoutPauses([cb, speech.EndUtteranceCommand()])
else:
self.finish()
return
# Call lineReached when we start speaking this line.
# lineReached will move the cursor and trigger reading of the next line.
cb = speech.CallbackCommand(lambda obj=self.reader.obj, state=self.speakTextInfoState.copy(): self.lineReached(obj,bookmark, state))
cb = speech.CallbackCommand(
lambda obj=self.reader.obj, state=self.speakTextInfoState.copy(): self.lineReached(obj, bookmark, state),
name="say-all:lineReached"
)
spoke = speech.speakTextInfo(self.reader, unit=textInfos.UNIT_READINGCHUNK,
reason=controlTypes.REASON_SAYALL, _prefixSpeechCommand=cb,
useCache=self.speakTextInfoState)
Expand Down Expand Up @@ -198,7 +201,7 @@ def finish(self):
# Otherwise, if a different synth is being used for say all,
# we might switch synths too early and truncate the final speech.
# We do this by putting a CallbackCommand at the start of a new utterance.
cb = speech.CallbackCommand(self.stop)
cb = speech.CallbackCommand(self.stop, name="say-all:stop")
speech.speakWithoutPauses([speech.EndUtteranceCommand(), cb,
speech.EndUtteranceCommand()])

Expand Down
8 changes: 7 additions & 1 deletion source/speech/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,18 @@ class CallbackCommand(BaseCallbackCommand):
otherwise it will block production of further speech and or other functionality in NVDA.
"""

def __init__(self, callback):
def __init__(self, callback, name: Optional[str] = None):
self._callback = callback
self._name = name if name else repr(callback)

def run(self,*args, **kwargs):
return self._callback(*args,**kwargs)

def __repr__(self):
return "CallbackCommand(name={name})".format(
name=self._name
)

class BeepCommand(BaseCallbackCommand):
"""Produce a beep.
"""
Expand Down