
    lKj                   t   d Z ddlmZ ddlZddlZddlmZmZmZm	Z	m
Z
 ddlmZmZ ddlmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z*m+Z,m-Z.m/Z0m1Z2m3Z4m5Z6m7Z8m9Z:  ejv                  e<      Z= G d	 d
      Z> G d de>      Z? G d de>      Z@ G d de>      ZA G d de>      ZB G d de>      ZC G d de>      ZD G d deD      ZE G d de>      ZF G d de>      ZG G d de>      ZH G d d e>      ZI G d! d"e>      ZJ G d# d$e>      ZK G d% d&e>      ZL G d' d(e>      ZM G d) d*e>      ZN G d+ d,e>      ZO G d- d.e>      ZP G d/ d0e>      ZQ G d1 d2e>      ZR G d3 d4e>      ZS G d5 d6e>      ZT G d7 d8e>      ZU G d9 d:e>      ZV G d; d<e>      ZW G d= d>e>      ZX G d? d@e>      ZYi ej                  e?ej                  e@ej                  eAej                  eBej                  eCej                  eDej                  eEej                  eFej                  eGej                  eHej                  eIej                  eJej                  eKej                  eLej                  eMej                  eNej                  eOej                  ePej                  eQej                  eRej                  eSej                  eTej                  eUej                  eVej                  eWej                  eXej                  eYej                  eYiZudCdAZv	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dDdBZwy)Ez
Control classes wrapping macOS AXUIElementRef.
Provides a Pythonic, object-oriented interface to accessibility elements
with typed subclasses for specific control types.

Equivalent to the Windows UIA controls.py module, adapted for macOS.
    )annotationsN)AnyCallableListOptionalUnion)AXUIElementCreateApplicationAXUIElementCreateSystemWide   )RoleSubrole	AttributeActionActivationPolicyNames)RectPointSizeGetAttributeSetAttributeGetParameterizedAttributeGetAttributeNamesGetActionNamesPerformActionGetChildrenGetPositionGetSizeGetRectGetChildCountIsAttributeSettableGetElementPidGetScreenSizeGetForegroundWindowPIDActivateApplicationClick
RightClickDoubleClickMiddleClickTypeText	WheelDownWheelUpDragToMoveToc                     e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZed        Z	 d	 	 	 	 	 ddZ	 d	 	 	 	 	 ddZd Z	ddZ
edd	       Zedd
       Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Zed        Zej,                  dd       Zedd       Zedd       Zedd       Zedd       Zej,                  dd       Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Z edd       Z!edd        Z"edd!       Z#edd"       Z$edd#       Z%edd$       Z&edd%       Z'edd&       Z(dd'Z)dd(Z*dd)Z+edd*       Z,edd+       Z-edd,       Z.edd-       Z/edd.       Z0edd/       Z1edd0       Z2edd1       Z3edd2       Z4edd3       Z5edd4       Z6edd5       Z7edd6       Z8edd7       Z9edd8       Z:edd9       Z;ed:        Z<ed;        Z=ed<        Z>ed=        Z?ed>        Z@edd?       ZAedd@       ZB	 d	 	 	 	 	 ddAZCeddB       ZDeddC       ZEeddD       ZFeddE       ZGddFZHddGZIddHZJddIZKddJZLddKZMddLZNddMZOddNZPddOZQddPZRddQZSddRZT	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddSZU	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddTZVddUZW	 d	 	 	 	 	 	 	 ddVZX	 d	 	 	 	 	 	 	 ddWZY	 d	 	 	 	 	 	 	 ddXZZ	 d	 	 	 	 	 	 	 ddYZ[dddZZ\ddd[Z]	 	 d	 	 	 	 	 	 	 dd\Z^dd]Z_	 d	 	 	 	 	 dd^Z`ddd_Za	 d	 dd`Zb	 d	 ddaZc	 d	 ddbZd	 d	 ddcZe	 d	 dddZf	 d	 ddeZg	 d	 ddfZh	 d	 ddgZi	 d	 ddhZj	 d	 ddiZk	 d	 ddjZl	 d	 ddkZm	 d	 ddlZn	 d	 ddmZo	 d	 ddnZp	 d	 ddoZq	 d	 ddpZr	 d	 ddqZs	 d	 ddrZt	 d	 ddsZu	 d	 ddtZv	 d	 dduZw	 d	 ddvZx	 d	 ddwZy	 d	 ddxZz	 d	 ddyZ{	 d	 ddzZ|dd{Z}dd|Z~dd}Zd~ Zy)Controla  
    Base Control class wrapping a macOS AXUIElementRef.
    Equivalent to Windows UIA Control class.

    Provides property-based access to accessibility attributes,
    child navigation, element search, action execution,
    mouse/keyboard interaction, and fluent chaining for child discovery.

    Supports lazy element resolution: construct with search parameters
    and the actual AX element is found on first property access.

    Usage:
        # Direct wrapping
        ctrl = Control(element=some_ax_ref)

        # From PID
        app = Control(pid=12345)

        # Deferred search (lazy)
        btn = Control(searchFromControl=window, role=Role.Button, title="Save")
        btn.Click()  # element is found here
    Nc                .   ||| _         d| _        nE|t        |      | _         d| _        n+|||t               | _         d| _        nd| _         d| _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        y)a&  
        Create a Control from an AXUIElement, application PID, or search parameters.

        Args:
            element: An AXUIElementRef to wrap directly.
            pid: Process ID to create an application element from.
            searchFromControl: Parent Control to search from (enables lazy resolution).
            role: AXRole to match when searching.
            title: AXTitle substring to match when searching.
            subrole: AXSubrole to match when searching.
            identifier: AXIdentifier to match when searching.
            predicate: Custom filter function for searching.
            searchDepth: Maximum tree depth for search.
            searchInterval: Seconds between search retries.
            foundIndex: 1-based index for multiple matches (1 = first match).
        NTF)_element_element_direct_assignr	   r
   _searchFromControl_searchRole_searchTitle_searchSubrole_searchIdentifier_searchPredicate_searchDepth_searchInterval_foundIndex)selfelementpidsearchFromControlroletitlesubrole
identifier	predicatesearchDepthsearchInterval
foundIndexs               f/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/macos_mcp/ax/controls.py__init__zControl.__init__V   s    < #DM*.D'_8=DM*.D'&4<EM79DM*.D' DM*/D' #4!%!+ )'-%    c                R    | j                   | j                          | j                   S )zw
        Get the underlying AXUIElementRef.
        Triggers lazy search if element was not directly assigned.
        )r0   Refindr;   s    rG   ElementzControl.Element   s!     == KKM}}rI   c                   | j                   | j                  ry| j                  | j                   duS | j                  j                   | j                  j                  ||      syt	        j
                         }	 | j                         }||| _         y||z   t	        j
                         z
  }|dkD  r t	        j                  t        ||             ny[)a&  
        Check if this control exists by searching for it.
        Retries up to maxSearchSeconds.

        Args:
            maxSearchSeconds: Maximum time to search.
            searchIntervalSeconds: Time between retries.

        Returns:
            True if the control was found.
        NTFr   )	r0   r1   r2   Existstime	monotonic_search_for_elementsleepmin)r;   maxSearchSecondssearchIntervalSeconds
start_timefound	remainings         rG   rO   zControl.Exists   s     ==$)D)D""*==,, ""++3**11 "7 ^^%
,,.E  %"%558HHI1}

3y*?@A rI   c                    d| _         | j                  || j                        s$|r!| j                         }t	        d| d|       yy)z
        Re-find this control, clearing any cached element.

        Args:
            maxSearchSeconds: Maximum time to search.
            raiseException: If True, raise LookupError on timeout.

        Returns:
            True if found.
        NzFind Control Timeout(zs): FT)r0   rO   r9   _get_search_descriptionLookupError)r;   rU   raiseExceptiondescs       rG   rK   zControl.Refind   sS     {{+T-A-AB335!$9:J9K4PTv"VWWrI   c                D   | j                   }|y|j                  }|yg }t        ||| j                  | j                  | j
                  | j                  | j                  | j                  d| j                  dk  
       | j                  dz
  }|t        |      k  r||   S y)z?Perform a single search attempt using stored search parameters.Nr   r   
