Example #1
0
	def executeGesture(self, gesture):
		"""Perform the action associated with a gesture.
		@param gesture: The gesture to execute.
		@type gesture: L{InputGesture}
		@raise NoInputGestureAction: If there is no action to perform.
		"""
		if watchdog.isAttemptingRecovery:
			# The core is dead, so don't try to perform an action.
			# This lets gestures pass through unhindered where possible,
			# as well as stopping a flood of actions when the core revives.
			raise NoInputGestureAction

		script = gesture.script
		focus = api.getFocusObject()
		if focus.sleepMode is focus.SLEEP_FULL or (focus.sleepMode and not getattr(script, 'allowInSleepMode', False)):
			raise NoInputGestureAction

		wasInSayAll=False
		if gesture.isModifier:
			if not self.lastModifierWasInSayAll:
				wasInSayAll=self.lastModifierWasInSayAll=sayAllHandler.isRunning()
		elif self.lastModifierWasInSayAll:
			wasInSayAll=True
			self.lastModifierWasInSayAll=False
		else:
			wasInSayAll=sayAllHandler.isRunning()
		if wasInSayAll:
			gesture.wasInSayAll=True

		speechEffect = gesture.speechEffectWhenExecuted
		if speechEffect == gesture.SPEECHEFFECT_CANCEL:
			queueHandler.queueFunction(queueHandler.eventQueue, speech.cancelSpeech)
		elif speechEffect in (gesture.SPEECHEFFECT_PAUSE, gesture.SPEECHEFFECT_RESUME):
			queueHandler.queueFunction(queueHandler.eventQueue, speech.pauseSpeech, speechEffect == gesture.SPEECHEFFECT_PAUSE)

		if log.isEnabledFor(log.IO) and not gesture.isModifier:
			log.io("Input: %s" % gesture.logIdentifier)

		if self._captureFunc:
			try:
				if self._captureFunc(gesture) is False:
					return
			except:
				log.error("Error in capture function, disabling", exc_info=True)
				self._captureFunc = None

		if gesture.isModifier:
			raise NoInputGestureAction

		if config.conf["keyboard"]["speakCommandKeys"] and gesture.shouldReportAsCommand:
			queueHandler.queueFunction(queueHandler.eventQueue, speech.speakMessage, gesture.displayName)

		gesture.reportExtra()

		if script:
			scriptHandler.queueScript(script, gesture)
			return

		raise NoInputGestureAction
Example #2
0
def nvdaControllerInternal_inputLangChangeNotify(threadID,hkl,layoutString):
	global lastInputMethodName, lastInputLanguageName
	focus=api.getFocusObject()
	#This callback can be called before NVDa is fully initialized
	#So also handle focus object being None as well as checking for sleepMode
	if not focus or focus.sleepMode:
		return 0
	import NVDAObjects.window
	#Generally we should not allow input lang changes from threads that are not focused.
	#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
	#Never announce changes while in sayAll (#1676)
	if sayAllHandler.isRunning():
		return 0
	import queueHandler
	import ui
	languageID=hkl&0xffff
	buf=create_unicode_buffer(1024)
	res=windll.kernel32.GetLocaleInfoW(languageID,2,buf,1024)
	# Translators: the label for an unknown language when switching input methods.
	inputLanguageName=buf.value if res else _("unknown language")
	layoutStringCodes=[]
	inputMethodName=None
	#layoutString can either be a real input method name, a hex string for an input method name in the registry, or an empty string.
	#If its a real input method name its used as is.
	#If its a hex string or its empty, then the method name is looked up by trying:
	#The full hex string, the hkl as a hex string, the low word of the hex string or hkl, the high word of the hex string or hkl.
	if layoutString:
		try:
			int(layoutString,16)
			layoutStringCodes.append(layoutString)
		except ValueError:
			inputMethodName=layoutString
	if not inputMethodName:
		layoutStringCodes.insert(0,hex(hkl)[2:].rstrip('L').upper().rjust(8,'0'))
		for stringCode in list(layoutStringCodes):
			layoutStringCodes.append(stringCode[4:].rjust(8,'0'))
			if stringCode[0]<'D':
				layoutStringCodes.append(stringCode[0:4].rjust(8,'0'))
		for stringCode in layoutStringCodes:
			inputMethodName=_lookupKeyboardLayoutNameWithHexString(stringCode)
			if inputMethodName: break
	if not inputMethodName:
		log.debugWarning("Could not find layout name for keyboard layout, reporting as unknown") 
		# Translators: The label for an unknown input method when switching input methods. 
		inputMethodName=_("unknown input method")
	if ' - ' in inputMethodName:
		inputMethodName="".join(inputMethodName.split(' - ')[1:])
	if inputLanguageName!=lastInputLanguageName:
		lastInputLanguageName=inputLanguageName
		# Translators: the message announcing the language and keyboard layout when it changes
		inputMethodName=_("{language} - {layout}").format(language=inputLanguageName,layout=inputMethodName)
	if inputMethodName!=lastInputMethodName:
		lastInputMethodName=inputMethodName
		queueHandler.queueFunction(queueHandler.eventQueue,ui.message,inputMethodName)
	return 0
