Replace event manager with Orca 50 model

This commit is contained in:
2026-04-11 03:12:21 -04:00
parent b641d6d8a4
commit bff131db18
6 changed files with 2793 additions and 1913 deletions
+27 -72
View File
@@ -51,7 +51,6 @@ if TYPE_CHECKING:
from .input_event import InputEvent
from .input_event_manager import InputEventManager
from .event_manager import EventManager
from .compositor_state_adapter import CompositorStateAdapter
from .signal_manager import SignalManager
from .dynamic_api_manager import DynamicApiManager
from .speech import Speech
@@ -258,14 +257,16 @@ except Exception:
from . import braille
from . import debug
from . import ax_device_manager
from . import command_manager
from . import event_manager
from . import compositor_state_adapter
from . import keybindings
from . import learn_mode_presenter
from . import logger
from . import mako_notification_monitor
from . import messages
from . import notification_presenter
from . import presentation_manager
from . import focus_manager
from . import cthulhu_modifier_manager
from . import cthulhu_state
@@ -408,7 +409,7 @@ def deviceChangeHandler(deviceManager: Any, device: Any) -> None:
if source == Gdk.InputSource.KEYBOARD:
msg: str = "CTHULHU: Keyboard change detected, re-creating the xmodmap"
debug.printMessage(debug.LEVEL_INFO, msg, True)
cthulhu_modifier_manager.getManager().refreshCthulhuModifiers("Keyboard change detected.")
cthulhu_modifier_manager.get_manager().refresh_cthulhu_modifiers("Keyboard change detected.")
def loadUserSettings(script: Optional[Any] = None, inputEvent: Optional[Any] = None, skipReloadMessage: bool = False) -> bool:
"""Loads (and reloads) the user settings module, reinitializing
@@ -421,23 +422,16 @@ def loadUserSettings(script: Optional[Any] = None, inputEvent: Optional[Any] = N
global _userSettings
# Shutdown the output drivers and give them a chance to die.
player = sound.getPlayer()
player.shutdown()
speech.shutdown()
braille.shutdown()
cthulhuApp.eventManager.pause_queuing(True, True, "Loading user settings.")
cthulhuApp.scriptManager.deactivate()
cthulhuApp.getSignalManager().emitSignal('load-setting-begin')
reloaded: bool = False
reloaded: bool = _userSettings is not None
if _userSettings:
_profile = cthulhuApp.settingsManager.getSetting('activeProfile')[1]
try:
_userSettings = cthulhuApp.settingsManager.getGeneralSettings(_profile)
cthulhuApp.settingsManager.setProfile(_profile)
reloaded = True
except ImportError:
debug.printException(debug.LEVEL_INFO)
except Exception:
@@ -456,49 +450,22 @@ def loadUserSettings(script: Optional[Any] = None, inputEvent: Optional[Any] = N
cthulhuApp.settingsManager.loadAppSettings(script)
if cthulhuApp.settingsManager.getSetting('enableSpeech'):
msg = 'CTHULHU: About to enable speech'
debug.printMessage(debug.LEVEL_INFO, msg, True)
try:
speech.init()
if reloaded and not skipReloadMessage:
script.speakMessage(messages.SETTINGS_RELOADED)
except Exception:
debug.printException(debug.LEVEL_SEVERE)
else:
msg = 'CTHULHU: Speech is not enabled in settings'
debug.printMessage(debug.LEVEL_INFO, msg, True)
if cthulhuApp.settingsManager.getSetting('enableBraille'):
msg = 'CTHULHU: About to enable braille'
debug.printMessage(debug.LEVEL_INFO, msg, True)
try:
braille.init(_processBrailleEvent)
except Exception:
debug.printException(debug.LEVEL_WARNING)
msg = 'CTHULHU: Could not initialize connection to braille.'
debug.printMessage(debug.LEVEL_WARNING, msg, True)
else:
msg = 'CTHULHU: Braille is not enabled in settings'
debug.printMessage(debug.LEVEL_INFO, msg, True)
command_manager.get_manager().load_keyboard_layout()
presentation_manager.get_manager().start_presenters()
if reloaded and not skipReloadMessage:
presentation_manager.get_manager().speak_message(messages.SETTINGS_RELOADED)
if cthulhuApp.settingsManager.getSetting('enableMouseReview'):
mouse_review.getReviewer().activate()
else:
mouse_review.getReviewer().deactivate()
if cthulhuApp.settingsManager.getSetting('enableSound'):
player.init()
cthulhu_modifier_manager.get_manager().refresh_cthulhu_modifiers("Loading user settings.")
cthulhu_modifier_manager.getManager().refreshCthulhuModifiers("Loading user settings.")
# Activate core systems FIRST before loading plugins
cthulhuApp.compositorStateAdapter.activate()
cthulhuApp.scriptManager.activate()
ax_device_manager.get_manager().activate()
cthulhuApp.eventManager.activate()
cthulhuApp.getSignalManager().emitSignal('load-setting-begin')
cthulhuApp.scriptManager.activate()
cthulhuApp.eventManager.pause_queuing(False, False, "User settings loaded.")
# NOW load plugins after script system is ready
activePluginsSetting = cthulhuApp.settingsManager.getSetting('activePlugins') or []
@@ -771,34 +738,28 @@ def shutdown(script: Optional[Any] = None, inputEvent: Optional[Any] = None) ->
signal.signal(signal.SIGALRM, settings.timeoutCallback)
signal.alarm(settings.timeoutTime)
cthulhu_state.activeScript.presentationInterrupt()
presManager = presentation_manager.get_manager()
presManager.interrupt_presentation()
presManager.present_message(messages.STOP_CTHULHU)
cthulhuApp.getSignalManager().emitSignal('stop-application-completed')
sound_theme_manager.getManager().playStopSound(wait=True, timeoutSeconds=1)
cthulhuApp.getPluginSystemManager().unloadAllPlugins(ForceAllPlugins=True)
cthulhuApp.getMakoNotificationMonitor().stop()
# Deactivate the event manager first so that it clears its queue and will not
# accept new events. Then let the script manager unregister script event listeners.
cthulhuApp.compositorStateAdapter.deactivate()
cthulhuApp.eventManager.deactivate()
# Pause event queuing first so that it clears its queue and will not accept
# new events. Then let the script manager unregister script event listeners.
cthulhuApp.eventManager.pause_queuing(True, True, "Shutting down.")
cthulhuApp.scriptManager.deactivate()
# Shutdown all the other support.
#
if settings.enableSpeech:
speech.shutdown()
if settings.enableBraille:
braille.shutdown()
if settings.enableSound:
player = sound.getPlayer()
player.shutdown()
cthulhuApp.eventManager.deactivate()
presentation_manager.get_manager().shutdown_presenters()
ax_device_manager.get_manager().deactivate()
if settings.timeoutCallback and (settings.timeoutTime > 0):
signal.alarm(0)
_initialized = False
cthulhu_modifier_manager.getManager().unsetCthulhuModifiers("Shutting down.")
cthulhu_modifier_manager.get_manager().unset_cthulhu_modifiers("Shutting down.")
debug.printMessage(debug.LEVEL_INFO, 'CTHULHU: Quitting Atspi main event loop', True)
Atspi.event_quit()
@@ -853,7 +814,7 @@ def crashOnSignal(signum: int, frame: Optional[FrameType]) -> None:
msg: str = f"CTHULHU: Shutting down and exiting due to signal={signum} {signalString}"
debug.printMessage(debug.LEVEL_SEVERE, msg, True)
debug.printStack(debug.LEVEL_SEVERE)
cthulhu_modifier_manager.getManager().unsetCthulhuModifiers("Crashed")
cthulhu_modifier_manager.get_manager().unset_cthulhu_modifiers("Crashed")
sys.exit(1)
def main() -> int:
@@ -956,11 +917,8 @@ class Cthulhu(GObject.Object):
# add members
self.resourceManager: resource_manager.ResourceManager = resource_manager.ResourceManager(self)
self.settingsManager: SettingsManager = settings_manager.SettingsManager(self) # Directly instantiate
self.eventManager: EventManager = event_manager.EventManager(self) # Directly instantiate
self.compositorStateAdapter: CompositorStateAdapter = compositor_state_adapter.CompositorStateAdapter()
self.eventManager.set_compositor_state_adapter(self.compositorStateAdapter)
self.scriptManager: ScriptManager = script_manager.ScriptManager(self) # Directly instantiate
script_manager._manager = self.scriptManager
self.eventManager: EventManager = event_manager.get_manager()
self.scriptManager: ScriptManager = script_manager.get_manager()
self.logger: logger.Logger = logger.Logger() # Directly instantiate
self.signalManager: SignalManager = signal_manager.SignalManager(self)
self.dynamicApiManager: DynamicApiManager = dynamic_api_manager.DynamicApiManager(self)
@@ -992,9 +950,6 @@ class Cthulhu(GObject.Object):
def getEventManager(self) -> EventManager:
return self.eventManager
def getCompositorStateAdapter(self) -> CompositorStateAdapter:
return self.compositorStateAdapter
def getSettingsManager(self) -> SettingsManager:
return self.settingsManager
+763 -1413
View File
File diff suppressed because it is too large Load Diff
@@ -8,11 +8,9 @@ from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from cthulhu import cthulhu_state
from cthulhu import cthulhu
from cthulhu import compositor_state_adapter
from cthulhu import compositor_state_types
from cthulhu import compositor_state_wayland
from cthulhu.wayland_protocols import ext_workspace_v1
class FakeWorkspaceBackend:
@@ -136,6 +134,8 @@ class CompositorStateAdapterRegressionTests(unittest.TestCase):
self.assertIsNone(backend._display)
def test_local_ext_workspace_wrapper_supports_base_pywayland_without_distro_protocol_module(self) -> None:
from cthulhu.wayland_protocols import ext_workspace_v1
fakeClientModule = types.ModuleType("pywayland.client")
class FakeDisplay:
@@ -309,29 +309,5 @@ class CompositorStateAdapterRegressionTests(unittest.TestCase):
self.assertEqual(cthulhu_state.compositorSnapshot.active_workspace_ids, frozenset({"ws-2"}))
self.assertFalse(cthulhu_state.pauseAtspiChurn)
def test_event_manager_startup_resyncs_adapter_after_focus_recovery(self) -> None:
adapter = mock.Mock()
adapter.sync_accessible_context = mock.Mock(return_value=None)
listener = mock.Mock()
window = object()
focusedObject = object()
with (
mock.patch.object(cthulhu.event_manager.Atspi.EventListener, "new", return_value=listener),
mock.patch.object(cthulhu.event_manager.AXUtilities, "can_be_active_window", return_value=False),
mock.patch.object(cthulhu.event_manager.AXUtilities, "find_active_window", return_value=window),
mock.patch.object(cthulhu.event_manager.AXUtilities, "get_focused_object", return_value=focusedObject),
mock.patch.object(cthulhu.event_manager.cthulhu, "setActiveWindow") as setActiveWindow,
mock.patch.object(cthulhu.event_manager.cthulhu, "setLocusOfFocus") as setLocusOfFocus,
):
manager = cthulhu.event_manager.EventManager(mock.Mock())
manager.set_compositor_state_adapter(adapter)
manager._sync_focus_on_startup()
setActiveWindow.assert_called_once_with(window, alsoSetLocusOfFocus=True, notifyScript=False)
setLocusOfFocus.assert_called_once_with(None, focusedObject, notifyScript=True, force=True)
adapter.sync_accessible_context.assert_called_once_with("event-manager-startup")
if __name__ == "__main__":
unittest.main()
File diff suppressed because it is too large Load Diff
@@ -1,209 +0,0 @@
import sys
import types
import unittest
from pathlib import Path
from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from cthulhu import cthulhu_state
from cthulhu import compositor_state_types
stubCthulhu = types.ModuleType("cthulhu.cthulhu")
stubCthulhu.cthulhuApp = mock.Mock()
sys.modules.setdefault("cthulhu.cthulhu", stubCthulhu)
from cthulhu import event_manager
class FakeEvent:
def __init__(self, event_type, source="same", detail1=0, detail2=0, any_data=None):
self.type = event_type
self.source = source
self.detail1 = detail1
self.detail2 = detail2
self.any_data = any_data
class EventManagerCompositorContextRegressionTests(unittest.TestCase):
def setUp(self) -> None:
self.originalPauseAtspiChurn = cthulhu_state.pauseAtspiChurn
self.originalPrioritizedDesktopContextToken = cthulhu_state.prioritizedDesktopContextToken
self.originalCompositorSnapshot = cthulhu_state.compositorSnapshot
self.originalActiveScript = cthulhu_state.activeScript
self.addCleanup(self._restore_cthulhu_state)
self.listener = mock.Mock()
self.listenerPatch = mock.patch.object(
event_manager.Atspi.EventListener,
"new",
return_value=self.listener,
)
self.listenerPatch.start()
self.addCleanup(self.listenerPatch.stop)
self.manager = event_manager.EventManager(mock.Mock(), asyncMode=False)
self.manager._active = True
self.manager._context_token_for_event = mock.Mock(side_effect=lambda event: event.source)
cthulhu_state.pauseAtspiChurn = False
cthulhu_state.prioritizedDesktopContextToken = None
cthulhu_state.compositorSnapshot = None
cthulhu_state.activeScript = None
def _restore_cthulhu_state(self) -> None:
cthulhu_state.pauseAtspiChurn = self.originalPauseAtspiChurn
cthulhu_state.prioritizedDesktopContextToken = self.originalPrioritizedDesktopContextToken
cthulhu_state.compositorSnapshot = self.originalCompositorSnapshot
cthulhu_state.activeScript = self.originalActiveScript
def test_set_compositor_state_adapter_registers_compositor_listener(self) -> None:
adapter = mock.Mock()
self.manager.set_compositor_state_adapter(adapter)
adapter.add_listener.assert_called_once_with(self.manager._handle_compositor_signal)
def test_pause_signal_updates_churn_state_and_resume_clears_it(self) -> None:
snapshot = compositor_state_types.DesktopContextSnapshot(session_type="wayland")
self.manager._handle_compositor_signal(
compositor_state_types.CompositorStateEvent(
compositor_state_types.PAUSE_ATSPI_CHURN,
reason="workspace-transition",
snapshot=snapshot,
payload={"context_token": "current"},
)
)
self.assertTrue(cthulhu_state.pauseAtspiChurn)
self.assertTrue(self.manager._churnSuppressed)
self.manager._handle_compositor_signal(
compositor_state_types.CompositorStateEvent(
compositor_state_types.RESUME_ATSPI_CHURN,
reason="workspace-transition",
snapshot=snapshot,
payload={"context_token": "current"},
)
)
self.assertFalse(cthulhu_state.pauseAtspiChurn)
self.assertFalse(self.manager._churnSuppressed)
def test_stale_context_event_is_obsolete_while_churn_is_paused(self) -> None:
self.manager._churnSuppressed = True
self.manager._prioritizedContextToken = "current"
event = FakeEvent("object:children-changed:add", source="stale")
self.assertTrue(self.manager._is_obsolete_by_context(event))
def test_flush_signal_removes_stale_events_from_queue(self) -> None:
self.manager._churnSuppressed = False
self.manager._prioritizedContextToken = "current"
staleEvent = FakeEvent("object:children-changed:add", source="stale")
currentEvent = FakeEvent("object:children-changed:add", source="current")
self.manager._eventQueue.put(staleEvent)
self.manager._eventQueue.put(currentEvent)
self.manager._handle_compositor_signal(
compositor_state_types.CompositorStateEvent(
compositor_state_types.FLUSH_STALE_ATSPI_EVENTS,
reason="resume",
snapshot=compositor_state_types.DesktopContextSnapshot(session_type="wayland"),
payload={"context_token": "current"},
)
)
self.assertEqual(list(self.manager._eventQueue.queue), [currentEvent])
def test_stale_background_event_does_not_activate_script_during_suppression(self) -> None:
script = mock.Mock()
script.isActivatableEvent.return_value = True
script.forceScriptActivation.return_value = False
self.manager._churnSuppressed = True
self.manager._prioritizedContextToken = "current"
event = FakeEvent("object:state-changed:showing", source="old")
result, reason = self.manager._isActivatableEvent(event, script)
self.assertFalse(result)
self.assertIn("compositor-prioritized context", reason)
def test_focus_event_syncs_accessible_context_back_into_adapter(self) -> None:
adapter = mock.Mock()
script = mock.Mock()
source = object()
event = FakeEvent("object:state-changed:focused", source=source, detail1=1)
self.manager._compositorStateAdapter = adapter
self.manager._get_scriptForEvent = mock.Mock(return_value=script)
self.manager._isActivatableEvent = mock.Mock(return_value=(False, "already active"))
self.manager._inFlood = mock.Mock(return_value=False)
with (
mock.patch.object(event_manager.debug, "printObjectEvent"),
mock.patch.object(event_manager.debug, "printDetails"),
mock.patch.object(event_manager.debug, "printMessage"),
mock.patch.object(event_manager.debug, "printTokens"),
mock.patch.object(event_manager.AXUtilities, "get_desktop", return_value=object()),
mock.patch.object(event_manager.AXUtilities, "is_defunct", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_iconified", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_frame", return_value=False),
mock.patch.object(event_manager.AXObject, "is_dead", return_value=False),
):
self.manager._processObjectEvent(event)
adapter.sync_accessible_context.assert_called_once_with("object:state-changed:focused")
def test_steam_children_changed_burst_is_suppressed_before_flood_threshold(self) -> None:
app = object()
cthulhu_state.activeScript = mock.Mock(app=app)
firstEvent = FakeEvent("object:children-changed:add", source="steam-context", any_data=object())
secondEvent = FakeEvent("object:children-changed:add", source="steam-context", any_data=object())
with (
mock.patch.object(event_manager.time, "monotonic", side_effect=[100.0, 100.05]),
mock.patch.object(event_manager.debug, "printMessage"),
mock.patch.object(event_manager.debug, "printTokens"),
mock.patch.object(event_manager.debug, "print_log"),
mock.patch.object(event_manager.AXObject, "get_application", return_value=app),
mock.patch.object(event_manager.AXObject, "get_name", return_value="steamwebhelper"),
mock.patch.object(event_manager.AXObject, "get_role", return_value=mock.Mock()),
mock.patch.object(event_manager.AXObject, "is_dead", return_value=False),
mock.patch.object(event_manager.AXUtilities, "has_no_state", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_defunct", return_value=False),
mock.patch.object(event_manager.AXUtilities, "manages_descendants", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_image", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_menu_item", return_value=False),
):
self.manager._isSteamApp = mock.Mock(return_value=True)
self.manager._isSteamNotificationEvent = mock.Mock(return_value=False)
self.assertFalse(self.manager._ignore(firstEvent))
self.assertTrue(self.manager._ignore(secondEvent))
def test_steam_focus_lost_burst_is_ignored_but_focus_gain_is_preserved(self) -> None:
app = object()
cthulhu_state.activeScript = mock.Mock(app=app)
focusLost = FakeEvent("object:state-changed:focused", source="steam-context", detail1=0)
focusGained = FakeEvent("object:state-changed:focused", source="steam-context", detail1=1)
with (
mock.patch.object(event_manager.debug, "printMessage"),
mock.patch.object(event_manager.debug, "printTokens"),
mock.patch.object(event_manager.debug, "print_log"),
mock.patch.object(event_manager.AXObject, "get_application", return_value=app),
mock.patch.object(event_manager.AXObject, "get_name", return_value="steamwebhelper"),
mock.patch.object(event_manager.AXObject, "get_role", return_value=mock.Mock()),
mock.patch.object(event_manager.AXUtilities, "has_no_state", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_defunct", return_value=False),
):
self.manager._isSteamApp = mock.Mock(return_value=True)
self.manager._isSteamNotificationEvent = mock.Mock(return_value=False)
self.assertTrue(self.manager._ignore(focusLost))
self.assertFalse(self.manager._ignore(focusGained))
if __name__ == "__main__":
unittest.main()
@@ -1,193 +0,0 @@
import sys
import types
import unittest
from pathlib import Path
from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from cthulhu import cthulhu_state
stubCthulhu = types.ModuleType("cthulhu.cthulhu")
stubCthulhu.cthulhuApp = mock.Mock()
sys.modules.setdefault("cthulhu.cthulhu", stubCthulhu)
from cthulhu import event_manager
class FakeEvent:
def __init__(self, event_type, source="same", detail1=0, detail2=0, any_data=None):
self.type = event_type
self.source = source
self.detail1 = detail1
self.detail2 = detail2
self.any_data = any_data
class EventManagerRelevanceGateRegressionTests(unittest.TestCase):
def setUp(self) -> None:
self.listener = mock.Mock()
self.listenerPatch = mock.patch.object(
event_manager.Atspi.EventListener,
"new",
return_value=self.listener,
)
self.listenerPatch.start()
self.addCleanup(self.listenerPatch.stop)
self.steamAppPatch = mock.patch.object(event_manager.EventManager, "_isSteamApp", return_value=False)
self.steamNotificationPatch = mock.patch.object(
event_manager.EventManager,
"_isSteamNotificationEvent",
return_value=False,
)
self.steamAppPatch.start()
self.steamNotificationPatch.start()
self.addCleanup(self.steamAppPatch.stop)
self.addCleanup(self.steamNotificationPatch.stop)
self.originalActiveScript = cthulhu_state.activeScript
self.originalLocusOfFocus = cthulhu_state.locusOfFocus
self.addCleanup(self._restore_state)
self.manager = event_manager.EventManager(mock.Mock(), asyncMode=False)
self.manager._active = True
cthulhu_state.activeScript = None
cthulhu_state.locusOfFocus = None
def _restore_state(self) -> None:
cthulhu_state.activeScript = self.originalActiveScript
cthulhu_state.locusOfFocus = self.originalLocusOfFocus
def test_unfocused_web_link_name_change_is_dropped_when_focus_is_stable_elsewhere(self) -> None:
app = object()
focus = object()
source = object()
event = FakeEvent(
"object:property-change:accessible-name",
source=source,
any_data="Diablo II: Resurrected Infernal Edition $39.99",
)
cthulhu_state.activeScript = mock.Mock(app=app)
cthulhu_state.locusOfFocus = focus
with (
mock.patch.object(event_manager.debug, "printMessage"),
mock.patch.object(event_manager.debug, "printTokens"),
mock.patch.object(event_manager.debug, "print_log"),
mock.patch.object(event_manager.AXObject, "get_application", return_value=app),
mock.patch.object(event_manager.AXObject, "get_name", return_value="Chromium"),
mock.patch.object(event_manager.AXObject, "get_role", return_value=event_manager.Atspi.Role.LINK),
mock.patch.object(event_manager.AXObject, "is_dead", return_value=False),
mock.patch.object(event_manager.AXUtilities, "has_no_state", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_defunct", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_focused", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_notification", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_alert", return_value=False),
):
self.assertTrue(self.manager._ignore(event))
def test_focused_web_link_name_change_is_kept(self) -> None:
app = object()
source = object()
event = FakeEvent("object:property-change:accessible-name", source=source, any_data="Cookie Clicker")
cthulhu_state.activeScript = mock.Mock(app=app)
cthulhu_state.locusOfFocus = source
with (
mock.patch.object(event_manager.debug, "printMessage"),
mock.patch.object(event_manager.debug, "printTokens"),
mock.patch.object(event_manager.debug, "print_log"),
mock.patch.object(event_manager.AXObject, "get_application", return_value=app),
mock.patch.object(event_manager.AXObject, "get_name", return_value="Chromium"),
mock.patch.object(event_manager.AXObject, "get_role", return_value=event_manager.Atspi.Role.LINK),
mock.patch.object(event_manager.AXObject, "is_dead", return_value=False),
mock.patch.object(event_manager.AXUtilities, "has_no_state", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_defunct", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_focused", return_value=True),
mock.patch.object(event_manager.AXUtilities, "is_notification", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_alert", return_value=False),
):
self.assertFalse(self.manager._ignore(event))
def test_live_region_name_change_is_kept_even_when_unfocused(self) -> None:
app = object()
focus = object()
source = object()
event = FakeEvent("object:property-change:accessible-name", source=source, any_data="sale updated")
cthulhu_state.activeScript = mock.Mock(app=app)
cthulhu_state.locusOfFocus = focus
def get_attribute(obj, name):
if name == "live":
return "polite"
return ""
with (
mock.patch.object(event_manager.debug, "printMessage"),
mock.patch.object(event_manager.debug, "printTokens"),
mock.patch.object(event_manager.debug, "print_log"),
mock.patch.object(event_manager.AXObject, "get_application", return_value=app),
mock.patch.object(event_manager.AXObject, "get_name", return_value="Chromium"),
mock.patch.object(event_manager.AXObject, "get_role", return_value=event_manager.Atspi.Role.LINK),
mock.patch.object(event_manager.AXObject, "get_attribute", side_effect=get_attribute),
mock.patch.object(event_manager.AXObject, "is_dead", return_value=False),
mock.patch.object(event_manager.AXUtilities, "has_no_state", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_defunct", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_focused", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_notification", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_alert", return_value=False),
):
self.assertFalse(self.manager._ignore(event))
def test_unfocused_focus_loss_is_dropped_when_focus_is_stable_elsewhere(self) -> None:
app = object()
focus = object()
source = object()
event = FakeEvent("object:state-changed:focused", source=source, detail1=0)
cthulhu_state.activeScript = mock.Mock(app=app)
cthulhu_state.locusOfFocus = focus
with (
mock.patch.object(event_manager.debug, "printMessage"),
mock.patch.object(event_manager.debug, "printTokens"),
mock.patch.object(event_manager.debug, "print_log"),
mock.patch.object(event_manager.AXObject, "get_application", return_value=app),
mock.patch.object(event_manager.AXObject, "get_name", return_value="Chromium"),
mock.patch.object(event_manager.AXObject, "get_role", return_value=event_manager.Atspi.Role.LINK),
mock.patch.object(event_manager.AXObject, "is_dead", return_value=False),
mock.patch.object(event_manager.AXUtilities, "has_no_state", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_defunct", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_notification", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_alert", return_value=False),
):
self.assertTrue(self.manager._ignore(event))
def test_repeated_web_children_changed_burst_is_collapsed(self) -> None:
app = object()
focus = object()
source = object()
firstEvent = FakeEvent("object:children-changed:add", source=source, any_data=object())
secondEvent = FakeEvent("object:children-changed:add", source=source, any_data=object())
cthulhu_state.activeScript = mock.Mock(app=app)
cthulhu_state.locusOfFocus = focus
with (
mock.patch.object(event_manager.time, "monotonic", side_effect=[100.0, 100.05]),
mock.patch.object(event_manager.debug, "printMessage"),
mock.patch.object(event_manager.debug, "printTokens"),
mock.patch.object(event_manager.debug, "print_log"),
mock.patch.object(event_manager.AXObject, "get_application", return_value=app),
mock.patch.object(event_manager.AXObject, "get_name", return_value="Chromium"),
mock.patch.object(event_manager.AXObject, "get_role", return_value=event_manager.Atspi.Role.SECTION),
mock.patch.object(event_manager.AXObject, "is_dead", return_value=False),
mock.patch.object(event_manager.AXUtilities, "has_no_state", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_defunct", return_value=False),
mock.patch.object(event_manager.AXUtilities, "manages_descendants", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_image", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_menu_item", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_notification", return_value=False),
mock.patch.object(event_manager.AXUtilities, "is_alert", return_value=False),
):
self.assertFalse(self.manager._ignore(firstEvent))
self.assertTrue(self.manager._ignore(secondEvent))