find_first)r2   rM   _find_recursive_rawr3   r5   r4   r6   r7   r8   r:   len)r;   parentparent_elementresultsidxs        rG   rR   zControl._search_for_element   s    ((>!""!!((A-	
 "W3<rI   c                   g }| j                   r|j                  d| j                          | j                  r|j                  d| j                         | j                  r|j                  d| j                         | j                  r|j                  d| j                         | j
                  r|j                  d       |rddj                  |      z   dz   S d	S )
z:Get a human-readable description of the search parameters.zRole=zTitle=zSubrole=zIdentifier=zPredicate=<custom>{z, }z{})r3   appendr4   r5   r6   r7   join)r;   partss     rG   r[   zControl._get_search_description   s    LL5!1!1 456LL6$"3"3!678LL8D$7$7#:;<!!LL;t'='=&@AB  LL-./4sTYYu%%+>$>rI   c                    t        |       S )zDWrap a raw AXUIElementRef in the appropriate typed Control subclass.)CreateControlr<   s    rG   _wrapzControl._wrap  s     W%%rI   c                R    t        | j                  t        j                        xs dS )z?Get the role of this element (e.g., 'AXButton', 'AXTextField'). )r   rM   r   r   rL   s    rG   r   zControl.Role       DLL)..9?R?rI   c                R    t        | j                  t        j                        xs dS )z8Get the subrole of this element (e.g., 'AXCloseButton').rs   )r   rM   r   r   rL   s    rG   r   zControl.Subrole  s      DLL)*;*;<BBrI   c                R    t        | j                  t        j                        xs dS )zBGet the localized role description (e.g., 'button', 'text field').rs   )r   rM   r   RoleDescriptionrL   s    rG   rw   zControl.RoleDescription        DLL)*C*CDJJrI   c                R    t        | j                  t        j                        xs dS )z$Get the title/label of this element.rs   )r   rM   r   TitlerL   s    rG   rz   zControl.Title  s     DLL)//:@b@rI   c                >    | j                   xs | j                  xs dS )zj
        Get the display name of this element.
        Tries Title, then Description, then Value.
        rs   )rz   DescriptionrL   s    rG   NamezControl.Name  s     zz3T--33rI   c                v    | j                   xs, | j                  xs | j                  xs | j                  xs dS )z@Get the human-readable label for this element (RoleDescription).rs   )rz   
Identifierr|   ValuerL   s    rG   LabelzControl.Label'  s1     zzTT__T0@0@TDJJTRTTrI   c                R    t        | j                  t        j                        xs dS )z2Get the accessibility description of this element.rs   )r   rM   r   r|   rL   s    rG   r|   zControl.Description,  s      DLL)*?*?@FBFrI   c                R    t        | j                  t        j                        xs dS )z"Get the help text of this element.rs   )r   rM   r   HelprL   s    rG   r   zControl.Help1  rt   rI   c                J    t        | j                  t        j                        S )z7Get the value of this element (type varies by element).)r   rM   r   r   rL   s    rG   r   zControl.Value6  s     DLL)//::rI   c                N    t        | j                  t        j                  |       y)zSet the value of this element.Nr   rM   r   r   r;   values     rG   r   zControl.Value;       	T\\9??E:rI   c                8    | j                   }|t        |      S dS )zGet the value as a string.rs   )r   strr;   vals     rG   ValueStringzControl.ValueString@  s      jj?s3x22rI   c                R    t        | j                  t        j                        xs dS )z<Get the unique identifier (similar to Windows AutomationId).rs   )r   rM   r   r   rL   s    rG   r   zControl.IdentifierF  s      DLL)*>*>?E2ErI   c                R    t        | j                  t        j                        }|duS )z!Check if this element is enabled.F)r   rM   r   Enabledr   s     rG   	IsEnabledzControl.IsEnabledK  s%     4<<):):;%rI   c                R    t        | j                  t        j                        }|du S )z)Check if this element has keyboard focus.T)r   rM   r   Focusedr   s     rG   	IsFocusedzControl.IsFocusedQ  s$     4<<):):;d{rI   c                N    t        | j                  t        j                  |       y)zSet focus on this element.Nr   rM   r   r   r   s     rG   r   zControl.IsFocusedW  s     	T\\9#4#4e<rI   c                R    t        | j                  t        j                        }|du S )z Check if this element is hidden.T)r   rM   r   Hiddenr   s     rG   IsHiddenzControl.IsHidden\  s$     4<<)9)9:d{rI   c                R    t        | j                  t        j                        }|du S )z"Check if this element is selected.T)r   rM   r   Selectedr   s     rG   
IsSelectedzControl.IsSelectedb  $     4<<););<d{rI   c                X    t        | j                        }|rt        |d   |d         S y)z7Get the position of this element in screen coordinates.r   r   xyN)r   rM   r   )r;   poss     rG   PositionzControl.Positionl  s-     $,,'3q6SV,,rI   c                X    t        | j                        }|rt        |d   |d         S y)zGet the size of this element.r   r   )widthheightN)r   rM   r   )r;   sizes     rG   ElementSizezControl.ElementSizet  s-     t||$d1gd1g66rI   c                ,    t        | j                        S )z{
        Get the bounding rectangle of this element.
        Equivalent to Windows UIA BoundingRectangle property.
        )r   rM   rL   s    rG   BoundingRectanglezControl.BoundingRectangle|  s     t||$$rI   c                X    | j                   }|r|j                  \  }}t        ||      S y)z%Get the center point of this element.r   N)r   centerr   )r;   rectcxcys       rG   CenterzControl.Center  s/     %%[[FB2$$rI   c                R    t        | j                  t        j                        }|du S )z(Check if this window is the main window.T)r   rM   r   Mainr   s     rG   IsMainzControl.IsMain  s"     4<<8d{rI   c                R    t        | j                  t        j                        }|du S )z"Check if this window is minimized.T)r   rM   r   	Minimizedr   s     rG   IsMinimizedzControl.IsMinimized  s$     4<<)<)<=d{rI   c                    t        | j                  t        j                        }|du ry| j                  t        j
                  k(  S )z+Check if this window is in fullscreen mode.T)r   rM   r   
FullScreenr   FullScreenWindowr   s     rG   IsFullScreenzControl.IsFullScreen  s9     4<<)=)=>$;||w7777rI   c                R    t        | j                  t        j                        }|du S )zCheck if this window is modal.T)r   rM   r   Modalr   s     rG   IsModalzControl.IsModal  s"     4<<9d{rI   c                f    t        | j                  t        j                        }|rt	        |      S y)zGet the parent element.N)r   rM   r   Parentro   )r;   rd   s     rG   r   zControl.Parent  +     dllI,<,<= ((rI   c                f    t        | j                  t        j                        }|rt	        |      S y)z"Get the containing window element.N)r   rM   r   Windowro   r;   windows     rG   r   zControl.Window  r   rI   c                f    t        | j                  t        j                        }|rt	        |      S y)zOGet the top-level UI element (typically a WindowControl or ApplicationControl).N)r   rM   r   TopLevelUIElementro   )r;   tops     rG   r   zControl.TopLevelUIElement  s+     4<<)D)DE %%rI   c                ,    t        | j                        S )z!Get the number of child elements.)r   rM   rL   s    rG   
ChildCountzControl.ChildCount       T\\**rI   c                h    t        | j                        }|D cg c]  }t        |       c}S c c}w )zZ
        Get all child controls.
        Equivalent to Windows UIA GetChildren().
        _GetChildrenrM   ro   )r;   childrenchilds      rG   r   zControl.GetChildren  s/    
  -2:;(e$(;;;s   /c                N    t        | j                        }|rt        |d         S y)zGet the first child control.r   Nr   r;   r   s     rG   GetFirstChildControlzControl.GetFirstChildControl  s%    - !--rI   c                N    t        | j                        }|rt        |d         S y)zGet the last child control.Nr   r   s     rG   GetLastChildControlzControl.GetLastChildControl  s%    - "..rI   c                f    t        | j                  t        j                        }|rt	        |      S yz3Get the focused window of this application element.Nr   rM   r   FocusedWindowro   r   s     rG   r   zControl.FocusedWindow  +     dllI,C,CD ((rI   c                f    t        | j                  t        j                        }|rt	        |      S yz0Get the main window of this application element.Nr   rM   r   
