Exemple #1
0
def handleInputCandidateListUpdate(candidatesString,selectionIndex,inputMethod):
	candidateStrings=candidatesString.split('\n')
	import speech
	from NVDAObjects.inputComposition import InputComposition, CandidateList, CandidateItem
	focus=api.getFocusObject()
	if not (0<=selectionIndex<len(candidateStrings)):
		if isinstance(focus,CandidateItem):
			oldSpeechMode = speech.getState().speechMode
			speech.setSpeechMode(speech.SpeechMode.off)
			eventHandler.executeEvent("gainFocus",focus.parent)
			speech.setSpeechMode(oldSpeechMode)
		return
	oldCandidateItemsText=None
	if isinstance(focus,CandidateItem):
		oldCandidateItemsText=focus.visibleCandidateItemsText
		parent=focus.parent
		wasCandidate=True
	else:
		parent=focus
		wasCandidate=False
	item=CandidateItem(parent=parent,candidateStrings=candidateStrings,candidateIndex=selectionIndex,inputMethod=inputMethod)
	if wasCandidate and focus.windowHandle==item.windowHandle and focus.candidateIndex==item.candidateIndex and focus.name==item.name:
		return
	if config.conf["inputComposition"]["autoReportAllCandidates"] and item.visibleCandidateItemsText!=oldCandidateItemsText:
		import ui
		ui.message(item.visibleCandidateItemsText)
	eventHandler.executeEvent("gainFocus",item)
Exemple #2
0
def handleInputCompositionStart(compositionString,selectionStart,selectionEnd,isReading):
	import speech
	from NVDAObjects.inputComposition import InputComposition
	from NVDAObjects.behaviors import CandidateItem
	focus=api.getFocusObject()
	if focus.parent and isinstance(focus.parent,InputComposition):
		#Candidates infront of existing composition string
		announce=not config.conf["inputComposition"]["announceSelectedCandidate"]
		focus.parent.compositionUpdate(compositionString,selectionStart,selectionEnd,isReading,announce=announce)
		return 0
	#IME keeps updating input composition while the candidate list is open
	#Therefore ignore new composition updates if candidate selections are configured for speaking.
	if config.conf["inputComposition"]["announceSelectedCandidate"] and isinstance(focus,CandidateItem):
		return 0
	if not isinstance(focus,InputComposition):
		parent=api.getDesktopObject().objectWithFocus()
		# #5640: Although we want to use the most correct focus (I.e. OS, not NVDA), if they are the same, we definitely want to use the original instance, so that state such as auto selection is maintained.
		if parent==focus:
			parent=focus
		curInputComposition=InputComposition(parent=parent)
		oldSpeechMode = speech.getState().speechMode
		speech.setSpeechMode(speech.SpeechMode.off)
		eventHandler.executeEvent("gainFocus",curInputComposition)
		focus=curInputComposition
		speech.setSpeechMode(oldSpeechMode)
	focus.compositionUpdate(compositionString,selectionStart,selectionEnd,isReading)
Exemple #3
0
def handleInputCompositionEnd(result):
    import speech
    import characterProcessing
    from NVDAObjects.inputComposition import InputComposition
    from NVDAObjects.IAccessible.mscandui import ModernCandidateUICandidateItem
    focus = api.getFocusObject()
    result = result.lstrip(u'\u3000 ')
    curInputComposition = None
    if isinstance(focus, InputComposition):
        curInputComposition = focus
        oldSpeechMode = speech.getState().speechMode
        speech.setSpeechMode(speech.SpeechMode.off)
        eventHandler.executeEvent("gainFocus", focus.parent)
        speech.setSpeechMode(oldSpeechMode)
    elif isinstance(focus.parent, InputComposition):
        #Candidate list is still up
        curInputComposition = focus.parent
        focus.parent = focus.parent.parent
    if isinstance(focus, ModernCandidateUICandidateItem):
        # Correct focus for ModernCandidateUICandidateItem
        # Find the InputComposition object and
        # correct focus to its parent
        if isinstance(focus.container, InputComposition):
            curInputComposition = focus.container
            newFocus = curInputComposition.parent
        else:
            # Sometimes InputCompositon object is gone
            # Correct to container of CandidateItem
            newFocus = focus.container
        oldSpeechMode = speech.getState().speechMode
        speech.setSpeechMode(speech.SpeechMode.off)
        eventHandler.executeEvent("gainFocus", newFocus)
        speech.setSpeechMode(oldSpeechMode)

    if curInputComposition and not result:
        result = curInputComposition.compositionString.lstrip(u'\u3000 ')
    if result:
        speech.speakText(result,
                         symbolLevel=characterProcessing.SymbolLevel.ALL)
Exemple #4
0
	def _get_speechEffectWhenExecuted(self):
		if inputCore.manager.isInputHelpActive:
			return self.SPEECHEFFECT_CANCEL
		if self.isExtended and winUser.VK_VOLUME_MUTE <= self.vkCode <= winUser.VK_VOLUME_UP:
			return None
		if self.vkCode == 0xFF:
			# #3468: This key is unknown to Windows.
			# This could be for an event such as gyroscope movement,
			# so don't interrupt speech.
			return None
		if not config.conf['keyboard']['speechInterruptForCharacters'] and (not self.shouldReportAsCommand or self.vkCode in (winUser.VK_SHIFT, winUser.VK_LSHIFT, winUser.VK_RSHIFT)):
			return None
		if self.vkCode==winUser.VK_RETURN and not config.conf['keyboard']['speechInterruptForEnter']:
			return None
		if self.vkCode in (winUser.VK_SHIFT, winUser.VK_LSHIFT, winUser.VK_RSHIFT):
			return self.SPEECHEFFECT_RESUME if speech.getState().isPaused else self.SPEECHEFFECT_PAUSE
		return self.SPEECHEFFECT_CANCEL
Exemple #5
0
def runWithoutUiMessage(func, *args, **kwargs):
    import config
    from versionInfo import version_year as mainVersion
    curSpeechMode = speech.speechMode if mainVersion < 2021 else speech.getState(
    ).speechMode
    configBackup = {
        "voice": curSpeechMode,
        "braille": config.conf["braille"]["messageTimeout"]
    }
    if mainVersion < 2021:
        speech.speechMode = speech.speechMode_off
    else:
        speech.setSpeechMode(speech.SpeechMode.off)
    config.conf["braille"]._cacheLeaf("messageTimeout", None, 0)
    try:
        func(*args, **kwargs)
    finally:
        if mainVersion < 2021:
            speech.speechMode = configBackup["voice"]
        else:
            speech.setSpeechMode(configBackup["voice"])
        config.conf["braille"]._cacheLeaf("messageTimeout", None,
                                          configBackup["braille"])
def getSpeechMode():
    try:
        # for nvda  version >= 2021.1
        return speech.getState().speechMode
    except AttributeError:
        return speech.speechMode
Exemple #7
0
def get_speech_mode():
    if hasattr(speech, "getState"):
        return speech.getState().speechMode
    return speech.speechMode