
    XaJj.                         d Z g dZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZmZ ddlmZ ddgej                   dkD     Zd	 Zd
 ZddZd Zd ZddZd ZddZddZd Zd ZddZd ZddZddedfdZ d Z!y)zu
Python <-> Objective-C bridge (PyObjC)

This module defines the core interfaces of the Python<->Objective-C bridge.
)IBOutletIBActionaccessorAccessortypedAccessorcallbackForselectorFor
synthesizenamedselectortypedSelectornamedSelectorinstancemethod	signatureIBInspectableIB_DESIGNABLEcallbackPointer    N)_C_ID	_C_NSBOOL_C_SEL_C_NSUInteger_closurePointer_makeClosureivarselector)getfullargspecs   {_NSRange=II}s   {_NSRange=QQ}l        c                     | S )z
    Class decorator for annotating that a class can be used in Interface Builder.

    The decorator doesn't do anything.
     )clss    [/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/objc/_descriptors.pyr   r   1   s	     J    c                     | S )zy
    Decorator for an Objective-C property to tell IB that the updated in IB.

    The decorator doesn't do anything
    r   )props    r   r   r   :   s	     Kr    c                 8    | t        d      S t        | d      S )z]
    Create an instance variable that can be used as an outlet in
    Interface Builder.
       )isOutlet)r   )names    r   r   r   C   s!    
 |QD1%%r    c                 6    | t        d      t        | d      S )ze
    Return an Objective-C method object that can be used as an action
    in Interface Builder.
    z$IBAction argument must be a callable   v@:@r   	TypeErrorr   funcs    r   r   r   N   s"    
 |>??DG,,r    c                 6    | t        d      t        | d      S )Nz*instancemethod argument must be a callableF)isClassMethodr*   r,   s    r   r   r   X   s     |DEED..r    c                    t        |       \  }}}}}}}| j                  }	t        |      }
|
t        |xs d      z
  }d|	j                  d      z   }|||rt	        |	d      ||cxk  r|
k  s*n ||
k(  rt	        d|	|
|fz        t	        d|	||
|fz        |dk(  r1|	j                  d      r%|	j                  d	      rt        | t        d
z         S |	j                  d      r(|	j                  d      rt        | d|z   t        z         S |	j                  d      r(|	j                  d      rt        | dt        z   |z         S |	j                  d      r%|	j                  d      rt        | dt        z         S |	j                  d      r|	j                  d      rt        | d      S |	j                  d      rd|	v rt        | d      S |dk(  rb|	j                  d      r(|	j                  d      rt        | |dz   t        z         S |	j                  d      r%|	j                  d      rt        | dt        z         S |	j                  d      r|	j                  d      rt        | d      S |	j                  d      rt        | d       S |	j                  d!      rt        | t        dz   |z         S |	j                  d"      r!|	j                  d#      rt        | d|z         S |	j                  d"      rt        | d      S |	j                  d$      rt        | d      S t        | d|z         S |dk(  r;|	j                  d%      rt        }n|	j                  d&      rd'}t        | |dz         S t	        |	 d(      ))zs
    Return an Objective-C method object that is conformant with key-value coding
    and key-value observing.
    r   r$   _zC can not be an accessor because it accepts varargs, varkw or kwonlyzj%s expected to take %d args, but must accept %d from Objective-C (implicit self plus count of underscores)zy%s expected to take between %d and %d args, but must accept %d from Objective-C (implicit self plus count of underscores)   validate_error_s   @:N^@o^@r)   insertObject_inAtIndex_s   v@:replaceObjectInAtIndex_withObject_get_range_s   v@:o^@insert_atIndexes_s   v@:@@replaceAtIndexes_with   objectIns   @:removeObjectFromremove
AtIndexes_r(   s   @@:@memberOfaddObject_	intersectcountOf
enumerator   @z not recognized as an accessor)r   __name__lencountr+   
startswithendswithr   r   r   
_C_NSRange)r-   typeSignatureargsvarargsvarkwdefaults
kwonlyargs_kwonlydefaults_annotationsfuncNamemaxArgsminArgsselArgss                r   r   r   ^   s    	t}}H$iGHN++G(..%%Ge/:
 	

 w)')gMWg./  MWgw78  !|z*x/@/@/KDI,CDD01h6G6G
6SDF],B],RSS  !238I8I!9
 DF],B],RSS  'H,=,=i,HDI