MainWindowro   r   s     rG   r   zControl.MainWindow  +     dllI,@,@A ((rI   c                    t        | j                  t        j                        }|r|D cg c]  }t	        |       c}S g S c c}w z,Get all windows of this application element.r   rM   r   Windowsro   r;   windowsws      rG   r   zControl.Windows  A     t||Y->->?.56gM!$g66	 7   Ac                f    t        | j                  t        j                        }|rt	        |      S y)z-Get the menu bar of this application element.N)r   rM   r   MenuBarro   )r;   menu_bars     rG   r   zControl.MenuBar  s+      i.?.?@ **rI   c                f    t        | j                  t        j                        }|rt	        |      S y)zGGet the extras menu bar (status bar items) of this application element.N)r   rM   r   ExtrasMenuBarro   )r;   extrass     rG   r   zControl.ExtrasMenuBar  r   rI   c                f    t        | j                  t        j                        }|rt	        |      S y)zGet the horizontal scroll bar.N)r   rM   r   HorizontalScrollBarro   r;   sbs     rG   r   zControl.HorizontalScrollBar  s+     $,,	(E(EF $$rI   c                f    t        | j                  t        j                        }|rt	        |      S y)zGet the vertical scroll bar.N)r   rM   r   VerticalScrollBarro   r   s     rG   r   zControl.VerticalScrollBar  s+     $,,	(C(CD $$rI   c                    | j                   duS )z-Check if the element can scroll horizontally.N)r   rL   s    rG   IsHorizontallyScrollablez Control.IsHorizontallyScrollable'  s     ''t33rI   c                    | j                   duS )z+Check if the element can scroll vertically.N)r   rL   s    rG   IsVerticallyScrollablezControl.IsVerticallyScrollable,  s     %%T11rI   c                    t        | j                  t        j                        }|r|D cg c]  }t	        |       c}S g S c c}w )z#Get all rows (for tables/outlines).)r   rM   r   Rowsro   r;   rowsrs      rG   r   zControl.Rows5  s?     DLL)..9.23dM!$d33	 4r   c                    t        | j                  t        j                        }|r|D cg c]  }t	        |       c}S g S c c}w )zGet visible rows.)r   rM   r   VisibleRowsro   r   s      rG   r  zControl.VisibleRows=  sA     DLL)*?*?@.23dM!$d33	 4r   c                    t        | j                  t        j                        }|r|D cg c]  }t	        |       c}S g S c c}w )zGet all columns.)r   rM   r   Columnsro   )r;   colscs      rG   r  zControl.ColumnsE  sA     DLL)*;*;<.23dM!$d33	 4r   c                    t        | j                  t        j                        }|r|D cg c]  }t	        |       c}S g S c c}w )zGet selected rows.)r   rM   r   SelectedRowsro   r   s      rG   r  zControl.SelectedRowsM  sA     DLL)*@*@A.23dM!$d33	 4r   c                R    t        | j                  t        j                        }|du S )z"Check if this element is expanded.Tr   rM   r   Expandedr   s     rG   
IsExpandedzControl.IsExpandedY  r   rI   c                V    t        | j                  t        j                        }||S dS )z/Get the number of characters in a text element.r   )r   rM   r   NumberOfCharactersr   s     rG   r  zControl.NumberOfCharactersc  s)     4<<)E)EFos,1,rI   c                R    t        | j                  t        j                        xs dS )zGet the selected text.rs   )r   rM   r   SelectedTextrL   s    rG   r  zControl.SelectedTexti  s      DLL)*@*@AGRGrI   c                J    t        | j                  t        j                        S )zGet the selected text range.)r   rM   r   SelectedTextRangerL   s    rG   r  zControl.SelectedTextRangen  s     DLL)*E*EFFrI   c                J    t        | j                  t        j                        S )z Get the visible character range.)r   rM   r   VisibleCharacterRangerL   s    rG   r  zControl.VisibleCharacterRanges  s     DLL)*I*IJJrI   c                J    t        | j                  t        j                        S )zGet the start text marker.)r   rM   r   StartTextMarkerrL   s    rG   r  zControl.StartTextMarkerx  s     DLL)*C*CDDrI   c                J    t        | j                  t        j                        S )zGet the end text marker.)r   rM   r   EndTextMarkerrL   s    rG   r  zControl.EndTextMarker}  s     DLL)*A*ABBrI   c                J    t        | j                  t        j                        S )z#Get the selected text marker range.)r   rM   r   SelectedTextMarkerRangerL   s    rG   r  zControl.SelectedTextMarkerRange  s     DLL)*K*KLLrI   c                R    t        | j                  t        j                        xs dS )z Get the language of the element.rs   )r   rM   r   LanguagerL   s    rG   r  zControl.Language  s      DLL)*<*<=CCrI   c                R    t        | j                  t        j                        xs dS )z'Get placeholder text (for text fields).rs   )r   rM   r   PlaceholderValuerL   s    rG   r  zControl.PlaceholderValue  s      DLL)*D*DEKKrI   c                   |xs | j                   }|xs | j                  }|r|syt        | j                  t        j
                  ||g      }|syt        | j                  t        j                  |      }|t        |      S dS )z
        Get the text between two text markers.
        If markers are not provided, uses the element's Start and End markers.
        rs   )r  r  r   rM   r   &TextMarkerRangeForUnorderedTextMarkersStringForTextMarkerRanger   )r;   start_marker
end_markerstartendmarker_rangetexts          rG   GetTextFromMarkerszControl.GetTextFromMarkers  s     4 4 4.D..C 1LL)JJUTWL
  )LL)<<l
 !,s4y4"4rI   c                h    t        | j                  t        j                        }|rt	        |      S dS )z)Get the URL (for links and web elements).rs   r   rM   r   URLr   r   s     rG   r*  zControl.URL  )     4<<7s3x&B&rI   c                h    t        | j                  t        j                        }|rt	        |      S dS )zGet the document path/URL.rs   r   rM   r   Documentr   r   s     rG   r.  zControl.Document  +     4<<););<s3x&B&rI   c                4    t        | j                        xs g S )z2Get all attribute names supported by this element.)r   rM   rL   s    rG   AttributeNameszControl.AttributeNames  s     !.4"4rI   c                4    t        | j                        xs g S )z/Get all action names supported by this element.)r   rM   rL   s    rG   ActionNameszControl.ActionNames  s     dll+1r1rI   c                .    t        | j                  |      S )z'Get a specific attribute value by name.)r   rM   r;   	attributes     rG   GetAttributeValuezControl.GetAttributeValue  s    DLL)44rI   c                0    t        | j                  ||      S )z'Set a specific attribute value by name.)r   rM   )r;   r6  r   s      rG   SetAttributeValuezControl.SetAttributeValue  s    DLL)U;;rI   c                .    t        | j                  |      S )z!Check if an attribute can be set.)r   rM   r5  s     rG   r   zControl.IsAttributeSettable  s    "4<<;;rI   c                .    t        | j                  |      S )zX
        Perform an action on this element.
        Returns True if successful.
        )r   rM   r;   actions     rG   r   zControl.PerformAction  s    
 T\\622rI   c                @    | j                  t        j                        S )z(Perform AXPress action (click/activate).)r   r   PressrL   s    rG   r?  zControl.Press      !!&,,//rI   c                @    | j                  t        j                        S )zPerform AXConfirm action.)r   r   ConfirmrL   s    rG   rB  zControl.Confirm  s    !!&..11rI   c                @    | j                  t        j                        S )zPerform AXCancel action.)r   r   CancelrL   s    rG   rD  zControl.Cancel  s    !!&--00rI   c                @    | j                  t        j                        S )zPerform AXIncrement action.)r   r   	IncrementrL   s    rG   rF  zControl.Increment      !!&"2"233rI   c                @    | j                  t        j                        S )zPerform AXDecrement action.)r   r   	DecrementrL   s    rG   rI  zControl.Decrement  rG  rI   c                @    | j                  t        j                        S )z-Perform AXShowMenu action (right-click menu).)r   r   ShowMenurL   s    rG   rK  zControl.ShowMenu  s    !!&//22rI   c                @    | j                  t        j                        S )zPerform AXPick action.)r   r   PickrL   s    rG   rM  zControl.Pick  s    !!&++..rI   c                @    | j                  t        j                        S )z(Perform AXRaise action (bring to front).)r   r   RaiserL   s    rG   rO  zControl.Raise  r@  rI   c                L    t        | j                  t        j                  d      S )zSet focus to this element.Tr   rL   s    rG   SetFocuszControl.SetFocus   s    DLL)*;*;TBBrI   c                    g }t        | j                  |||||||dd
       |D cg c]  }t        |       c}S c c}w )a  
        Find all descendant controls matching the given criteria.
        Equivalent to Windows UIA FindAll().

        Args:
            role: Filter by AXRole.
            subrole: Filter by AXSubrole.
            title: Filter by AXTitle (substring match).
            identifier: Filter by AXIdentifier.
            predicate: Custom filter function.
            max_depth: Maximum search depth.

        Returns:
            List of matching typed Control objects.
        r   Fr`   rb   rM   ro   )	r;   r?   rA   r@   rB   rC   	max_depthraw_resultselems	            rG   FindAllzControl.FindAll  sR    0 LL	
 1<<d#<<<s   ;c                h    g }t        | j                  |||||||dd
       |rt        |d         S dS )z
        Find the first descendant control matching the given criteria.
        Equivalent to Windows UIA FindFirst().
        r   Tr`   NrS  )r;   r?   rA   r@   rB   rC   rT  rU  s           rG   	FindFirstzControl.FindFirst/  sK     LL	
 1<}[^,EErI   c                    || j                   v S )z1Check if this element supports a specific action.)r3  r<  s     rG   	HasActionzControl.HasActionK  s    ))))rI   c                T    | j                  ||      }|rt        |d   |d   |       yy)a  
        Click this control at the given ratio position.

        Args:
            ratioX: Horizontal position ratio (0.0=left, 0.5=center, 1.0=right).
            ratioY: Vertical position ratio (0.0=top, 0.5=center, 1.0=bottom).
            waitTime: Delay after clicking.
        r   r   N)_get_click_point_Clickr;   ratioXratioYwaitTimepoints        rG   r$   zControl.ClickS  s2     %%ff558U1Xx0 rI   c                T    | j                  ||      }|rt        |d   |d   |       yy)zRight-click this control.r   r   N)r]  _RightClickr_  s        rG   r%   zControl.RightClickb  s2     %%ff5a%(H5 rI   c                T    | j                  ||      }|rt        |d   |d   |       yy)zDouble-click this control.r   r   N)r]  _DoubleClickr_  s        rG   r&   zControl.DoubleClickj  2     %%ff5q58X6 rI   c                T    | j                  ||      }|rt        |d   |d   |       yy)zMiddle-click this control.r   r   N)r]  _MiddleClickr_  s        rG   r'   zControl.MiddleClickr  rh  rI   c                :    | j                          t        |       y)zScroll down on this control.N)MoveCursorToCenter
