Example #1
0
def _callLaterExec(callable, args, kwargs):
	import watchdog
	watchdog.alive()
	try:
		return callable(*args, **kwargs)
	finally:
		watchdog.asleep()
        def run(self):
            global _isPumpPending
            _isPumpPending = False
            # print("pumpujuuu")
            watchdog.alive()
            try:
                # if touchHandler.handler:
                #     touchHandler.handler.pump()
                JABHandler.pumpAll()
                # IAccessibleHandler.pumpAll()
                queueHandler.pumpAll()
                # mouseHandler.pumpAll()
                # braille.pumpAll()
                # vision.pumpAll()
            except Exception as e:

                print("errors in this core pump cycle", e)
                # raise
            # baseObject.AutoPropertyObject.invalidateCaches()
            # print("spinkam")
            watchdog.asleep()
            # print("vstalsem")
            if _isPumpPending and not _pump.IsRunning():
                # #3803: Another pump was requested during this pump execution.
                # As our pump is not re-entrant, schedule another pump.
                _pump.Start(PUMP_MAX_DELAY, True)
Example #3
0
def flushQueue(queue):
    for count in xrange(queue.qsize() + 1):
        if not queue.empty():
            (func, args, kwargs) = queue.get_nowait()
            watchdog.alive()
            try:
                func(*args, **kwargs)
            except:
                log.exception("Error in func %s from %s" % (func.__name__, queue.__name__))
Example #4
0
def flushQueue(queue):
	for count in range(queue.qsize()+1):
		if not queue.empty():
			(func,args,kwargs)=queue.get_nowait()
			watchdog.alive()
			try:
				func(*args,**kwargs)
			except:
				log.exception(f"Error in func {func.__qualname__}")
Example #5
0
def flushQueue(queue):
    for count in xrange(queue.qsize() + 1):
        if not queue.empty():
            (func, args, kwargs) = queue.get_nowait()
            watchdog.alive()
            try:
                func(*args, **kwargs)
            except:
                log.exception("Error in func %s from %s" %
                              (func.__name__, queue.__name__))
Example #6
0
		def Notify(self):
			try:
				JABHandler.pumpAll()
				IAccessibleHandler.pumpAll()
				queueHandler.pumpAll()
				mouseHandler.pumpAll()
			except:
				log.exception("errors in this core pump cycle")
			baseObject.AutoPropertyObject.invalidateCaches()
			watchdog.alive()
Example #7
0
		def Notify(self):
			try:
				JABHandler.pumpAll()
				IAccessibleHandler.pumpAll()
				queueHandler.pumpAll()
				mouseHandler.pumpAll()
				braille.pumpAll()
			except:
				log.exception("errors in this core pump cycle")
			baseObject.AutoPropertyObject.invalidateCaches()
			watchdog.alive()
Example #8
0
File: api.py Project: lpintes/NVDA
def processPendingEvents(processEventQueue=True):
	# Import late to avoid circular import.
	import IAccessibleHandler
	import JABHandler
	import wx
	import queueHandler
	watchdog.alive()
	wx.Yield()
	JABHandler.pumpAll()
	IAccessibleHandler.pumpAll()
	import baseObject
	baseObject.AutoPropertyObject.invalidateCaches()
	if processEventQueue:
		queueHandler.flushQueue(queueHandler.eventQueue)
Example #9
0
def processPendingEvents(processEventQueue=True):
    # Import late to avoid circular import.
    import IAccessibleHandler
    import JABHandler
    import wx
    import queueHandler
    watchdog.alive()
    wx.Yield()
    JABHandler.pumpAll()
    IAccessibleHandler.pumpAll()
    import baseObject
    baseObject.AutoPropertyObject.invalidateCaches()
    if processEventQueue:
        queueHandler.flushQueue(queueHandler.eventQueue)
