Skip to content

Commit

Permalink
WebAccessBmdti: Manual refresh is now synchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienCochuyt committed Oct 17, 2024
1 parent e379811 commit 085d2a2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
28 changes: 27 additions & 1 deletion addon/globalPlugins/webAccess/nodeHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,36 @@ def afficheNode(self, node, level=0):
s += self.afficheNode(child, level + 1)
return s

def update(self, force=False):
def update(self, force=False, ruleManager=None, debug=False):
"""Analyze the VirtualBuffer
If a RuleManager is specified, it is immediately updated and no
event is sent to the scheduler.
"""
# t = logTimeStart()
if self.treeInterceptor is None or not self.treeInterceptor.isReady:
self._ready = False
if debug:
log.info(f"No TreeInterceptor")
return False
try:
info = self.treeInterceptor.makeTextInfo(textInfos.POSITION_LAST)
except Exception:
self._ready = False
if debug:
log.exception()
return False
try:
size = info._endOffset + 1
except Exception:
self._ready = False
if debug:
log.exception()
return False
if not force and size == self.treeInterceptorSize:
# probably not changed
if debug:
log.info(f"Size unchanged: {size}")
return False
self.treeInterceptorSize = size
if True:
Expand All @@ -260,6 +273,8 @@ def update(self, force=False):
end = info._endOffset
if start == end:
self._ready = False
if debug:
log.info("The VirtualBuffer is empty")
return False
text = NVDAHelper.VBuf_getTextInRange(
info.obj.VBufHandle, start, end, True)
Expand All @@ -278,22 +293,33 @@ def update(self, force=False):
if self.mainNode is None:
self.updating = False
self._ready = False
if debug:
# @@@
log.info("NodeManager.update: ")
return False
self.identifier = time.time()
# logTime ("Update node manager %d nodes" % len(fields), t)
self.updating = False
# playWebAccessSound("tick")
self._curNode = self.caretNode = self.getCaretNode() # FIXME: Dead code
if ruleManager:
# Synchronous update, eg. from WebAccessBmdti.script_refreshResults
self._ready = True
return ruleManager.update(nodeManager=self, force=force)
try:
info = self.treeInterceptor.makeTextInfo(textInfos.POSITION_LAST)
except Exception:
self._ready = False
if debug:
log.exception()
return False
size = info._endOffset + 1
from . import webAppScheduler
if size != self.treeInterceptorSize:
# treeInterceptor has changed during analyze
self._ready = False
if debug:
log.info("VirtualBuffer has changed during analysis")
webAppScheduler.scheduler.send(
eventName="updateNodeManager",
treeInterceptor=self.treeInterceptor
Expand Down
14 changes: 12 additions & 2 deletions addon/globalPlugins/webAccess/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,8 +1115,18 @@ def script_quickNavToPreviousResultLevel3(self, gesture):
def script_refreshResults(self, gesture):
# Translators: Notified when manually refreshing results
ui.message(_("Refresh results"))
self.webAccess.rootRuleManager.clear()
self.webAccess.nodeManager.update(force=True)
try:
res = self.webAccess.nodeManager.update(
force=True,
ruleManager=self.webAccess.rootRuleManager,
)
except Exception:
log.exception()
res = False
if res:
ui.message(_("Updated"))
else:
ui.message(_("Update failed"))

script_refreshResults.ignoreTreeInterceptorPassThrough = True
script_refreshResults.passThroughIfNoWebModule = True
Expand Down

0 comments on commit 085d2a2

Please sign in to comment.