_WheelDownr;   clickss     rG   r)   zControl.WheelDownz  s    !6rI   c                :    | j                          t        |       y)zScroll up on this control.N)rl  _WheelUprn  s     rG   r*   zControl.WheelUp  s    !rI   c                   | j                   }|syt        |t              r(|j                   }|sy|j                  |j                  }}nYt        |t
              r|j                  |j                  }}n0t        |t        t        f      rt        |      dk\  r|d   |d   }}nyt        |j                  |j                  ||||       y)a  
        Drag from this control's center to a target.

        Args:
            target: A Control (uses its center), a Point, or (x, y) tuple.
            duration: Duration of the drag in seconds.
            steps: Number of intermediate mouse move steps.
        N   r   r   )
r   
isinstancer.   r   r   r   tuplelistrc   _DragTo)r;   targetdurationstepsr#  r$  end_xend_ys           rG   r+   zControl.DragTo  s     fg&--C55#%%5E&!88VXX5E.3v;!3C!!9fQi5E%%@rI   c                b    | j                   }|r!t        |j                  |j                         yy)z4Move the mouse cursor to the center of this control.N)r   _MoveTor   r   )r;   r   s     rG   rl  zControl.MoveCursorToCenter  s%    FHHfhh' rI   c                    | j                   }|r<|j                  |j                  |z  z   }|j                  |j                  |z  z   }||fS y)zECalculate click coordinates from ratio position within bounding rect.N)r   leftr   r   r   )r;   r`  ra  r   r   r   s         rG   r]  zControl._get_click_point  sL     %%		DJJ//A4;;//Aq6MrI   c                <    | j                          t        ||       y)z
        Focus this control and type text into it.

        Args:
            text: The text to type.
            interval: Delay between keystrokes in seconds.
        N)rQ  	_TypeText)r;   r&  intervals      rG   SendKeyszControl.SendKeys  s     	$!rI   c                J    | j                  t        j                  ||||      S )z+Find the first AXApplication child control.r?   r@   rB   rC   rT  )rY  r   Applicationr;   r@   rB   rC   rT  s        rG   ApplicationControlzControl.ApplicationControl  /     ~~!!!  
 	
rI   c                J    | j                  t        j                  ||||      S )z&Find the first AXWindow child control.r  )rY  r   r   r  s        rG   WindowControlzControl.WindowControl  -     ~~!  
 	
rI   c                J    | j                  t        j                  ||||      S )z&Find the first AXButton child control.r  )rY  r   Buttonr  s        rG   ButtonControlzControl.ButtonControl  r  rI   c                J    | j                  t        j                  ||||      S )z(Find the first AXCheckBox child control.r  )rY  r   CheckBoxr  s        rG   CheckBoxControlzControl.CheckBoxControl  -     ~~!  
 	
rI   c                J    | j                  t        j                  ||||      S )z+Find the first AXRadioButton child control.r  )rY  r   RadioButtonr  s        rG   RadioButtonControlzControl.RadioButtonControl  r  rI   c                J    | j                  t        j                  ||||      S )z)Find the first AXTextField child control.r  )rY  r   	TextFieldr  s        rG   TextFieldControlzControl.TextFieldControl  s-     ~~!  
 	
rI   c                J    | j                  t        j                  ||||      S )z(Find the first AXTextArea child control.r  )rY  r   TextArear  s        rG   TextAreaControlzControl.TextAreaControl  r  rI   c                J    | j                  t        j                  ||||      S )z(Find the first AXComboBox child control.r  )rY  r   ComboBoxr  s        rG   ComboBoxControlzControl.ComboBoxControl  r  rI   c                J    | j                  t        j                  ||||      S )z+Find the first AXPopUpButton child control.r  )rY  r   PopUpButtonr  s        rG   PopUpButtonControlzControl.PopUpButtonControl(  r  rI   c                J    | j                  t        j                  ||||      S )z&Find the first AXSlider child control.r  )rY  r   Sliderr  s        rG   SliderControlzControl.SliderControl4  r  rI   c                J    | j                  t        j                  ||||      S )z(Find the first AXMenuItem child control.r  )rY  r   MenuItemr  s        rG   MenuItemControlzControl.MenuItemControl@  r  rI   c                J    | j                  t        j                  ||||      S )z+Find the first AXMenuBarItem child control.r  )rY  r   MenuBarItemr  s        rG   MenuBarItemControlzControl.MenuBarItemControlL  r  rI   c                J    | j                  t        j                  ||||      S )zCFind the first AXTab child control (use AXTabGroup for tab groups).r  )rY  r   Tabr  s        rG   
TabControlzControl.TabControlX  -     ~~!  
 	
rI   c                J    | j                  t        j                  ||||      S )z$Find the first AXList child control.r  )rY  r   r   r  s        rG   ListControlzControl.ListControld  -     ~~!  
 	
rI   c                J    | j                  t        j                  ||||      S )z%Find the first AXTable child control.r  )rY  r   Tabler  s        rG   TableControlzControl.TableControlp  -     ~~!  
 	
rI   c                J    | j                  t        j                  ||||      S )z'Find the first AXOutline child control.r  )rY  r   Outliner  s        rG   OutlineControlzControl.OutlineControl|  -     ~~!  
 	
rI   c                J    | j                  t        j                  ||||      S )z*Find the first AXScrollArea child control.r  )rY  r   
ScrollArear  s        rG   ScrollAreaControlzControl.ScrollAreaControl  -     ~~!  
 	
rI   c                J    | j                  t        j                  ||||      S )z%Find the first AXGroup child control.r  )rY  r   Groupr  s        rG   GroupControlzControl.GroupControl  r  rI   c                J    | j                  t        j                  ||||      S )z%Find the first AXImage child control.r  )rY  r   Imager  s        rG   ImageControlzControl.ImageControl  r  rI   c                J    | j                  t        j                  ||||      S )z$Find the first AXLink child control.r  )rY  r   Linkr  s        rG   LinkControlzControl.LinkControl  r  rI   c                J    | j                  t        j                  ||||      S )z*Find the first AXStaticText child control.r  )rY  r   
StaticTextr  s        rG   StaticTextControlzControl.StaticTextControl  r  rI   c                J    | j                  t        j                  ||||      S )z'Find the first AXWebArea child control.r  )rY  r   WebArear  s        rG   WebAreaControlzControl.WebAreaControl  r  rI   c                J    | j                  t        j                  ||||      S )z2Find the first AXDisclosureTriangle child control.r  )rY  r   DisclosureTriangler  s        rG   DisclosureTriangleControlz!Control.DisclosureTriangleControl  s/     ~~((!  
 	
rI   c                J    | j                  t        j                  ||||      S )z#Find the first AXRow child control.r  )rY  r   Rowr  s        rG   
RowControlzControl.RowControl  r  rI   c                J    | j                  t        j                  ||||      S )z$Find the first AXCell child control.r  )rY  r   Cellr  s        rG   CellControlzControl.CellControl  r  rI   c                J    | j                  t        j                  ||||      S )z(Find the first AXDockItem child control.r  )rY  r   DockItemr  s        rG   DockItemControlzControl.DockItemControl  r  rI   c                J    | j                  t        j                  ||||      S )z1Find the first AXProgressIndicator child control.r  )rY  r   ProgressIndicatorr  s        rG   ProgressIndicatorControlz Control.ProgressIndicatorControl   s/     ~~''!  
 	