Example #10
0
    def leftDrag(self, timeout=0.3, mouse_up=True):
        """ Drag with left button from x,y to r,b coordinates.
		Dangerous! When mouse_up is false, should be paired with leftUp !!!
		Args:
			timeout (float): time (in seconds) to wait before moving from initial to final position
			mouse_up (bool): generate mouse_up event after dragging (!!! Dangerous !!!) 
		"""
        self.moveTo()
        winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN, 0, 0, None, None)
        watchdog.asleep()  # do not let watchdog interrupt us
        time.sleep(timeout)
        watchdog.alive()
        libsibiac.MouseMove(self.windowHandle, c_int(self.r), c_int(self.b))
        if mouse_up:
            winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP, 0, 0, None, None)
Example #11
0
def _espeak_speak(msg, lang, index=None, prop=None):
	global currentEngine, lastIndex, espeakMark
	currentEngine = 1
	msg = unicode(msg)
	msg.translate({ord(u'\01'):None,ord(u'<'):u'&lt;',ord(u'>'):u'&gt;'})
	msg = u"<voice xml:lang=\"%s\">%s</voice>" % (lang, msg)
	msg += u"<mark name=\"%d\" />" % espeakMark
	_espeak.speak(msg)
	while currentEngine == 1 and _espeak.lastIndex != espeakMark:
		time.sleep(0.1)
		watchdog.alive()
	time.sleep(0.4)
	watchdog.alive()
	lastIndex = index
	currentEngine = 0
	espeakMark += 1
Example #12
0
	def execute(self):
		data = self.inputCtrl.GetValue()
		watchdog.alive()
		self.console.push(data)
		watchdog.asleep()
		if data:
			# Only add non-blank lines to history.
			if len(self.inputHistory) > 1 and self.inputHistory[-2] == data:
				# The previous line was the same and we don't want consecutive duplicates, so trash the most recent line.
				del self.inputHistory[-1]
			else:
				# Update the content for the most recent line of history.
				self.inputHistory[-1] = data
			# Start with a new, blank line.
			self.inputHistory.append("")
		self.inputHistoryPos = len(self.inputHistory) - 1
		self.inputCtrl.ChangeValue("")
Example #13
0
 def execute(self):
     data = self.inputCtrl.GetValue()
     watchdog.alive()
     self.console.push(data)
     watchdog.asleep()
     if data:
         # Only add non-blank lines to history.
         if len(self.inputHistory) > 1 and self.inputHistory[-2] == data:
             # The previous line was the same and we don't want consecutive duplicates, so trash the most recent line.
             del self.inputHistory[-1]
         else:
             # Update the content for the most recent line of history.
             self.inputHistory[-1] = data
         # Start with a new, blank line.
         self.inputHistory.append("")
     self.inputHistoryPos = len(self.inputHistory) - 1
     self.inputCtrl.ChangeValue("")
Example #14
0
def pumpAll():
	# This dict can mutate during iteration, so use keys().
	for ID in generators.keys():
		# KeyError could occur within the generator itself, so retrieve the generator first.
		try:
			gen = generators[ID]
		except KeyError:
			# Generator was cancelled. This is fine.
			continue
		watchdog.alive()
		try:
			next(gen)
		except StopIteration:
			log.debug("generator %s finished"%ID)
			del generators[ID]
		except:
			log.exception("error in generator %d"%ID)
			del generators[ID]
	flushQueue(eventQueue)
Example #15
0
def pumpAll():
    # This dict can mutate during iteration, so use keys().
    for ID in generators.keys():
        # KeyError could occur within the generator itself, so retrieve the generator first.
        try:
            gen = generators[ID]
        except KeyError:
            # Generator was cancelled. This is fine.
            continue
        watchdog.alive()
        try:
            next(gen)
        except StopIteration:
            log.debug("generator %s finished" % ID)
            del generators[ID]
        except:
            log.exception("error in generator %d" % ID)
            del generators[ID]
    flushQueue(eventQueue)
Example #16
0
		def run(self):
			global _isPumpPending
			_isPumpPending = False
			watchdog.alive()
			try:
				if touchHandler.handler:
					touchHandler.handler.pump()
				JABHandler.pumpAll()
				IAccessibleHandler.pumpAll()
				queueHandler.pumpAll()
				mouseHandler.pumpAll()
				braille.pumpAll()
			except:
				log.exception("errors in this core pump cycle")
			baseObject.AutoPropertyObject.invalidateCaches()
			watchdog.asleep()
			if _isPumpPending and not _pump.IsRunning():
				# #3803: Another pump was requested during this pump execution.
				# As our pump is not re-entrant, schedule another pump.
				_pump.Start(PUMP_MAX_DELAY, True)
