From 49e835c17e9efe8e3497c45d8c5bcfa98b315d6c Mon Sep 17 00:00:00 2001
From: Julien Cochuyt <JulienCochuyt@users.noreply.github.com>
Date: Wed, 21 Aug 2024 13:06:58 +0200
Subject: [PATCH] Rename more legacy "WebApp" and "MarkerManager" leftovers

Notably:
 - in `webAccess`: `supportWebApp` -> `canHaveWebAccessSupport`
 - in `webAppLib`: `playWebAppSound` -> `playWebAccessSound`
 - in `webAppScheduler`: `event_webApp` -> `event_webModule`
 - in `webAppScheduler`: `event_markerManagerUpdated` -> `event_ruleManagerUpdated`
 - in `WebModule`: `event_webApp_gainFocus` -> `event_webModule_gainFocus`
 - in `WebModule`: `event_webApp_loseFocus` -> `event_webModule_loseFocus`

The latter two are currently dead code but will likely be revived for issue #17.
---
 addon/globalPlugins/webAccess/__init__.py     | 73 ++++++++-----------
 .../webAccess/gui/webModulesManager.py        | 16 ++--
 addon/globalPlugins/webAccess/nodeHandler.py  |  4 +-
 addon/globalPlugins/webAccess/overlay.py      | 10 ++-
 .../webAccess/ruleHandler/__init__.py         | 25 ++++---
 .../webAccess/webAppLib/__init__.py           | 12 ++-
 .../webAccess/webAppScheduler.py              | 19 +++--
 .../webAccess/webModuleHandler/webModule.py   | 14 ++--
 8 files changed, 92 insertions(+), 81 deletions(-)

diff --git a/addon/globalPlugins/webAccess/__init__.py b/addon/globalPlugins/webAccess/__init__.py
index 2efebe2f..ebd84334 100644
--- a/addon/globalPlugins/webAccess/__init__.py
+++ b/addon/globalPlugins/webAccess/__init__.py
@@ -56,58 +56,49 @@
 
 import os
 import re
-import core
 import wx
 
 from NVDAObjects.IAccessible import IAccessible
 from NVDAObjects.IAccessible.MSHTML import MSHTML
 from NVDAObjects.IAccessible.ia2Web import Ia2Web
 from NVDAObjects.IAccessible.mozilla import Mozilla
-from scriptHandler import script
 import addonHandler
 import api
 import baseObject
 from buildVersion import version_detailed as NVDA_VERSION
 import controlTypes
+import core
 import eventHandler
 import globalPluginHandler
 import gui
 from logHandler import log
-import scriptHandler
-import speech
+from scriptHandler import script
 import ui
 import virtualBuffers
 
-from . import nodeHandler
 from . import overlay
-from . import webAppLib
-from .webAppLib import *
-from .webAppScheduler import WebAppScheduler
 from . import webModuleHandler
+from .webAppLib import playWebAccessSound, sleep
+from .webAppScheduler import WebAppScheduler
 
 
 addonHandler.initTranslation()
 
 
-TRACE = lambda *args, **kwargs: None  # @UnusedVariable
-#TRACE = log.info
-
 SCRIPT_CATEGORY = "WebAccess"
-
-#
-# defines sound directory
-#
-
 SOUND_DIRECTORY = os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "..", "sounds")
+SUPPORTED_HOSTS = ['brave', 'firefox', 'chrome', 'java', 'iexplore', 'microsoftedgecp', 'msedge']
+TRACE = lambda *args, **kwargs: None  # @UnusedVariable
+#TRACE = log.info
 
 
+# Currently dead code, but will likely be revived for issue #17.
+activeWebModule = None
 
-supportedWebAppHosts = ['brave', 'firefox', 'chrome', 'java', 'iexplore', 'microsoftedgecp', 'msedge']
-
-activeWebApp = None
 webAccessEnabled = True
 scheduler = None
 
+
 class DefaultBrowserScripts(baseObject.ScriptableObject):
 
 	def __init__(self, warningMessage):
@@ -118,7 +109,7 @@ def __init__(self, warningMessage):
 			self.__class__.__gestures["kb:control+shift+%s" % character] = "notAssigned"
 
 	def script_notAssigned(self, gesture):  # @UnusedVariable
-		playWebAppSound("keyError")
+		playWebAccessSound("keyError")
 		sleep(0.2)
 		ui.message(self.warningMessage)
 