Example #3
0
def executeGesture(self, gesture):
    """Perform the action associated with a gesture.
		@param gesture: The gesture to execute.
		@type gesture: L{InputGesture}
		@raise NoInputGestureAction: If there is no action to perform.
		"""
    if watchdog.isAttemptingRecovery:
        # The core is dead, so don't try to perform an action.
        # This lets gestures pass through unhindered where possible,
        # as well as stopping a flood of actions when the core revives.
        raise NoInputGestureAction

    script = gesture.script
    if "brailleDisplayDrivers" in str(type(gesture)):
        if instanceGP.brailleKeyboardLocked and (
            (hasattr(script, "__func__") and
             script.__func__.__name__ != "script_toggleLockBrailleKeyboard")
                or not hasattr(script, "__func__")):
            return
        if not config.conf["brailleExtender"][
                'stopSpeechUnknown'] and gesture.script == None:
            stopSpeech = False
        elif hasattr(script, "__func__") and (script.__func__.__name__ in [
                "script_braille_dots", "script_braille_enter",
                "script_volumePlus", "script_volumeMinus",
                "script_toggleVolume", "script_hourDate", "script_ctrl",
                "script_alt", "script_nvda", "script_win", "script_ctrlAlt",
                "script_ctrlAltWin", "script_ctrlAltWinShift",
                "script_ctrlAltShift", "script_ctrlWin", "script_ctrlWinShift",
                "script_ctrlShift", "script_altWin", "script_altWinShift",
                "script_altShift", "script_winShift"
        ] or (not config.conf["brailleExtender"]['stopSpeechScroll']
              and script.__func__.__name__ in
              ["script_braille_scrollBack", "script_braille_scrollForward"])):
            stopSpeech = False
        else:
            stopSpeech = True
    else:
        stopSpeech = True

    focus = api.getFocusObject()
    if focus.sleepMode is focus.SLEEP_FULL or (focus.sleepMode and not getattr(
            script, 'allowInSleepMode', False)):
        raise NoInputGestureAction

    wasInSayAll = False
    if gesture.isModifier:
        if not self.lastModifierWasInSayAll:
            wasInSayAll = self.lastModifierWasInSayAll = sayAllHandler.isRunning(
            )
    elif self.lastModifierWasInSayAll:
        wasInSayAll = True
        self.lastModifierWasInSayAll = False
    else:
        wasInSayAll = sayAllHandler.isRunning()
    if wasInSayAll:
        gesture.wasInSayAll = True

    speechEffect = gesture.speechEffectWhenExecuted
    if not stopSpeech: pass
    elif speechEffect == gesture.SPEECHEFFECT_CANCEL:
        queueHandler.queueFunction(queueHandler.eventQueue,
                                   speech.cancelSpeech)
    elif speechEffect in (gesture.SPEECHEFFECT_PAUSE,
                          gesture.SPEECHEFFECT_RESUME):
        queueHandler.queueFunction(queueHandler.eventQueue, speech.pauseSpeech,
                                   speechEffect == gesture.SPEECHEFFECT_PAUSE)

    if log.isEnabledFor(log.IO) and not gesture.isModifier:
        self._lastInputTime = time.time()
        log.io("Input: %s" % gesture.identifiers[0])

    if self._captureFunc:
        try:
            if self._captureFunc(gesture) is False:
                return
        except BaseException:
            log.error("Error in capture function, disabling", exc_info=True)
            self._captureFunc = None

    if gesture.isModifier:
        raise NoInputGestureAction

    if config.conf["keyboard"][
            "speakCommandKeys"] and gesture.shouldReportAsCommand:
        queueHandler.queueFunction(queueHandler.eventQueue,
                                   speech.speakMessage, gesture.displayName)

    gesture.reportExtra()

    # #2953: if an intercepted command Script (script that sends a gesture) is queued
    # then queue all following gestures (that don't have a script) with a fake script so that they remain in order.
    if not script and scriptHandler._numIncompleteInterceptedCommandScripts:
        script = lambda gesture: gesture.send()

    if script:
        scriptHandler.queueScript(script, gesture)
        return

    raise NoInputGestureAction
