55"""
66
77import asyncio
8+ import logging
89import threading
910from concurrent .futures import ThreadPoolExecutor
10- from typing import Optional , Callable , Any
11- import logging
11+ from typing import Any , Callable , Optional
1212
1313logger = logging .getLogger (__name__ )
1414
1717
1818try :
1919 import gi
20- gi .require_version ('Atspi' , '2.0' )
20+
21+ gi .require_version ("Atspi" , "2.0" )
2122 from gi .repository import Atspi
2223
2324 ROLE_MAPPING = {
7778 Atspi = None
7879
7980
80- from .references import (
81- ElementReference , ElementRole , ElementBounds , ElementState , ReferenceManager
81+ from .references import ( # noqa: E402
82+ ElementBounds ,
83+ ElementReference ,
84+ ElementRole ,
85+ ElementState ,
86+ ReferenceManager ,
8287)
8388
8489
@@ -97,10 +102,10 @@ def _get_state_from_atspi(state_set) -> ElementState:
97102 return ElementState ()
98103
99104 return ElementState (
100- visible = state_set .contains (Atspi .StateType .VISIBLE ) and
101- state_set .contains (Atspi .StateType .SHOWING ),
102- enabled = state_set .contains (Atspi .StateType .ENABLED ) and
103- state_set .contains (Atspi .StateType .SENSITIVE ),
105+ visible = state_set .contains (Atspi .StateType .VISIBLE )
106+ and state_set .contains (Atspi .StateType .SHOWING ),
107+ enabled = state_set .contains (Atspi .StateType .ENABLED )
108+ and state_set .contains (Atspi .StateType .SENSITIVE ),
104109 focused = state_set .contains (Atspi .StateType .FOCUSED ),
105110 selected = state_set .contains (Atspi .StateType .SELECTED ),
106111 checked = state_set .contains (Atspi .StateType .CHECKED ),
@@ -123,12 +128,7 @@ def _get_bounds_from_atspi(accessible) -> ElementBounds:
123128 component = accessible .get_component_iface ()
124129 if component :
125130 rect = component .get_extents (Atspi .CoordType .SCREEN )
126- return ElementBounds (
127- x = rect .x ,
128- y = rect .y ,
129- width = rect .width ,
130- height = rect .height
131- )
131+ return ElementBounds (x = rect .x , y = rect .y , width = rect .width , height = rect .height )
132132 except Exception :
133133 pass
134134 return ElementBounds (x = 0 , y = 0 , width = 0 , height = 0 )
@@ -229,7 +229,7 @@ def _build_tree_sync(
229229 current_depth : int = 0 ,
230230 app_name : Optional [str ] = None ,
231231 window_title : Optional [str ] = None ,
232- parent_ref : Optional [str ] = None
232+ parent_ref : Optional [str ] = None ,
233233 ) -> list [ElementReference ]:
234234 """Build element tree from accessible (sync)."""
235235 refs = []
@@ -261,7 +261,7 @@ def _build_tree_sync(
261261 available_actions = _get_available_actions (accessible ),
262262 description = accessible .get_description () or "" ,
263263 value = _get_element_value (accessible ),
264- atspi_path = str (accessible .get_id ()) if hasattr (accessible , ' get_id' ) else None ,
264+ atspi_path = str (accessible .get_id ()) if hasattr (accessible , " get_id" ) else None ,
265265 atspi_accessible = accessible ,
266266 parent_ref = parent_ref ,
267267 app_name = app_name ,
@@ -283,7 +283,7 @@ def _build_tree_sync(
283283 current_depth = current_depth + 1 ,
284284 app_name = app_name ,
285285 window_title = window_title ,
286- parent_ref = ref_id
286+ parent_ref = ref_id ,
287287 )
288288 for child_ref in child_refs :
289289 if child_ref .parent_ref == ref_id :
@@ -298,9 +298,7 @@ def _build_tree_sync(
298298 return refs
299299
300300 async def build_tree (
301- self ,
302- app_name_filter : Optional [str ] = None ,
303- max_depth : int = 15
301+ self , app_name_filter : Optional [str ] = None , max_depth : int = 15
304302 ) -> list [ElementReference ]:
305303 """Build the full accessibility tree.
306304
@@ -333,9 +331,7 @@ def _build():
333331 return await self ._run_sync (_build )
334332
335333 async def build_tree_for_window (
336- self ,
337- window_accessible ,
338- max_depth : int = 15
334+ self , window_accessible , max_depth : int = 15
339335 ) -> list [ElementReference ]:
340336 """Build accessibility tree for a specific window only.
341337
@@ -368,7 +364,7 @@ def _build():
368364 window_accessible ,
369365 max_depth = max_depth ,
370366 app_name = app_name ,
371- window_title = window_title
367+ window_title = window_title ,
372368 )
373369 except Exception as e :
374370 logger .error (f"Error building tree for window: { e } " )
@@ -377,9 +373,7 @@ def _build():
377373 return await self ._run_sync (_build )
378374
379375 async def build_tree_for_windows (
380- self ,
381- window_accessibles : list ,
382- max_depth : int = 15
376+ self , window_accessibles : list , max_depth : int = 15
383377 ) -> list [ElementReference ]:
384378 """Build accessibility tree for multiple windows.
385379
@@ -411,7 +405,7 @@ def _build():
411405 window_accessible ,
412406 max_depth = max_depth ,
413407 app_name = app_name ,
414- window_title = window_title
408+ window_title = window_title ,
415409 )
416410 all_refs .extend (refs )
417411 except Exception as e :
@@ -517,9 +511,7 @@ def _get_element_at_point_sync(self, x: int, y: int):
517511 if app :
518512 component = app .get_component_iface ()
519513 if component :
520- accessible = component .get_accessible_at_point (
521- x , y , Atspi .CoordType .SCREEN
522- )
514+ accessible = component .get_accessible_at_point (x , y , Atspi .CoordType .SCREEN )
523515 if accessible :
524516 return accessible
525517 except Exception :
0 commit comments