@@ -224,7 +215,7 @@ def showWebAccessGui(self):
 			# Translators: Error message when attempting to show the Web Access GUI.
 			ui.message(_("The current object does not support Web Access."))
 			return
-		if not supportWebApp(obj):
+		if not canHaveWebAccessSupport(obj):
 			# Translators: Error message when attempting to show the Web Access GUI.
 			ui.message(_("You must be in a web browser to use Web Access."))
 			return
@@ -305,23 +296,23 @@ def script_toggleWebAccessSupport(self, gesture):  # @UnusedVariable
 			ui.message(_("Web Access support enabled."))  # FR: u"Support Web Access activé."
 
 
-def getActiveWebApp():
-	global activeWebApp
-	return activeWebApp
+def getActiveWebModule():
+	global activeWebModule
+	return activeWebModule
 
 
-def webAppLoseFocus(obj):
-	global activeWebApp
-	if activeWebApp is not None:
-		sendWebAppEvent('webApp_loseFocus', obj, activeWebApp)
-		activeWebApp = None
-		#log.info("Losing webApp focus for object:\n%s\n" % ("\n".join(obj.devInfo)))
+def webModuleLoseFocus(obj):
+	global activeWebModule
+	if activeWebModule is not None:
+		sendWebModuleEvent('webModule_loseFocus', obj, activeWebModule)
+		activeWebModule = None
+		#log.info("Losing webModule focus for object:\n%s\n" % ("\n".join(obj.devInfo)))
 
 
-def supportWebApp(obj):
+def canHaveWebAccessSupport(obj):
 	if obj is None or obj.appModule is None:
-		return None
-	return  obj.appModule.appName in supportedWebAppHosts
+		return False
+	return obj.appModule.appName in SUPPORTED_HOSTS
 
 
 def VirtualBuffer_changeNotify(cls, rootDocHandle, rootID):
@@ -336,10 +327,10 @@ def virtualBuffer_loadBufferDone(self, success=True):
 	virtualBuffer_loadBufferDone.super.__get__(self)(success=success)
 
 
-def sendWebAppEvent(eventName, obj, webApp=None):
-	if webApp is None:
+def sendWebModuleEvent(eventName, obj, webModule=None):
+	if webModule is None:
 		return
-	scheduler.send(eventName="webApp", name=eventName, obj=obj, webApp=webApp)
+	scheduler.send(eventName="webModule", name=eventName, obj=obj, webModule=webModule)
 
 
 def eventExecuter_gen(self, eventName, obj):
@@ -354,18 +345,18 @@ def eventExecuter_gen(self, eventName, obj):
 			yield func, (obj, self.next)
 
 	# webApp level
-	if  not supportWebApp(obj) and eventName in ["gainFocus"] and activeWebApp is not None:
+	if  not canHaveWebAccessSupport(obj) and eventName in ["gainFocus"] and activeWebModule is not None:
 		# log.info("Received event %s on a non-hosted object" % eventName)
 		webAppLoseFocus(obj)
 	else:
-		webApp = obj.webAccess.webModule if isinstance(obj, overlay.WebAccessObject) else None
-		if webApp is None:
-			if activeWebApp is not None and obj.hasFocus:
+		webModule = obj.webAccess.webModule if isinstance(obj, overlay.WebAccessObject) else None
+		if webModule is None:
+			if activeWebModule is not None and obj.hasFocus:
 				#log.info("Disabling active webApp event %s" % eventName)
 				webAppLoseFocus(obj)
 		else:
 			# log.info("Getting method %s -> %s" %(webApp.name, funcName))
-			func = getattr(webApp, funcName, None)
+			func = getattr(webModule, funcName, None)
 			if func:
 				yield func,(obj, self.next)
 
diff --git a/addon/globalPlugins/webAccess/gui/webModulesManager.py b/addon/globalPlugins/webAccess/gui/webModulesManager.py
index 6b815b0d..0dcf84e1 100644
--- a/addon/globalPlugins/webAccess/gui/webModulesManager.py
+++ b/addon/globalPlugins/webAccess/gui/webModulesManager.py
@@ -20,7 +20,11 @@
 # See the file COPYING.txt at the root of this distribution for more details.
 
 
