Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 3
0
def speak(str, time):
    if hasattr(speech, "SpeechMode"):
        speech.setSpeechMode(speech.SpeechMode.off)
        sleep(time)
        speech.setSpeechMode(speech.SpeechMode.talk)
    else:
        speech.speechMode = speech.speechMode_off
        sleep(time)
        speech.speechMode = speech.speechMode_talk
    if str != None:
        sleep(0.1)
        message(str)
Exemplo n.º 4
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"])
Exemplo n.º 5
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)
def setSpeechMode(mode):
    try:
        # for nvda version >= 2021.1
        speech.setSpeechMode(mode)
    except AttributeError:
        speech.speechMode = mode
def setSpeechMode_off():
    try:
        # for nvda version >= 2021.1
        speech.setSpeechMode(speech.SpeechMode.off)
    except AttributeError:
        speech.speechMode = speech.speechMode_off
Exemplo n.º 8
0
def set_speech_talk():
    if hasattr(speech, "SpeechMode"):
        return speech.setSpeechMode(speech.SpeechMode.talk)
    speech.speechMode = speech.speechMode_talk
Exemplo n.º 9
0
def set_speech_off():
    if hasattr(speech, "SpeechMode"):
        return speech.setSpeechMode(speech.SpeechMode.off)
    speech.speechMode = speech.speechMode_off