,BCC  *x/@/@/ODH55  +0@H0LDH55 
Az*x/@/@/LDME,AM,QRR  !349J9J:9VDF],BCC  *x/@/@/NDG44|,DG44  ,DI,=,MNN  'H,=,=i,HDF],BCC  'DG44  -DG44(>??	Ay))M  . M(=>>
xj >?
@@r    c                       fd}|S )Nc                     | t        d      t        | t              rt        | j                  d      S t        |       S )Nz4typedSelector() function argument must be a callableT)r   r/   r)   r+   
isinstanceclassmethodr   __func__)r-   r   s    r   _typedSelectorz%typedSelector.<locals>._typedSelector   s>    <RSSdK(DMMYdSS	22r    r   )r   rc   s   ` r   r   r      s    3 r    c                 (      fd}|S  fd}|S )z
    Decorator for overriding the Objective-C SEL for a method, usage:

        @namedSelector("foo:bar:")
        def foobar(self, foo, bar):
            return foo + bar
    c                     | t        d      t        | t              rt        | j                  d      S t        |       S )N)namedSelector argument must be a callableT)r   r   r/   )r   r   r_   )r-   r&   r   s    r   _namedselectorz%namedSelector.<locals>._namedselector   sL    | KLL$,MM!'"&	  D49EEr    c                     | t        d      t        | t              rt        | j                  d      S t        |       S )Nrf   T)r   r/   r   r_   )r-   r&   s    r   rg   z%namedSelector.<locals>._namedselector   sG    | KLL$,MM!"& 
 D400r    r   )r&   r   rg   s   `` r   r   r      s&     
	F2 		1 r    c                 R    t        j                  dt        d       t        | |      S )Nz4use objc.namedSelector instead of objc.namedselectorr?   
stacklevel)warningswarnDeprecationWarningr   )r&   r   s     r   r
   r
      s&    MM>
 y))r    c                       fd}|S )a  
    Decorator for creating a typed accessor, usage:

        @typedAccessor('i')
        def someIntegerAccessor(self):
            return self.someInteger

        @typedAccessor('i')
        def setSomeIntegerAccessor_(self, anInteger):
            self.someInteger = anInteger
    c                     t        |       S N)r   )r-   rQ   s    r   _typedAccessorz%typedAccessor.<locals>._typedAccessor  s    m,,r    r   )rQ   rs   s   ` r   r   r      s    - r    c                 P    t        j                  dt        d       t        |       S )Nz*Use objc.accessor instead of objc.Accessorr?   rk   )rm   rn   ro   r   r,   s    r   r   r     s#    MM46HUV D>r    c                       fd}|S )a  
    Decorator for converting a function into an object that can be used
    as a callback function for (Objective-)C API's that take such a beast
    as one of their arguments.

    Note that using this decorator for methods is unsupported and that this
    decorator is optional when the callback isn't stored by the called function

    Usage::

        @objc.callbackFor(NSArray.sortedArrayUsingFunction_context_)
        def compare(left, right, context):
            return 1
    c                 L    t        |       \  }|| _        fd| _        | S )Nc                       S rr   r   )metas   r   <lambda>z1callbackFor.<locals>.addClosure.<locals>.<lambda>%  s    r    )r   pyobjc_closure__metadata__)functionclosurerx   argIndexcallables     @r   
addClosurezcallbackFor.<locals>.addClosure"  s*    $XxB") ,r    r   )r   r~   r   s   `` r   r   r     s      r    c                 Z    t        | d      st        d      t        | j                        S )zj
    Return a value for "closure" that can be passed to a function
    expecting a "void *" argument.
    rz   z*Object is not decorated with 'callbackFor')hasattr
ValueErrorr   rz   )r}   s    r   r   r   +  s,    
 7,-EFF71122r    c                    |dk(  r;| j                         d   D ]  }|d   t        k(  sd|v s|d    n& t        d      	 | j                         d   |   d   fd}|S # t        t        f$ r t        d      w xY w)av  
    Decorator that makes sure that the method has the right signature to be
    used as the selector argument to the specified method.

    Usage::

        @objc.selectorFor(NSApplication.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_)  # noqa: B950
        def sheetDidEnd_returnCode_contextInfo_(self, sheet, returnCode, info):
            pass
    	argumentstypesel_of_typez-Not a selector argument with type informationc                     t        |       S )Nr)   ri   )r|   r   s    r   addSignaturez!selectorFor.<locals>.addSignatureO  s    I66r    )r{   r   r   
IndexErrorKeyError)r   r~   argr   r   s       @r   r   r   6  s     2~((*;7C6{f$#)=.	 8
 LMM	N --/<XF}UI7  H% 	NLMM	Ns   A# #A>FTc                    | st        d      |d| z   }t        j                  d      j                  }d| d   j	                          | dd  d}|rt        j                  d||dz        }nt        j                  d	||dz        }t        j                  d
| |dz        }|rt        |t               |       t        |t               |       t        |      ||<   y)aC  
    Use this in a class dictionary to syntheze simple setting/setter methods.

    Note: this is only necessary to get proper behaviour when Key-Value coding
    is used and special features (like copying) are needed

    usage::

        class MyClass (NSObject):
            objc.synthesize('someTitle', copy=True)

    zEmpty property nameNr1   r$   setr   za
            def %(name)s(self, value):
                self.%(ivar)s = value.copy()
            )r&   r   zZ
            def %(name)s(self, value):
                self.%(ivar)s = value
            zR
            def %(name)s(self):
                return self.%(ivar)s
            )r   )
r   sys	_getframef_localsuppertextwrapdedentexecglobalsr   )	r&   copy	readwriter   ivarName	classDict
setterNamesettergetters	            r   r	   r	   U  s     .//:a ))ItAw}}'QRz3J "84	5
  "84	5
 __	 
*		+F VWY	*I&D/Ihr    c                 T    t        j                  dt        d       | d<   fd}|S )z
    A Python method decorator that allows easy specification
    of Objective-C selectors.

    Usage::

        @objc.signature('i@:if')
        def methodWithX_andY_(self, x, y):
            return 0
    z2Usage objc.typedSelector instead of objc.signaturer?   rk   r   c                     t        | fi S rr   ri   )r-   kws    r   makeSignaturez signature.<locals>.makeSignature  s    ###r    )rm   rn   ro   )r   r   r   s    ` r   r   r     s2     MM<
  B{O$ r    rr   )rJ   )r   )"__doc____all__r   r   rm   
objc._objcr   r   r   r   r   r   r   r   inspectr   maxsizerP   r   r   r   r   r   r   r   r   r
   r   r   r   r   r   r	   r   r   r    r   <module>r      s   &   	 	 	 # 01#++2EF
&-/YAx	#L*&23@ 548*vr    