Example #4
0
    def executeGesture(self, gesture):
        """Perform the action associated with a gesture.
		@param gesture: The gesture to execute.
		@type gesture: L{InputGesture}
		@raise NoInputGestureAction: If there is no action to perform.
		"""
        if watchdog.isAttemptingRecovery:
            # The core is dead, so don't try to perform an action.
            # This lets gestures pass through unhindered where possible,
            # as well as stopping a flood of actions when the core revives.
            raise NoInputGestureAction

        script = gesture.script
        focus = api.getFocusObject()
        if focus.sleepMode is focus.SLEEP_FULL or (
                focus.sleepMode
                and not getattr(script, 'allowInSleepMode', False)):
            raise NoInputGestureAction

        wasInSayAll = False
        if gesture.isModifier:
            if not self.lastModifierWasInSayAll:
                wasInSayAll = self.lastModifierWasInSayAll = sayAllHandler.isRunning(
                )
        elif self.lastModifierWasInSayAll:
            wasInSayAll = True
            self.lastModifierWasInSayAll = False
        else:
            wasInSayAll = sayAllHandler.isRunning()
        if wasInSayAll:
            gesture.wasInSayAll = True

        speechEffect = gesture.speechEffectWhenExecuted
        if speechEffect == gesture.SPEECHEFFECT_CANCEL:
            queueHandler.queueFunction(queueHandler.eventQueue,
                                       speech.cancelSpeech)
        elif speechEffect in (gesture.SPEECHEFFECT_PAUSE,
                              gesture.SPEECHEFFECT_RESUME):
            queueHandler.queueFunction(
                queueHandler.eventQueue, speech.pauseSpeech,
                speechEffect == gesture.SPEECHEFFECT_PAUSE)

        if gesture.shouldPreventSystemIdle:
            winKernel.SetThreadExecutionState(winKernel.ES_SYSTEM_REQUIRED)

        if log.isEnabledFor(log.IO) and not gesture.isModifier:
            self._lastInputTime = time.time()
            log.io("Input: %s" % gesture.identifiers[0])

        if self._captureFunc:
            try:
                if self._captureFunc(gesture) is False:
                    return
            except:
                log.error("Error in capture function, disabling",
                          exc_info=True)
                self._captureFunc = None

        if gesture.isModifier:
            raise NoInputGestureAction

        if config.conf["keyboard"][
                "speakCommandKeys"] and gesture.shouldReportAsCommand:
            queueHandler.queueFunction(queueHandler.eventQueue,
                                       speech.speakMessage,
                                       gesture.displayName)

        gesture.reportExtra()

        # #2953: if an intercepted command Script (script that sends a gesture) is queued
        # then queue all following gestures (that don't have a script) with a fake script so that they remain in order.
        if not script and scriptHandler._numIncompleteInterceptedCommandScripts:
            script = lambda gesture: gesture.send()

        if script:
            scriptHandler.queueScript(script, gesture)
            return
        else:
            # Clear memorized last script to avoid getLastScriptRepeatCount detect a repeat
            # in case an unbound gesture is executed between two identical bound gestures.
            queueHandler.queueFunction(queueHandler.eventQueue,
                                       scriptHandler.clearLastScript)
            raise NoInputGestureAction