rI   c                b    | j                   }| j                  }| j                  }d| d|d| dS )NzControl(Role=z, Name=z, Rect=))r   r   r   )r;   r?   namer   s       rG   __str__zControl.__str__  s:    yyzz%%tfGD874&BBrI   c                j    d| j                   j                   d| j                  d| j                  dS )N<z Role=z Name=>)	__class____name__r   r   rL   s    rG   __repr__zControl.__repr__  s1    4>>**+6$))fTZZNRSTTrI   c                `    t        |t              r| j                  |j                  k(  S t        S N)rt  r.   r0   NotImplemented)r;   others     rG   __eq__zControl.__eq__  s%    eW%==ENN22rI   c                >    t        t        | j                              S r  )hashidr0   rL   s    rG   __hash__zControl.__hash__  s    Bt}}%&&rI   )NNNNNNNN         ?r   )r=   Optional[int]r>   Optional[Control]r?   Optional[str]r@   r  rA   r  rB   r  rC   #Optional[Callable[[Control], bool]]rD   intrE   floatrF   r  )      @r  )rU   r  rV   r  returnbool)r  T)rU   r  r]   r  r  r  r  r   r  r.   )r  Noner  r  r   r  r  r  )r  zOptional[Point])r  zOptional[Size])r  zOptional[Rect]r  r  r  zOptional[WindowControl]r  r  r  List[Control]r  zList[WindowControl])NN)r!  r   r"  r   r  r   )r  z	list[str])r6  r   )r6  r   r  r  )r=  r   r  r  )NNNNNr  )r?   Optional[Role | str]rA   r  r@   r  rB   r  rC   r  rT  r  r  r  )r?   r  rA   r  r@   r  rB   r  rC   r  rT  r  r  r  )r  r  g?)r`  r  ra  r  rb  r  r  r  )   )ro  r  r  r  )r     )rx  zUnion[Control, Point, tuple]ry  r  rz  r  r  r  )r  r  )r`  r  ra  r  r  zOptional[tuple[float, float]])g{Gz?)r&  r   r  r  r  r  )NNNr  )r  z'ApplicationControl')r  z'WindowControl')r  z'ButtonControl')r  z'CheckBoxControl')r  z'RadioButtonControl')r  z'TextFieldControl')r  z'TextAreaControl')r  z'ComboBoxControl')r  z'PopUpButtonControl')r  z'SliderControl')r  z'MenuItemControl')r  z'MenuBarItemControl')r  z'TabControl')r  z'ListControl')r  z'TableControl')r  z'OutlineControl')r  z'ScrollAreaControl')r  z'GroupControl')r  z'ImageControl')r  z'LinkControl')r  z'StaticTextControl')r  z'WebAreaControl')r  z'DisclosureTriangleControl')r  z'RowControl')r  z'CellControl')r  z'DockItemControl')r  z'ProgressIndicatorControl')r  
__module____qualname____doc__rH   propertyrM   rO   rK   rR   r[   staticmethodrq   r   r   rw   rz   r}   r   r|   r   r   setterr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r'  r*  r.  r1  r3  r7  r9  r   r   r?  rB  rD  rF  rI  rK  rM  rO  rQ  rW  rY  r[  r$   r%   r&   r'   r)   r*   r+   rl  r]  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   rI   rG   r.   r.   >   s%
   2 !/3"#!%$(9= #4& 4& -	4&
 4& 4& 4& "4& 74& 4& 4& 4&l   MP% %%DI%	%P EI %=A	*:? & & @ @ C C K K A A 4 4 U U G G @ @ ; ; \\; ; 3 3
 F F    
  
 = =  
       % %    
  
 8 8         + +<               4 4 2 2           - -
 H H G G K K E E C C M M D D L L
 ;?55475	5< ' '
 ' ' 5 5 2 25<<3021443/0C &*!%#$(9=%="%= %= 	%=
 "%= 7%= %= 
%=R &*!%#$(9=F"F F 	F
 "F 7F F 
F8* KO11+01BG1	1  KO66+06BG6	6 KO77+07BG7	7 KO77+07BG7	7
 	A,A A 	A
 
A@( 47		+0		&		"  FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	

 FH

	$

 FH

	

 FH

	

 FH

	

 FH

	#

 CU
'rI   r.   c                  4    e Zd ZdZ fdZd Zd$dZd$dZed$d       Z	ed%d       Z
ed%d       Zed$d	       Zed&d
       Zed'd       Zed'd       Zed(d       Zed%d       Zed%d       Zej&                  d)d       Zed*d       Zed+d       Zed+d       Zed+d       Zed+d       Zed        Zed        Zed%d       Zed%d       Zed%d       Zed%d       Zed+d       Zed*d       Z ed%d       Z!d,d-dZ"d%d Z#d%d!Z$d%d"Z%d%d#Z& xZ'S ).r  a8  
    Control for AXApplication elements.

    Wraps both the AXUIElementRef (for accessibility tree access) and
    the NSRunningApplication (for process-level metadata like bundle ID,
    icon, launch date, hidden state, etc.).

    The NSRunningApplication is lazily resolved from the PID on first access.
    c                2    t        |   di | d | _        y )Nr  )superrH   _ns_running_app)r;   kwargsr  s     rG   rH   zApplicationControl.__init__2  s    "6"#rI   c                    | j                   gt        | j                        }|Pddlm} |j                         j                         D ])  }|j                         |k(  s|| _          | j                   S  | j                   S )zCLazily resolve the NSRunningApplication for this application's PID.r   )NSWorkspace)r  r    rM   Cocoar  sharedWorkspacerunningApplicationsprocessIdentifier)r;   r=   r  apps       rG   _get_ns_running_appz&ApplicationControl._get_ns_running_app6  sw    '-C-&668LLNC,,.#5/2,###	 O ###rI   c                V    d| j                   d| j                  d| j                  dS )Nz	App(Name=z	, Status=z	, Policy=r  )r}   StatusActivationPolicyrL   s    rG   r  zApplicationControl.__str__C  s4    		}Idkk_ =++.a1	
rI   c                "    | j                         S r  )r  rL   s    rG   r  zApplicationControl.__repr__I  s    ||~rI   c                :    | j                   }|r|S | j                  S )zR
        Get the display name of this application.
        Tries AX Title
        )rz   LocalizedName)r;   r  s     rG   r}   zApplicationControl.NameP  s      zzt3!3!33rI   c                D    | j                   }|syt        d |D              S )a  
        Check if this application's windows are all minimized.
        Returns True only when the application has at least one window
        and every window is minimized.  Returns False if there are no
        windows or any window is not minimized.
        Fc              3  4   K   | ]  }|j                     y wr  r   .0r   s     rG   	<genexpr>z1ApplicationControl.IsMinimized.<locals>.<genexpr>d  s     2'Q1=='   )r   allr;   r   s     rG   r   zApplicationControl.IsMinimizedY  s$     ,,2'222rI   c                D    | j                   }|syt        d |D              S )z
        Check if any of this application's windows are in fullscreen mode.
        Returns True if at least one window is fullscreen.
        Returns False if there are no windows or none are fullscreen.
        Fc              3  4   K   | ]  }|j                     y wr  r   r'  s     rG   r)  z2ApplicationControl.IsFullScreen.<locals>.<genexpr>p       37a1>>7r*  )r   anyr,  s     rG   r   zApplicationControl.IsFullScreenf  s$     ,,37333rI   c                    | j                   ry| j                  }|syt        d |D              ry| j                  rt	        d |D              ryyy)	u>  
        Get a human-readable status summarizing the application's current state.

        Returns one of:
            'Active'     — Frontmost application with visible windows.
            'Fullscreen' — Frontmost application in fullscreen mode.
            'Visible'    — Has windows on screen but is not the frontmost app.
            'Hidden'     — Hidden via Cmd+H; windows are preserved but invisible.
            'Minimized'  — All windows are minimized to the Dock.
            'Windowless' — Running but has no windows (closed or never opened).
        r   
Windowlessc              3  4   K   | ]  }|j                     y wr  r&  r'  s     rG   r)  z,ApplicationControl.Status.<locals>.<genexpr>  s     .gq}}gr*  r   c              3  4   K   | ]  }|j                     y wr  r/  r'  s     rG   r)  z,ApplicationControl.Status.<locals>.<genexpr>  r0  r*  
FullscreenActiveVisible)r   r   r+  IsActiver1  r,  s     rG   r  zApplicationControl.Statusr  sL     ==,,.g..==3733#rI   c                f    t        | j                  t        j                        }|rt	        |      S y)z9Get the currently focused UI element in this application.N)r   rM   r   FocusedUIElementro   )r;   rV  s     rG   r;  z#ApplicationControl.FocusedUIElement  s+     DLL)*D*DE &&rI   c                f    t        | j                  t        j                        }|rt	        |      S yr   r   r   s     rG   r   z ApplicationControl.FocusedWindow  r   rI   c                f    t        | j                  t        j                        }|rt	        |      S yr   r   r   s     rG   r   zApplicationControl.MainWindow  r   rI   c                    t        | j                  t        j                        }|r|D cg c]  }t	        |       c}S g S c c}w r   r   r   s      rG   r   zApplicationControl.Windows  r   r   c                R    t        | j                  t        j                        }|du S )z3Check if the application is running (AX attribute).T)r   rM   r   IsApplicationRunningr   s     rG   r@  z'ApplicationControl.IsApplicationRunning  s$     4<<)G)GHd{rI   c                R    t        | j                  t        j                        }|du S )z%Get the enhanced user interface flag.T)r   rM   r   Enhancedr   s     rG   EnhancedUserInterfacez(ApplicationControl.EnhancedUserInterface  r   rI   c                N    t        | j                  t        j                  |       y)zOSet the enhanced user interface flag (enables deeper tree access in some apps).N)r   rM   r   rB  r   s     rG   rC  z(ApplicationControl.EnhancedUserInterface  s     	T\\9#5#5u=rI   c                ,    t        | j                        S )z5Get the process identifier (PID) of this application.)r    rM   rL   s    rG   PIDzApplicationControl.PID  r   rI   c                f    | j                         }|r|j                         }|rt        |      S dS y)z{
        Get the CFBundleIdentifier of this application.
        Example: 'com.apple.Safari', 'com.google.Chrome'.
        N)r  bundleIdentifierr   r;   r  r   s      rG   BundleIdentifierz#ApplicationControl.BundleIdentifier  s7     &&(&&(C"3s8,,rI   c                f    | j                         }|r|j                         }|rt        |      S dS y)zy
        Get the file URL to the application's .app bundle.
        Example: 'file:///Applications/Safari.app/'.
        N)r  	bundleURLr   r;   r  urls      rG   	BundleURLzApplicationControl.BundleURL  s4     &&(--/C"3s8,,rI   c                f    | j                         }|r|j                         }|rt        |      S dS y)z
        Get the file URL to the application's executable binary.
        Example: 'file:///Applications/Safari.app/Contents/MacOS/Safari'.
        N)r  executableURLr   rM  s      rG   ExecutableURLz ApplicationControl.ExecutableURL  s7     &&(##%C"3s8,,rI   c                f    | j                         }|r|j                         }|rt        |      S dS y)z
        Get the localized display name of the application.
        Example: 'Safari', 'Google Chrome'.
        This is the user-facing name shown in the Dock and App Switcher.
        N)r  localizedNamer   rI  s      rG   r#  z ApplicationControl.LocalizedName  s7     &&(##%C"3s8,,rI   c                H    | j                         }|r|j                         S y)z
        Get the application icon as an NSImage.
        Can be converted to other formats using Cocoa APIs.

        Returns:
            NSImage or None.
        N)r  iconr;   r  s     rG   IconzApplicationControl.Icon  s$     &&(88:rI   c                H    | j                         }|r|j                         S y)zx
        Get the date and time when the application was launched.

        Returns:
            NSDate or None.
        N)r  
launchDaterW  s     rG   
LaunchDatezApplicationControl.LaunchDate	  s%     &&(>>##rI   c                >    | j                   }|yt               }||k(  S )a  
        Check if this application is the currently active (frontmost) application.

        Uses CGWindowListCopyWindowInfo (via GetForegroundWindowPID) instead of
        NSRunningApplication.isActive() because the latter relies on AppKit
        notifications delivered via NSRunLoop. Without an active event loop
        (e.g. Python scripts, notebooks), isActive() returns stale cached data.
        F)rF  r"   )r;   r=   frontmost_pids      rG   r9  zApplicationControl.IsActive  s(     hh;.0m##rI   c                Z    | j                         }|rt        |j                               S y)z.Check if this application is currently hidden.F)r  r  isHiddenrW  s     rG   r   zApplicationControl.IsHidden&  s)     &&(''rI   c                Z    | j                         }|rt        |j                               S y)z0Check if the application has finished launching.F)r  r  isFinishedLaunchingrW  s     rG   IsFinishedLaunchingz&ApplicationControl.IsFinishedLaunching.  s,     &&(//122rI   c                Z    | j                         }|rt        |j                               S y)z-Check if the application has been terminated.F)r  r  isTerminatedrW  s     rG   IsTerminatedzApplicationControl.IsTerminated6  s,     &&(((*++rI   c                    | j                         }|r3t        |j                               }t        j                  |d| d      S y)u  
        Get the activation policy of the application as a human-readable string.

        Returns:
            'Regular'    — appears in Dock and App Switcher (normal apps),
            'Accessory'  — does not appear in Dock, may show in App Switcher,
            'Prohibited' — does not appear in Dock or App Switcher (background agents),
            None if unavailable.
        zUnknown(r  N)r  r  activationPolicyr   get)r;   r  policys      rG   r   z#ApplicationControl.ActivationPolicy>  sG     &&(--/0F(,,Vxxq5IJJrI   c                Z    | j                         }|rt        |j                               S y)z
        Get the executing processor architecture of the application.

        Common values:
            - 16777223 (0x01000007) = x86_64
            - 16777228 (0x0100000C) = arm64
        N)r  r  executableArchitecturerW  s     rG   ExecutableArchitecturez)ApplicationControl.ExecutableArchitectureO  s,     &&(s11344rI   c                Z    | j                         }|rt        |j                               S y)z6Check if this application currently owns the menu bar.F)r  r  ownsMenuBarrW  s     rG   OwnsMenuBarzApplicationControl.OwnsMenuBar]  s*     &&()**rI   c                t    | j                         }|r&ddlm} |r|nd}t        |j	                  |            S y)z
        Activate (bring to front) this application.

        Args:
            ignoring_other_apps: If True, activates even if another app is active.

        Returns:
            True if activation was successful.
        r   )&NSApplicationActivateIgnoringOtherAppsF)r  r  rq  r  activateWithOptions_)r;   ignoring_other_appsr  rq  optionss        rG   ActivatezApplicationControl.Activatei  sD     &&(D ;N6ST  009::rI   c                Z    | j                         }|rt        |j                               S y)z
        Hide this application (equivalent to Cmd+H).

        Returns:
            True if the application was successfully hidden.
        F)r  r  hiderW  s     rG   HidezApplicationControl.Hide}  s)     &&(
##rI   c                Z    | j                         }|rt        |j                               S y)z
        Unhide (show) this application if it was hidden.

        Returns:
            True if the application was successfully unhidden.
        F)r  r  unhiderW  s     rG   UnhidezApplicationControl.Unhide  s)     &&(

%%rI   c                Z    | j                         }|rt        |j                               S y)z
        Request this application to quit gracefully.
        The application may prompt to save unsaved documents.

        Returns:
            True if the termination request was sent successfully.
        F)r  r  	terminaterW  s     rG   	TerminatezApplicationControl.Terminate  s)     &&(((rI   c                Z    | j                         }|rt        |j                               S y)z
        Force-quit this application immediately.
        Does not give the application a chance to save or clean up.
        Use with caution.

        Returns:
            True if the force termination was successful.
        F)r  r  forceTerminaterW  s     rG   ForceTerminatez!ApplicationControl.ForceTerminate  s,     &&(**,--rI   r  r  r  r  r  r   )r  r  )r  r  )T)rs  r  r  r  )(r  r
  r  r  rH   r  r  r  r  r}   r   r   r  r;  r   r   r   r@  rC  r  rF  rJ  rO  rR  r#  rX  r[  r9  r   rb  re  r   rl  ro  ru  rx  r{  r~  r  __classcell__)r  s   @rG   r  r  '  s/   $$
 4 4 
3 
3 	4 	4  :          
  
 !!> "> + + 	 	 	 	 	 	 
 
   
 
 $ $             (

rI   r  c                      e Zd ZdZddZddZddZddZddZddZ	ddZ
ddd	Zdd
ZddZddZedd       Zedd       Zy)r  zv
    Control for AXWindow elements.
    Provides window management methods similar to Windows UIA TopLevel mixin.
    c                    t        | j                  t        j                        }|rt	        |t
        j                        S y)z'Close this window via the close button.F)r   rM   r   CloseButtonr   r   r?  )r;   	close_btns     rG   ClosezWindowControl.Close  s/     y/D/DE	 FLL99rI   c                L    t        | j                  t        j                  d      S )zMinimize this window.Tr   rM   r   r   rL   s    rG   MinimizezWindowControl.Minimize  s    DLL)*=*=tDDrI   c                L    t        | j                  t        j                  d      S )zRestore this minimized window.Fr  rL   s    rG   
UnminimizezWindowControl.Unminimize  s    DLL)*=*=uEErI   c                "    | j                         S )z4Restore from minimized state (alias for Unminimize).)r  rL   s    rG   RestorezWindowControl.Restore  s      rI   c                    t        | j                  t        j                        }|rt	        |t
        j                        S y)z0Zoom (maximize) this window via the zoom button.F)r   rM   r   
ZoomButtonr   r   r?  )r;   zoom_btns     rG   ZoomzWindowControl.Zoom  s/    i.B.BC 6<<88rI   c                "    | j                         S )z.Maximize (zoom) this window. Alias for Zoom().)r  rL   s    rG   MaximizezWindowControl.Maximize  s    yy{rI   c                f    | j                   }t        | j                  t        j                  |       S )z2Toggle fullscreen mode via AXFullScreen attribute.)r   r   rM   r   r   )r;   currents     rG   r   zWindowControl.FullScreen  s(    ##DLL)*>*>GLLrI   c                    t        | j                        }|rt        |       | j                          t	        j
                  |       y)z
        Bring this window's application to front and raise the window.

        Args:
            waitTime: Delay after activation.
        T)r    rM   r#   rO  rP   rS   )r;   rb  r=   s      rG   	SetActivezWindowControl.SetActive  s5     DLL)$



8rI   c                    | j                   }|syt               \  }}||j                  z
  dz  }||j                  z
  dz  }t	        | j
                  t        j                  ||f      S )z-Move this window to the center of the screen.Frs  )r   r!   r   r   r   rM   r   r   )r;   r   screen_wscreen_hnew_xnew_ys         rG   MoveToCenterzWindowControl.MoveToCenter  sb    %%*_(DJJ&!+DKK'1,DLL)*<*<uenMMrI   c                P    t        | j                  t        j                  ||f      S )z
        Resize this window.

        Args:
            width: New width in points.
            height: New height in points.
        )r   rM   r   r   )r;   r   r   s      rG   ResizezWindowControl.Resize  s     DLL)..5&/JJrI   c                P    t        | j                  t        j                  ||f      S )z
        Move this window to the specified screen position.

        Args:
            x: X coordinate.
            y: Y coordinate.
        )r   rM   r   r   )r;   r   r   s      rG   MoveWindowTozWindowControl.MoveWindowTo  s!     DLL)*<*<q!fEErI   c                f    t        | j                  t        j                        }|rt	        |      S y)z-Get the default button of this window/dialog.N)r   rM   r   DefaultButtonro   r;   btns     rG   r  zWindowControl.DefaultButton  s+     4<<)@)@A %%rI   c                f    t        | j                  t        j                        }|rt	        |      S y)z,Get the cancel button of this window/dialog.N)r   rM   r   CancelButtonro   r  s     rG   r  zWindowControl.CancelButton  s+     4<<)?)?@ %%rI   Nr  )g?)rb  r  r  r  )r   r  r   r  r  r  )r   r  r   r  r  r  r  )r  r
  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  rI   rG   r  r    sl    
EF!M
NKF    rI   r  c                      e Zd ZdZy)r  zControl for AXButton elements.Nr  r
  r  r  r  rI   rG   r  r    s    (rI   r  c                  *    e Zd ZdZedd       ZddZy)r  z Control for AXCheckBox elements.c                0    | j                   }|dk(  xs |du S )z!Check if the checkbox is checked.r   Tr   r   s     rG   	IsCheckedzCheckBoxControl.IsChecked         jjax&3$;&rI   c                "    | j                         S )zToggle the checkbox.r?  rL   s    rG   TogglezCheckBoxControl.Toggle&      zz|rI   Nr  )r  r
  r  r  r  r  r  r  rI   rG   r  r    s    *' '
rI   r  c                  *    e Zd ZdZedd       ZddZy)r  z#Control for AXRadioButton elements.c                0    | j                   }|dk(  xs |du S )z'Check if this radio button is selected.r   Tr  r   s     rG   r   zRadioButtonControl.IsSelected.  r  rI   c                "    | j                         S )zSelect this radio button.r  rL   s    rG   SelectzRadioButtonControl.Select4  r  rI   Nr  )r  r
  r  r  r  r   r  r  rI   rG   r  r  +  s    -' '
rI   r  c                  :    e Zd ZdZddZddZed	d       Zd
dZy)r  z!Control for AXTextField elements.c                L    t        | j                  t        j                  |      S )z!Set the text value of this field.r   r;   r&  s     rG   SetTextzTextFieldControl.SetText<      DLL)//4@@rI   c                    | j                   S )z!Get the text value of this field.)r   rL   s    rG   GetTextzTextFieldControl.GetText@  s    rI   c                V    t        | j                  t        j                        }||S dS )z$Get the insertion point line number.r   )r   rM   r   InsertionPointLineNumberr   s     rG   InsertionPointzTextFieldControl.InsertionPointD  s)     4<<)K)KLos,1,rI   c                $    | j                  d      S )zClear the text in this field.rs   )r  rL   s    rG   	ClearTextzTextFieldControl.ClearTextJ  s    ||BrI   Nr&  r   r  r  r  r  r  )	r  r
  r  r  r  r  r  r  r  r  rI   rG   r  r  9  s)    +A  - -
 rI   r  c                      e Zd ZdZy)r  z2Control for AXTextArea elements (multi-line text).Nr  r  rI   rG   r  r  O  s    <rI   r  c                       e Zd ZdZddZddZy)r  z Control for AXComboBox elements.c                L    t        | j                  t        j                  |      S )zSet the text value.r   r  s     rG   r  zComboBoxControl.SetTextX  r  rI   c                "    | j                         S )zExpand the dropdown.r  rL   s    rG   ExpandzComboBoxControl.Expand\  r  rI   Nr  r  )r  r
  r  r  r  r  r  rI   rG   r  r  U  s    *ArI   r  c                      e Zd ZdZddZy)r  z4Control for AXPopUpButton elements (dropdown menus).c                "    | j                         S )zOpen the pop-up menu.r  rL   s    rG   OpenzPopUpButtonControl.Opend  r  rI   Nr  r  r
  r  r  r  r  rI   rG   r  r  a  s
    >rI   r  c                  l    e Zd ZdZedd       Zej                  dd       Zedd       Zedd       Zy)	r  zControl for AXSlider elements.c                d    | j                   }	 |t        |      S dS # t        t        f$ r Y yw xY w)z Get the slider value as a float.        r   r  	TypeError
ValueErrorr   s     rG   SliderValuezSliderControl.SliderValuel  <     jj	!$5:9c9:& 		     //c                N    t        | j                  t        j                  |       y)zSet the slider value.Nr   r   s     rG   r  zSliderControl.SliderValueu  r   rI   c                h    t        | j                  t        j                        }|t	        |      S dS )zGet the minimum value.r  )r   rM   r   MinValuer  r   s     rG   r  zSliderControl.MinValuez  s-     4<<););< _uSz5#5rI   c                h    t        | j                  t        j                        }|t	        |      S dS )zGet the maximum value.g      Y@)r   rM   r   MaxValuer  r   s     rG   r  zSliderControl.MaxValue  s-     4<<););< _uSz7%7rI   Nr  r  )r   r  r  r  )	r  r
  r  r  r  r  r  r  r  r  rI   rG   r  r  i  sY    (  ; ; 6 6
 8 8rI   r  c                  *    e Zd ZdZedd       ZddZy)r  z Control for AXMenuItem elements.c                R    t        | j                  t        j                        xs dS )z#Get the command character shortcut.rs   )r   rM   r   MenuItemCmdCharrL   s    rG   r  zMenuItemControl.MenuItemCmdChar  rx   rI   c                "    | j                         S )zSelect this menu item.r  rL   s    rG   r  zMenuItemControl.Select  r  rI   Nr  r  )r  r
  r  r  r  r  r  r  rI   rG   r  r    s    *K KrI   r  c                      e Zd ZdZddZy)r  z#Control for AXMenuBarItem elements.c                "    | j                         S )zOpen this menu bar item.r  rL   s    rG   r  zMenuBarItemControl.Open  r  rI   Nr  r  r  rI   rG   r  r    s
    -rI   r  c                      e Zd ZdZddZy)r  zControl for AXTab elements.c                "    | j                         S )zSelect this tab.r  rL   s    rG   r  zTabControl.Select  r  rI   Nr  )r  r
  r  r  r  r  rI   rG   r  r    s
    %rI   r  c                  "    e Zd ZdZedd       Zy)r  zControl for AXList elements.c                    t        | j                  t        j                        }|r|D cg c]  }t	        |       c}S g S c c}w )zGet selected children.)r   rM   r   SelectedChildrenro   )r;   r   r  s      rG   r  zListControl.SelectedChildren  sA      i.H.HI.67hM!$h77	 8r   Nr  )r  r
  r  r  r  r  r  rI   rG   r  r    s    & rI   r  c                  F    e Zd ZdZedd       Zedd       Zedd       Zy)r  zControl for AXTable elements.c                V    t        | j                  t        j                        }||S dS )zGet the number of rows.r   )r   rM   r   RowCountr   s     rG   r  zTableControl.RowCount  s)     4<<););<os,1,rI   c                V    t        | j                  t        j                        }||S dS )zGet the number of columns.r   )r   rM   r   ColumnCountr   s     rG   r  zTableControl.ColumnCount  s)     4<<)>)>?os,1,rI   c                f    t        | j                  t        j                        }|rt	        |      S y)zGet the table header.N)r   rM   r   Headerro   )r;   headers     rG   r  zTableControl.Header  r   rI   Nr  r  )r  r
  r  r  r  r  r  r  r  rI   rG   r  r    s?    '- -
 - -
  rI   r  c                  "    e Zd ZdZedd       Zy)r  z,Control for AXOutline elements (tree views).c                    t        | j                  t        j                        }|r|D cg c]  }t	        |       c}S g S c c}w )zGet disclosed (visible) rows.)r   rM   r   DisclosedRowsro   r   s      rG   r  zOutlineControl.DisclosedRows  sA     DLL)*A*AB.23dM!$d33	 4r   Nr  )r  r
  r  r  r  r  r  rI   rG   r  r    s    6 rI   r  c                  *    e Zd ZdZedd       ZddZy)r  z"Control for AXScrollArea elements.c                    t        | j                  t        j                        }|r|D cg c]  }t	        |       c}S g S c c}w )z$Get the contents of the scroll area.)r   rM   r   Contentsro   )r;   contentsr  s      rG   r  zScrollAreaControl.Contents  sA      i.@.@A.67hM!$h77	 8r   c                   d}d}t        | j                  t        j                        }|r(t        |t        j                        }|	 t        |      }t        | j                  t        j                        }|r,t        |t        j                        }|	 t        |      }||fS ||fS # t        t        f$ r Y gw xY w# t        t        f$ r Y ||fS w xY w)zs
        Get the scroll position as (horizontal_percent, vertical_percent).
        Values are 0.0 to 1.0.
        r  )	r   rM   r   r   r   r  r  r  r   )r;   h_pctv_pcth_barr   v_bars         rG   GetScrollPositionz#ScrollAreaControl.GetScrollPosition  s    
 T\\9+H+HIuioo6C!#JE T\\9+F+FGuioo6C!#JE u~u~ ":.  ":. u~s$   B) B> )B;:B;>CCNr  )r  ztuple[float, float])r  r
  r  r  r  r  r  r  rI   rG   r  r    s    , rI   r  c                      e Zd ZdZy)r  zControl for AXGroup elements.Nr  r  rI   rG   r  r    s    'rI   r  c                  "    e Zd ZdZedd       Zy)r  zControl for AXImage elements.c                h    t        | j                  t        j                        }|rt	        |      S dS )zGet the image URL if available.rs   r)  r   s     rG   r*  zImageControl.URL  r+  rI   Nr  r  r
  r  r  r  r*  r  rI   rG   r  r    s    '' 'rI   r  c                  "    e Zd ZdZedd       Zy)r  zControl for AXLink elements.c                h    t        | j                  t        j                        }|rt	        |      S dS )zGet the link URL.rs   r)  r   s     rG   r*  zLinkControl.URL  r+  rI   Nr  r   r  rI   rG   r  r  	  s    &' 'rI   r  c                  "    e Zd ZdZedd       Zy)r  z)Control for AXProgressIndicator elements.c                d    | j                   }	 |t        |      S dS # t        t        f$ r Y yw xY w)zGet the progress value.r  r  r   s     rG   ProgressValuez&ProgressIndicatorControl.ProgressValue  r  r  Nr  )r  r
  r  r  r  r  r  rI   rG   r  r    s    3 rI   r  c                  "    e Zd ZdZedd       Zy)r  z"Control for AXStaticText elements.c                6    | j                   xs | j                  S )zGet the text content.)r   rz   rL   s    rG   TextzStaticTextControl.Text#  s     -4::-rI   Nr  )r  r
  r  r  r  r  r  rI   rG   r  r     s    ,. .rI   r  c                  4    e Zd ZdZedd       Zedd       Zy)r  zControl for AXWebArea elements.c                h    t        | j                  t        j                        }|rt	        |      S dS )zGet the web page URL.rs   r)  r   s     rG   r*  zWebAreaControl.URL,  r+  rI   c                h    t        | j                  t        j                        }|rt	        |      S dS )zGet the document URL.rs   r-  r   s     rG   r.  zWebAreaControl.Document2  r/  rI   Nr  )r  r
  r  r  r  r*  r.  r  rI   rG   r  r  )  s+    )' '
 ' 'rI   r  c                  *    e Zd ZdZedd       ZddZy)r  z*Control for AXDisclosureTriangle elements.c                0    | j                   }|dk(  xs |du S )z$Check if the disclosure is expanded.r   Tr  r   s     rG   r  z$DisclosureTriangleControl.IsExpanded<  r  rI   c                "    | j                         S )zToggle the disclosure state.r  rL   s    rG   r  z DisclosureTriangleControl.ToggleB  r  rI   Nr  )r  r
  r  r  r  r  r  r  rI   rG   r  r  9  s    4' '
rI   r  c                      e Zd ZdZy)r  z Control for AXDockItem elements.Nr  r  rI   rG   r  r  G  s    *rI   r  c                  "    e Zd ZdZedd       Zy)r  zControl for AXCell elements.c                V    t        | j                  t        j                        }||S dS )zGet the row index of this cell.r   r   rM   r   Indexr   s     rG   RowIndexzCellControl.RowIndexP  '     4<<9os-2-rI   Nr  )r  r
  r  r  r  r  r  rI   rG   r  r  M  s    &. .rI   r  c                  F    e Zd ZdZedd       Zedd       Zedd       Zy)r  z(Control for AXRow/AXOutlineRow elements.c                V    t        | j                  t        j                        }||S dS )zGet the row index.r   r  r   s     rG   r  zRowControl.IndexZ  r  rI   c                V    t        | j                  t        j                        }||S dS )z!Get the outline disclosure level.r   )r   rM   r   DisclosureLevelr   s     rG   r  zRowControl.DisclosureLevel`  s)     4<<)B)BCos,1,rI   c                R    t        | j                  t        j                        }|du S )z2Check if this outline row is disclosed (expanded).Tr	  r   s     rG   IsDisclosedzRowControl.IsDisclosedf  r   rI   Nr  r  )r  r
  r  r  r  r  r  r  r  rI   rG   r  r  W  s?    2. .
 - -
  rI   r  c                |    t        | t        j                        }t        j	                  |t
              } ||       S )a  
    Create the appropriate typed Control subclass for an AXUIElement.
    Equivalent to Windows UIA Control.CreateControlFromElement().

    Args:
        element: An AXUIElementRef.

    Returns:
        A typed Control subclass (e.g., ButtonControl, TextFieldControl).
    rp   )r   r   r   _ROLE_TO_CONTROL_CLASSrh  r.   )r<   r?   control_classs      rG   ro   ro     s1     0D*..tW=M))rI   c
                N   ||kD  ry|	r|ryt        |       }
