Changeset 2159

Show
Ignore:
Timestamp:
06/26/08 02:20:05 (5 months ago)
Author:
mdcurran
Message:

scriptHandler: don't allow executeScript to execute a script while an execution of that same script is already happening. This fixes problems where holding down a cursor key in edit fields can sometimes keep repeating the chunk of text when the caret reaches the end. This is because api.processPendingEvents pumps the queue and therefore scripts queued after the current script get executed inside that script.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/source/scriptHandler.py

    r2059 r2159  
    77import time 
    88import weakref 
     9from keyUtils import sendKey 
    910import appModuleHandler 
    1011import api 
     
    1516_lastScriptRef=None #Holds a weakref to the last script that was executed 
    1617_lastScriptCount=0 #The amount of times the last script was repeated 
     18_isScriptRunning=False 
    1719 
    1820def findScript(keyPress): 
     
    8082        @type keyPress: an NVDA keyPress 
    8183        """ 
    82         global _lastScriptTime, _lastScriptCount, _lastScriptRef  
    83         scriptTime=time.time() 
    84         scriptRef=weakref.ref(script) 
    85         if (scriptTime-_lastScriptTime)<=0.5 and _lastScriptRef and script==_lastScriptRef(): 
    86                 _lastScriptCount+=1 
    87         else: 
    88                 _lastScriptCount=0 
    89         _lastScriptRef=scriptRef 
    90         _lastScriptTime=scriptTime 
    91         script(keyPress) 
     84        global _lastScriptTime, _lastScriptCount, _lastScriptRef, _isScriptRunning  
     85        lastScriptRef=_lastScriptRef() if _lastScriptRef else None 
     86        #We don't allow the same script to be executed from with in itself, but we still should pass the key through 
     87        if _isScriptRunning and lastScriptRef==script: 
     88                return sendKey(keyPress) 
     89        _isScriptRunning=True 
     90        try: 
     91                scriptTime=time.time() 
     92                scriptRef=weakref.ref(script) 
     93                if (scriptTime-_lastScriptTime)<=0.5 and script==lastScriptRef: 
     94                        _lastScriptCount+=1 
     95                else: 
     96                        _lastScriptCount=0 
     97                _lastScriptRef=scriptRef 
     98                _lastScriptTime=scriptTime 
     99                script(keyPress) 
     100        finally: 
     101                _isScriptRunning=False 
    92102 
    93103def getLastScriptRepeateCount():