Example #5
0
    def executeKeyboardGesture(self, gesture, bypassRemanence=False):
        """Perform the action associated with a gesture.
		@param gesture: The gesture to execute
		@type gesture: L{InputGesture}
		@raise NoInputGestureAction: If there is no action to perform.
		"""
        if not hasattr(gesture, "noAction"):
            gesture.noAction = False
        if watchdog.isAttemptingRecovery:
            # The core is dead, so don't try to perform an action.
            # This lets gestures pass through unhindered where possible,
            # as well as stopping a flood of actions when the core revives.
            raise NoInputGestureAction
        newGesture = self.manageRemanence(
            gesture) if not bypassRemanence else None
        if newGesture is not None:
            queueHandler.queueFunction(queueHandler.eventQueue,
                                       self.executeNewGesture, newGesture)
            return
        newGesture = self.getNumpadKeyReplacement(gesture)
        if newGesture is not None:
            queueHandler.queueFunction(queueHandler.eventQueue,
                                       self.executeNewGesture, newGesture)
            return
        script = gesture.script
        focus = api.getFocusObject()
        if focus.sleepMode is focus.SLEEP_FULL\
         or (focus.sleepMode and not getattr(script, 'allowInSleepMode', False)):
            raise NoInputGestureAction
        wasInSayAll = False
        if gesture.isModifier:
            if not _NVDA_InputManager.lastModifierWasInSayAll:
                wasInSayAll = _NVDA_InputManager.lastModifierWasInSayAll = sayAllHandler.isRunning(
                )
        elif _NVDA_InputManager.lastModifierWasInSayAll:
            wasInSayAll = True
            _NVDA_InputManager.lastModifierWasInSayAll = False
        else:
            wasInSayAll = sayAllHandler.isRunning()
        if wasInSayAll:
            gesture.wasInSayAll = True
        speechEffect = gesture.speechEffectWhenExecuted
        if speechEffect == gesture.SPEECHEFFECT_CANCEL:
            queueHandler.queueFunction(queueHandler.eventQueue,
                                       speech.cancelSpeech)
        elif speechEffect in (gesture.SPEECHEFFECT_PAUSE,
                              gesture.SPEECHEFFECT_RESUME):  # noqa:E501
            queueHandler.queueFunction(
                queueHandler.eventQueue, speech.pauseSpeech,
                speechEffect == gesture.SPEECHEFFECT_PAUSE)
        if py3 and gesture.shouldPreventSystemIdle:
            winKernel.SetThreadExecutionState(winKernel.ES_SYSTEM_REQUIRED
                                              | winKernel.ES_DISPLAY_REQUIRED)
        if log.isEnabledFor(log.IO) and not gesture.isModifier:
            _NVDA_InputManager._lastInputTime = time.time()
            log.io("Input: %s" % gesture.identifiers[0])
        if _NVDA_InputManager._captureFunc:
            try:
                if _NVDA_InputManager._captureFunc(gesture) is False:
                    return
            except:  # noqa:E722
                log.error("Error in capture function, disabling",
                          exc_info=True)
                _NVDA_InputManager._captureFunc = None
        if gesture.isModifier:
            if gesture.noAction:
                gesture.normalizedModifiers = []
                return
            raise NoInputGestureAction
        self.speakGesture(gesture)
        if not script:
            gesture.reportExtra()
        # then queue all following gestures
        # (that don't have a script
        # ) with a fake script so that they remain in order.
        if not script and (
                bypassRemanence
                or scriptHandler._numIncompleteInterceptedCommandScripts):
            script = lambda gesture: gesture.send()  # noqa:E731
        if script:
            scriptHandler.queueScript(script, gesture)
            return
        raise NoInputGestureAction