|
D ]	  }|	r|r yt        |t        j                        xs d}|rt        |t        j                        xs dnd}|rt        |t        j
                        xs dnd}|rt        |t        j                        xs dnd}d}|r||k7  rd}|r	|r||k7  rd}|r|r||vrd}|r	|r||k7  rd}|r|rt        |      } ||      sd}|r|s|s|s|s|r|j                  |       |	r yt        |||||||||dz   |	
        y)z
    Recursive element search helper that collects raw AXUIElementRefs.
    Used by Control.FindAll/FindFirst and the lazy search system.
    The predicate receives a CreateControl-wrapped element for filtering.
    Nrs   TFr   )
r   r   r   r   r   rz   r   ro   rk   rb   )r<   rf   r?   rA   r@   rB   rC   rT  current_depthra   r   r   
child_rolechild_subrolechild_titlechild_identifiermatchcontrols                     rG   rb   rb     sV   " y gG$H' "%8>B
<CL	 1 128b 	 EJl5)//:@bt?IL	 4 45;t 	
 J$&EW'!9EUuK7EZ$4
$BEY#E*GW%dg*	NN5! 	A	
G rI   r  )r<   r   rf   z	list[Any]r?   r  rA   r  r@   r  rB   r  rC   r  rT  r  r   r  ra   r  r  r  )xr  
__future__r   rP   loggingtypingr   r   r   r   r   ApplicationServicesr	   r
   enumsr   r   r   r   r   corer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r^  r%   re  r&   rg  r'   rj  r(   r  r)   rm  r*   rq  r+   rw  r,   r~  	getLoggerr  loggerr.   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  
OutlineRowr  ro   rb   r  rI   rG   <module>r0     s   #   7 7
        > 
		8	$a' a'R'G GTcG cL	G 	g   w  ,	& 		g 	 8G 8<
g 
  	' 	7 0	W 	" "J	7 	'7 ''' '
w 
. .'W '  	g 	.' . 6(KK 	KK 	MM?	
 	( 	NN$ 	MM? 	MM? 	( 	KK 	MM? 	( 	HHj 	II{ 	JJ  	LL.!" 	OO&#$ 	JJJJII{4OO&LL.6MM?II{HHjOOZ9 @**E
E
E
 E
 	E

 E
 E
 3E
 E
 E
 E
 
E
rI   