Skip to content

Commit d310cae

Browse files
authored
Merge 188c79c into 444b568
2 parents 444b568 + 188c79c commit d310cae

1 file changed

Lines changed: 28 additions & 14 deletions

File tree

source/NVDAObjects/window/excel.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# A part of NonVisual Desktop Access (NVDA)
22
# Copyright (C) 2006-2023 NV Access Limited, Dinesh Kaushal, Siddhartha Gupta, Accessolutions, Julien Cochuyt,
3-
# Cyrille Bougot
3+
# Cyrille Bougot, Leonard de Ruijter
44
# This file is covered by the GNU General Public License.
55
# See the file COPYING for more details.
66

@@ -712,7 +712,6 @@ class ExcelWorksheet(ExcelBase):
712712

713713

714714
treeInterceptorClass=ExcelBrowseModeTreeInterceptor
715-
716715
role=controlTypes.Role.TABLE
717716

718717
def _get_excelApplicationObject(self):
@@ -953,28 +952,43 @@ def _get_states(self):
953952
), canPropagate=True)
954953

955954
def script_changeSelection(self,gesture):
956-
oldSelection=api.getFocusObject()
955+
oldSelection = self._getSelection()
957956
gesture.send()
958-
import eventHandler
959-
import time
960-
newSelection=None
961-
curTime=startTime=time.time()
962-
while (curTime-startTime)<=0.15:
957+
newSelection = None
958+
start = time.time()
959+
retryInterval = 0.01
960+
maxTimeout = 0.15
961+
elapsed = 0
962+
retries = 0
963+
while True:
963964
if scriptHandler.isScriptWaiting():
964965
# Prevent lag if keys are pressed rapidly
965966
return
967+
api.processPendingEvents(processEventQueue=False)
966968
if eventHandler.isPendingEvents('gainFocus'):
969+
# This object is no longer focused.
967970
return
968-
newSelection=self._getSelection()
969-
if newSelection and newSelection!=oldSelection:
971+
newSelection = self._getSelection()
972+
if newSelection and newSelection != oldSelection:
973+
log.debug(f"Detected new selection after {elapsed} sec")
970974
break
971-
api.processPendingEvents(processEventQueue=False)
972-
time.sleep(0.015)
973-
curTime=time.time()
975+
elapsed = time.time() - start
976+
if elapsed >= maxTimeout:
977+
log.debug(f"Canceled detecting new selection after {elapsed} sec")
978+
break
979+
# We spin the first few tries, as sleep is not accurate for tiny periods
980+
# and we might end up sleeping longer than we need to. Spinning improves
981+
# responsiveness in the case that the app responds fairly quickly.
982+
if retries > 2:
983+
# Don't spin too long, though. If we get to this point, the app is
984+
# probably taking a while to respond, so super fast response is
985+
# already lost.
986+
time.sleep(retryInterval)
987+
retries += 1
974988
if newSelection:
975989
if oldSelection.parent==newSelection.parent:
976990
newSelection.parent=oldSelection.parent
977-
eventHandler.executeEvent('gainFocus',newSelection)
991+
eventHandler.executeEvent('gainFocus', newSelection)
978992

979993
def _WaitForValueChangeForAction(self, action, fetcher, timeout=0.15):
980994
oldVal = fetcher()

0 commit comments

Comments
 (0)