Example #6
0
    def executeGesture(self, gesture):
        """Perform the action associated with a gesture.
		@param gesture: The gesture to execute.
		@type gesture: L{InputGesture}
		@raise NoInputGestureAction: If there is no action to perform.
		"""
        if watchdog.isAttemptingRecovery:
            # The core is dead, so don't try to perform an action.
            # This lets gestures pass through unhindered where possible,
            # as well as stopping a flood of actions when the core revives.
            raise NoInputGestureAction

        script = gesture.script
        focus = api.getFocusObject()
        if focus.sleepMode is focus.SLEEP_FULL or (
                focus.sleepMode
                and not getattr(script, 'allowInSleepMode', False)):
            raise NoInputGestureAction

        wasInSayAll = False
        if gesture.isModifier:
            if not self.lastModifierWasInSayAll:
                wasInSayAll = self.lastModifierWasInSayAll = sayAllHandler.isRunning(
                )
        elif self.lastModifierWasInSayAll:
            wasInSayAll = True
            self.lastModifierWasInSayAll = False
        else:
            wasInSayAll = sayAllHandler.isRunning()
        if wasInSayAll:
            gesture.wasInSayAll = True

        speechEffect = gesture.speechEffectWhenExecuted
        if speechEffect == gesture.SPEECHEFFECT_CANCEL:
            queueHandler.queueFunction(queueHandler.eventQueue,
                                       speech.cancelSpeech)
        elif speechEffect in (gesture.SPEECHEFFECT_PAUSE,
                              gesture.SPEECHEFFECT_RESUME):
            queueHandler.queueFunction(
                queueHandler.eventQueue, speech.pauseSpeech,
                speechEffect == gesture.SPEECHEFFECT_PAUSE)

        if log.isEnabledFor(log.IO) and not gesture.isModifier:
            log.io("Input: %s" % gesture.logIdentifier)

        if self._captureFunc:
            try:
                if self._captureFunc(gesture) is False:
                    return
            except:
                log.error("Error in capture function, disabling",
                          exc_info=True)
                self._captureFunc = None

        if gesture.isModifier:
            raise NoInputGestureAction

        if config.conf["keyboard"][
                "speakCommandKeys"] and gesture.shouldReportAsCommand:
            queueHandler.queueFunction(queueHandler.eventQueue,
                                       speech.speakMessage,
                                       gesture.displayName)
        # nvdajp begin
        if hasattr(gesture, "vkCode") and gesture.vkCode == winUser.VK_RETURN:
            dummy = winUser.getAsyncKeyState(winUser.VK_BACK)
        # nvdajp end

        gesture.reportExtra()

        # #2953: if an intercepted command Script (script that sends a gesture) is queued
        # then queue all following gestures (that don't have a script) with a fake script so that they remain in order.
        if not script and scriptHandler._numIncompleteInterceptedCommandScripts:
            script = lambda gesture: gesture.send()

        if script:
            scriptHandler.queueScript(script, gesture)
            return

        raise NoInputGestureAction
Example #7
0
 def shouldNukeRoleSpeech(self):
     if config.conf["unspoken"]["sayAll"]:
         return not sayAllHandler.isRunning()
     return True
Example #8
0
	def shouldNukeRoleSpeech(self):
		if config.conf["unspoken"]["sayAll"] and sayAllHandler.isRunning():
			return False
		if config.conf["unspoken"]["speakRoles"]:
			return False
		return True
Example #9
0
 def shouldNukeRoleSpeech(self):
     if self.use_in_say_all and sayAllHandler.isRunning():
         return False
     if self.speak_roles:
         return False
     return True