-__author__ = "Julien Cochuyt <j.cochuyt@accessolutions.fr>"
+__authors__ = (
+	"Julien Cochuyt <j.cochuyt@accessolutions.fr>",
+	"André-Abush Clause <a.clause@accessolutions.fr>",
+	"Gatien Bouyssou <gatien.bouyssou@francetravail.fr>",
+)
 
 
 import os
@@ -228,9 +232,11 @@ def onModulesListItemSelected(self, evt):
 		self.moduleEditButton.Enable(item is not None)
 		self.rulesManagerButton.Enable(
 			item is not None
-			and hasattr(item, "markerManager")
-			and item.markerManager.isReady
-			)
+			# FIXME: This test never succeeds as a live WebModule is not
+			# taken from the context.
+			# TODO: Remove this restriction for issue #42
+			and item.ruleManager.isReady
+		)
 		self.moduleDeleteButton.Enable(item is not None)
 
 	def onRulesManager(self, evt=None):
@@ -289,4 +295,4 @@ def Show(self, context):
 		self.Fit()
 		self.modulesList.SetFocus()
 		self.CentreOnScreen()
-		return super().Show()
\ No newline at end of file
+		return super().Show()
diff --git a/addon/globalPlugins/webAccess/nodeHandler.py b/addon/globalPlugins/webAccess/nodeHandler.py
index 6dcacef8..2f3682ef 100644
--- a/addon/globalPlugins/webAccess/nodeHandler.py
+++ b/addon/globalPlugins/webAccess/nodeHandler.py
@@ -273,7 +273,7 @@ def update(self):
 		self.identifier = time.time()
 		# logTime ("Update node manager %d nodes" % len(fields), t)
 		self.updating = False
-		# playWebAppSound ("tick")
+		# playWebAccessSound("tick")
 		self._curNode = self.caretNode = self.getCaretNode()
 		try:
 			info = self.treeInterceptor.makeTextInfo(textInfos.POSITION_LAST)
@@ -549,7 +549,7 @@ def isReady(self):
 
 	def checkNodeManager(self):
 		if self.nodeManager is None or not self.nodeManager.isReady:
-			playWebAppSound("keyError")
+			playWebAccessSound("keyError")
 			return False
 		else:
 			return True