Example #17
0
 def Notify(self):
     global _isPumpPending
     _isPumpPending = False
     watchdog.alive()
     try:
         if touchHandler.handler:
             touchHandler.handler.pump()
         JABHandler.pumpAll()
         IAccessibleHandler.pumpAll()
         queueHandler.pumpAll()
         mouseHandler.pumpAll()
         braille.pumpAll()
     except:
         log.exception("errors in this core pump cycle")
     baseObject.AutoPropertyObject.invalidateCaches()
     watchdog.asleep()
     if _isPumpPending and not _pump.IsRunning():
         # #3803: A pump was requested, but the timer was ignored by a modal loop
         # because timers aren't re-entrant.
         # Therefore, schedule another pump.
         _pump.Start(PUMP_MAX_DELAY, True)
Example #18
0
		def Notify(self):
			global _isPumpPending
			_isPumpPending = False
			watchdog.alive()
			try:
				if touchHandler.handler:
					touchHandler.handler.pump()
				JABHandler.pumpAll()
				IAccessibleHandler.pumpAll()
				queueHandler.pumpAll()
				mouseHandler.pumpAll()
				braille.pumpAll()
			except:
				log.exception("errors in this core pump cycle")
			baseObject.AutoPropertyObject.invalidateCaches()
			watchdog.asleep()
			if _isPumpPending and not _pump.IsRunning():
				# #3803: A pump was requested, but the timer was ignored by a modal loop
				# because timers aren't re-entrant.
				# Therefore, schedule another pump.
				_pump.Start(PUMP_MAX_DELAY, True)
Example #19
0
def pumpAll():
    # This dict can mutate during iteration, so use keys().
    for ID in generators.keys():
        # KeyError could occur within the generator itself, so retrieve the generator first.
        try:
            gen = generators[ID]
        except KeyError:
            # Generator was cancelled. This is fine.
            continue
        watchdog.alive()
        try:
            next(gen)
        except StopIteration:
            log.debug("generator %s finished" % ID)
            del generators[ID]
        except:
            log.exception("error in generator %d" % ID)
            del generators[ID]
            # Lose our reference so Python can destroy the generator if appropriate.
        del gen
    if generators:
        core.requestPump()
    flushQueue(eventQueue)
def pumpAll():
	# This dict can mutate during iteration, so wrap the keys in a list.
	for ID in list(generators):
		# KeyError could occur within the generator itself, so retrieve the generator first.
		try:
			gen = generators[ID]
		except KeyError:
			# Generator was cancelled. This is fine.
			continue
		watchdog.alive()
		try:
			next(gen)
		except StopIteration:
			log.debug("generator %s finished"%ID)
			del generators[ID]
		except:
			log.exception("error in generator %d"%ID)
			del generators[ID]
		# Lose our reference so Python can destroy the generator if appropriate.
		del gen
	if generators:
		core.requestPump()
	flushQueue(eventQueue)