diff --git a/addon/globalPlugins/webAccess/overlay.py b/addon/globalPlugins/webAccess/overlay.py
index 87607c7d..8b0da048 100644
--- a/addon/globalPlugins/webAccess/overlay.py
+++ b/addon/globalPlugins/webAccess/overlay.py
@@ -23,7 +23,11 @@
 WebAccess overlay classes
 """
 
-__author__ = "Julien Cochuyt <j.cochuyt@accessolutions.fr>"
+__authors__ = (
+	"Julien Cochuyt <j.cochuyt@accessolutions.fr>",
+	"André-Abush Clause <a.clause@accessolutions.fr>",
+	"Gatien Bouyssou <gatien.bouyssou@francetravail.fr>",
+)
 
 
 import weakref
@@ -192,7 +196,7 @@ def treeInterceptor(self):
 
 	@property
 	def webModule(self):
-		from . import supportWebApp, webAccessEnabled
+		from . import canHaveWebAccessSupport, webAccessEnabled
 		if not webAccessEnabled:
 			return None
 		ti = self.treeInterceptor
@@ -202,7 +206,7 @@ def webModule(self):
 		webModule = self._webModule
 		if not webModule:
 			obj = ti.rootNVDAObject
-			if not supportWebApp(obj):
+			if not canHaveWebAccessSupport(obj):
 				return None
 			from . import webModuleHandler
 			try:
diff --git a/addon/globalPlugins/webAccess/ruleHandler/__init__.py b/addon/globalPlugins/webAccess/ruleHandler/__init__.py
index bf694e6e..4f6b2061 100644
--- a/addon/globalPlugins/webAccess/ruleHandler/__init__.py
+++ b/addon/globalPlugins/webAccess/ruleHandler/__init__.py
@@ -59,7 +59,7 @@
 from ..webAppLib import (
 	html,
 	logTimeStart,
-	playWebAppSound,
+	playWebAccessSound,
 )
 from .. import webAppScheduler
 from . import ruleTypes
@@ -107,7 +107,7 @@ def showManager(context):
 	webModule = context["webModule"]
 	mgr = webModule.ruleManager
 	if not mgr.isReady:
-		playWebAppSound("keyError")
+		playWebAccessSound("keyError")
 		time.sleep(0.2)
 		speech.cancelSpeech()
 		ui.message(_("Not ready"))
@@ -129,7 +129,7 @@ def __init__(self, warningMessage):
 			self.__class__.__gestures["kb:control+shift+%s" % character] = "notAssigned"
 
 	def script_notAssigned(self, gesture):
-		playWebAppSound("keyError")
+		playWebAccessSound("keyError")
 		callLater(200, ui.message, self.warningMessage)
 
 	__gestures = {}
@@ -397,7 +397,7 @@ def update(self, nodeManager=None, force=False):
 					self.zone = None
 			#logTime("update marker", t)
 			if self.isReady:
-				webAppScheduler.scheduler.send(eventName="markerManagerUpdated", markerManager=self)
+				webAppScheduler.scheduler.send(eventName="ruleManagerUpdated", ruleManager=self)
 				self.timerCheckAutoAction = threading.Timer(
 					1,  # Accepts floating point number for sub-second precision
 					self.checkAutoAction
@@ -416,7 +416,12 @@ def checkPageTitle(self):
 		webModule = self.webModule
 		if title != webModule.activePageTitle:
 			webModule.activePageTitle = title
-			webAppScheduler.scheduler.send(eventName="webApp", name="webApp_pageChanged", obj=title, webApp=webModule)
+			webAppScheduler.scheduler.send(
+				eventName="webModule",
+				name="webModule_pageChanged",
+				obj=title,
+				webModule=webModule
+			)
 			return True
 		return False
 
@@ -441,7 +446,7 @@ def checkAutoAction(self):
 					if (lastText is None or text != lastText):
 						self.triggeredIdentifiers[controlIdentifier] = text
 						if autoActionName == "speak":
-							playWebAppSound("errorMessage")
+							playWebAccessSound("errorMessage")
 						elif autoActionName == "moveto":
 							if lastText is None:
 								# only if it's a new identifier
@@ -648,7 +653,7 @@ def quickNav(
 		quiet=False,
 	):
 		if not self.isReady:
-			playWebAppSound("keyError")
+			playWebAccessSound("keyError")
 			ui.message(_("Not ready"))
 			return None
 
@@ -657,7 +662,7 @@ def quickNav(
 			position = html.getCaretInfo()
 
 		if position is None:
-			playWebAppSound("keyError")
+			playWebAccessSound("keyError")
 			ui.message(_("Not ready"))
 			return None
 
@@ -675,11 +680,11 @@ def quickNav(
 			)
 			if result:
 				if not relative:
-					playWebAppSound("loop")
+					playWebAccessSound("loop")
 					time.sleep(0.2)
 				break
 		else:
-			playWebAppSound("keyError")
+			playWebAccessSound("keyError")
 			time.sleep(0.2)
 			if quiet:
 				return False
diff --git a/addon/globalPlugins/webAccess/webAppLib/__init__.py b/addon/globalPlugins/webAccess/webAppLib/__init__.py
index 6aadbc49..c8257fc1 100644
--- a/addon/globalPlugins/webAccess/webAppLib/__init__.py
+++ b/addon/globalPlugins/webAccess/webAppLib/__init__.py
@@ -22,7 +22,11 @@
 # Get ready for Python 3
 
 
-__author__ = "Frédéric Brugnot <f.brugnot@accessolutions.fr>"
+__authors__ = (
+	"Frédéric Brugnot <f.brugnot@accessolutions.fr>",
+	"Julien Cochuyt <j.cochuyt@accessolutions.fr>",
+	"André-Abush Clause <a.clause@accessolutions.fr>",
+)
 
 
 import os
@@ -62,12 +66,12 @@ def speechOn(delay=0):
 	api.processPendingEvents ()
 	speech.setSpeechMode(speech.SpeechMode.talk)
 
-def playWebAppSound (name):
+def playWebAccessSound(name):
 	from ... import webAccess
 	try:
 		playSound(os.path.join(webAccess.SOUND_DIRECTORY, "%s.wav" % name))
-	except:
-		pass
+	except Exception:
+		log.exception()
 
 def playSound(sound):
 	sound = os.path.abspath(os.path.join(os.path.dirname(__file__), sound))
diff --git a/addon/globalPlugins/webAccess/webAppScheduler.py b/addon/globalPlugins/webAccess/webAppScheduler.py
index 269d3c1e..a12e940a 100644
--- a/addon/globalPlugins/webAccess/webAppScheduler.py
+++ b/addon/globalPlugins/webAccess/webAppScheduler.py
@@ -85,7 +85,7 @@ def run(self):
 
 				else:
 					log.info("event %s is not found" % eventName)
-		log.info  ("webAppScheduler stopped !")
+		log.info("webAppScheduler stopped!")
 
 	def send(self, **kwargs):
 		self.queue.put(kwargs)
@@ -108,10 +108,10 @@ def event_timeout(self):
 	def fakeNext(self = None):
 		return True
 
-	def event_webApp(self, name=None, obj=None, webApp=None):
+	def event_webModule(self, name=None, obj=None, webModule=None):
 		funcName = 'event_%s' % name
-		#log.info("webApp %s will handle the event %s" % (webApp.name, name))
-		func = getattr(webApp, funcName, None)
+		#log.info("webModule %s will handle the event %s" % (webModule.name, name))
+		func = getattr(webModule, funcName, None)
 		if func:
 			func(obj, self.fakeNext)
 	
@@ -153,10 +153,9 @@ def event_nodeManagerUpdated(self, nodeManager):
 			return
 		nodeManager.treeInterceptor.webAccess.ruleManager.update(nodeManager)
 
-	def event_markerManagerUpdated(self, markerManager):
+	def event_ruleManagerUpdated(self, ruleManager):
 		# Doesn't work outside of the main thread for Google Chrome 83
-		wx.CallAfter(markerManager.checkPageTitle)
-		# markerManager.checkAutoAction()
+		wx.CallAfter(ruleManager.checkPageTitle)
 
 	def event_gainFocus(self, obj):
 		pass
@@ -169,7 +168,7 @@ def onNodeMoveto(self, node, reason):
 	
 		if webModule is not None:
 			scheduler.send(
-				eventName="webApp",
+				eventName="webModule",
 				name='node_gainFocus',
-				obj=node, webApp=webModule
-				)
+				obj=node, webModule=webModule
+			)
diff --git a/addon/globalPlugins/webAccess/webModuleHandler/webModule.py b/addon/globalPlugins/webAccess/webModuleHandler/webModule.py
index 21de1f58..db6e051a 100644
--- a/addon/globalPlugins/webAccess/webModuleHandler/webModule.py
+++ b/addon/globalPlugins/webAccess/webModuleHandler/webModule.py
@@ -48,7 +48,7 @@
 import ui
 from ..lib.markdown2 import markdown
 from ..lib.packaging import version
-from ..webAppLib import playWebAppSound
+from ..webAppLib import playWebAccessSound
 from .. import ruleHandler
 
 class InvalidApiVersion(version.InvalidVersion):
@@ -280,15 +280,17 @@ def _setLayeredProperty(self, name, value):
 				layer.dirty = True
 				data["overrides"][name] = overridden
 
-	def event_webApp_pageChanged(self, pageTitle, nextHandler):
+	def event_webModule_pageChanged(self, pageTitle, nextHandler):
 		speech.cancelSpeech()
-		playWebAppSound("pageChanged")
+		playWebAccessSound("pageChanged")
 		speech.speakMessage(pageTitle)
 
-	def event_webApp_gainFocus(self, obj, nextHandler):
+	# Currently dead code, but will likely be revived for issue #17
+	def event_webModule_gainFocus(self, obj, nextHandler):
 		if obj.role not in [controlTypes.ROLE_DOCUMENT, controlTypes.ROLE_FRAME, controlTypes.ROLE_INTERNALFRAME]:
 			nextHandler()
 
+	# Currently dead code, but will likely be revived for issue #17
 	def event_focusEntered(self, obj, nextHandler):
 		if obj.role != controlTypes.ROLE_DOCUMENT:
 			nextHandler()
@@ -296,8 +298,8 @@ def event_focusEntered(self, obj, nextHandler):
 	def event_gainFocus(self, obj, nextHandler):
 		nextHandler()
 
-	def event_webApp_loseFocus(self, obj, nextHandler):
-		playWebAppSound("webAppLoseFocus")
+	def event_webModule_loseFocus(self, obj, nextHandler):
+		playWebAccessSound("webAppLoseFocus")
 		nextHandler()
 
 	def script_contextualHelp(self, gesture):