Example #21
0
File: api.py Project: lpintes/NVDA
def setFocusObject(obj):
	"""Stores an object as the current focus object. (Note: this does not physically change the window with focus in the operating system, but allows NVDA to keep track of the correct object).
Before overriding the last object, this function calls event_loseFocus on the object to notify it that it is loosing focus. 
@param obj: the object that will be stored as the focus object
@type obj: NVDAObjects.NVDAObject
"""
	if not isinstance(obj,NVDAObjects.NVDAObject):
		return False
	if globalVars.focusObject:
		eventHandler.executeEvent("loseFocus",globalVars.focusObject)
	oldFocusLine=globalVars.focusAncestors
	#add the old focus to the old focus ancestors, but only if its not None (is none at NVDA initialization)
	if globalVars.focusObject: 
		oldFocusLine.append(globalVars.focusObject)
	oldAppModules=[o.appModule for o in oldFocusLine if o and o.appModule]
	appModuleHandler.cleanup()
	ancestors=[]
	tempObj=obj
	matchedOld=False
	focusDifferenceLevel=0
	oldFocusLineLength=len(oldFocusLine)
	# Starting from the focus, move up the ancestor chain.
	safetyCount=0
	while tempObj:
		if safetyCount<100:
			safetyCount+=1
		else:
			try:
				log.error("Never ending focus ancestry: last object: %s, %s, window class %s, application name %s"%(tempObj.name,controlTypes.roleLabels[tempObj.role],tempObj.windowClassName,tempObj.appModule.appName))
			except:
				pass
			tempObj=getDesktopObject()
		# Scan backwards through the old ancestors looking for a match.
		for index in xrange(oldFocusLineLength-1,-1,-1):
			watchdog.alive()
			if tempObj==oldFocusLine[index]:
				# Match! The old and new focus ancestors converge at this point.
				# Copy the old ancestors up to and including this object.
				origAncestors=oldFocusLine[0:index+1]
				#make sure to cache the last old ancestor as a parent on the first new ancestor so as not to leave a broken parent cache
				if ancestors and origAncestors:
					ancestors[0].container=origAncestors[-1]
				origAncestors.extend(ancestors)
				ancestors=origAncestors
				focusDifferenceLevel=index+1
				# We don't need to process any more in either this loop or the outer loop; we have all of the ancestors.
				matchedOld=True
				break
		if matchedOld:
			break
		# We're moving backwards along the ancestor chain, so add this to the start of the list.
		ancestors.insert(0,tempObj)
		container=tempObj.container
		tempObj.container=container # Cache the parent.
		tempObj=container
	newAppModules=[o.appModule for o in ancestors if o and o.appModule]
	#Remove the final new ancestor as this will be the new focus object
	del ancestors[-1]
	try:
		treeInterceptorHandler.cleanup()
	except watchdog.CallCancelled:
		pass
	treeInterceptorObject=None
	o=None
	watchdog.alive()
	for o in ancestors[focusDifferenceLevel:]+[obj]:
		try:
			treeInterceptorObject=treeInterceptorHandler.update(o)
		except:
			log.exception("Error updating tree interceptor")
	#Always make sure that the focus object's treeInterceptor is forced to either the found treeInterceptor (if its in it) or to None
	#This is to make sure that the treeInterceptor does not have to be looked up, which can cause problems for winInputHook
	if obj is o or obj in treeInterceptorObject:
		obj.treeInterceptor=treeInterceptorObject
	else:
		obj.treeInterceptor=None
	# #3804: handleAppSwitch should be called as late as possible,
	# as triggers must not be out of sync with global focus variables.
	# setFocusObject shouldn't fail earlier anyway, but it's best to be safe.
	appModuleHandler.handleAppSwitch(oldAppModules,newAppModules)
	# Set global focus variables.
	globalVars.focusDifferenceLevel=focusDifferenceLevel
	globalVars.focusObject=obj
	globalVars.focusAncestors=ancestors
	braille.invalidateCachedFocusAncestors(focusDifferenceLevel)
	if config.conf["reviewCursor"]["followFocus"]:
		setNavigatorObject(obj,isFocus=True)
	return True
Example #22
0
def setFocusObject(obj):
    """Stores an object as the current focus object. (Note: this does not physically change the window with focus in the operating system, but allows NVDA to keep track of the correct object).
Before overriding the last object, this function calls event_loseFocus on the object to notify it that it is loosing focus. 
@param obj: the object that will be stored as the focus object
@type obj: NVDAObjects.NVDAObject
"""
    if not isinstance(obj, NVDAObjects.NVDAObject):
        return False
    if globalVars.focusObject:
        eventHandler.executeEvent("loseFocus", globalVars.focusObject)
    oldFocusLine = globalVars.focusAncestors
    #add the old focus to the old focus ancestors, but only if its not None (is none at NVDA initialization)
    if globalVars.focusObject:
        oldFocusLine.append(globalVars.focusObject)
    oldAppModules = [o.appModule for o in oldFocusLine if o and o.appModule]
    appModuleHandler.cleanup()
    ancestors = []
    tempObj = obj
    matchedOld = False
    focusDifferenceLevel = 0
    oldFocusLineLength = len(oldFocusLine)
    # Starting from the focus, move up the ancestor chain.
    safetyCount = 0
    while tempObj:
        if safetyCount < 100:
            safetyCount += 1
        else:
            try:
                log.error(
                    "Never ending focus ancestry: last object: %s, %s, window class %s, application name %s"
                    % (tempObj.name, controlTypes.roleLabels[tempObj.role],
                       tempObj.windowClassName, tempObj.appModule.appName))
            except:
                pass
            tempObj = getDesktopObject()
        # Scan backwards through the old ancestors looking for a match.
        for index in range(oldFocusLineLength - 1, -1, -1):
            watchdog.alive()
            if tempObj == oldFocusLine[index]:
                # Match! The old and new focus ancestors converge at this point.
                # Copy the old ancestors up to and including this object.
                origAncestors = oldFocusLine[0:index + 1]
                #make sure to cache the last old ancestor as a parent on the first new ancestor so as not to leave a broken parent cache
                if ancestors and origAncestors:
                    ancestors[0].container = origAncestors[-1]
                origAncestors.extend(ancestors)
                ancestors = origAncestors
                focusDifferenceLevel = index + 1
                # We don't need to process any more in either this loop or the outer loop; we have all of the ancestors.
                matchedOld = True
                break
        if matchedOld:
            break
        # We're moving backwards along the ancestor chain, so add this to the start of the list.
        ancestors.insert(0, tempObj)
        container = tempObj.container
        tempObj.container = container  # Cache the parent.
        tempObj = container
    #Remove the final new ancestor as this will be the new focus object
    del ancestors[-1]
    # #5467: Ensure that the appModule of the real focus is included in the newAppModule list for profile switching
    # Rather than an original focus ancestor which happened to match the new focus.
    newAppModules = [o.appModule for o in ancestors if o and o.appModule]
    if obj.appModule:
        newAppModules.append(obj.appModule)
    try:
        treeInterceptorHandler.cleanup()
    except watchdog.CallCancelled:
        pass
    treeInterceptorObject = None
    o = None
    watchdog.alive()
    for o in ancestors[focusDifferenceLevel:] + [obj]:
        try:
            treeInterceptorObject = treeInterceptorHandler.update(o)
        except:
            log.error("Error updating tree interceptor", exc_info=True)
    #Always make sure that the focus object's treeInterceptor is forced to either the found treeInterceptor (if its in it) or to None
    #This is to make sure that the treeInterceptor does not have to be looked up, which can cause problems for winInputHook
    if obj is o or obj in treeInterceptorObject:
        obj.treeInterceptor = treeInterceptorObject
    else:
        obj.treeInterceptor = None
    # #3804: handleAppSwitch should be called as late as possible,
    # as triggers must not be out of sync with global focus variables.
    # setFocusObject shouldn't fail earlier anyway, but it's best to be safe.
    appModuleHandler.handleAppSwitch(oldAppModules, newAppModules)
    # Set global focus variables.
    globalVars.focusDifferenceLevel = focusDifferenceLevel
    globalVars.focusObject = obj
    globalVars.focusAncestors = ancestors
    braille.invalidateCachedFocusAncestors(focusDifferenceLevel)
    if config.conf["reviewCursor"]["followFocus"]:
        setNavigatorObject(obj, isFocus=True)
    return True
Example #23
0
import winUser
user32 = winUser.user32
import time
import watchdog
import os
from logHandler import log
import core

from .location import *
from .location import _LocationRef

watchdog.asleep()  # can take a while...
sibiac_dir = os.path.dirname(__file__)
dll = os.path.join(sibiac_dir, "..", "sibiac", "libsibiac.dll")
libsibiac = cdll.LoadLibrary(dll)
watchdog.alive()


def Colors2Tuple(arg, default=None):
    """ Convert an argument to tuple
	Args:
		arg (tuple of ints or single int, optional): the argument to convert
	"""
    if arg is None:
        if default is None:
            return None
        else:
            arg = default
    if isinstance(arg, tuple):
        return arg
    if isinstance(arg, int):