
    Cj                        S r SSKJr  SSKJr  SSKJrJrJrJ	r	J
r
  SSKJrJr  SSKJrJrJr  SSKJr  \(       a  SSKJr  SS	KJr  SS
KJr  \	" SSS9r " S S\\   5      r " S S\\   5      r " S S\\   5      rg)zC
Descriptors to define properties on your widget, screen, or App.

    )annotations)isclass)TYPE_CHECKINGCallableGenericTypeVaroverload)NoActiveAppError
active_app)	NoMatches	QueryType	WrongTypeWidgetApp)DOMNode)MessagePumpAppTyper   )boundc                  ,    \ rS rSrSrSS jrSS jrSrg)	app   a  Create a property to return the active app.

All widgets have a default `app` property which returns an App instance.
Type checkers will complain if you try to access attributes defined on your App class, which aren't
present in the base class. To keep the type checker happy you can add this property to get your
specific App subclass.

Example:
    ```python
    class MyWidget(Widget):
        app = getters.app(MyApp)
    ```

Args:
    app_type: The App subclass, or a callable which returns an App subclass.
c                J    [        U5      (       a  Xl        g U" 5       U l        g N)r   	_app_type)selfapp_types     a/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/getters.py__init__app.__init__*   s    %,X%6%6HJ    c                    [         R                  " 5       n[        X0R                  5      (       d   eU$ ! [         aH    SSKJn  Un[        XT5      (       d+  Uc
  [        5       eUR                  n[        XT5      (       d  M+  Un Nof = f)Nr   r   )	r   getLookupErrortextual.appr   
isinstancer
   _parentr   )r   objobj_typer   r   nodes         r   __get__app.__get__-   s~    
	.."C #~~....
  	''*D ++<*,,|| !++ C	s   5 ABBB)r   N)r   z+type[AppType] | Callable[[], type[AppType]]returnNone)r)   r   r*   ztype[MessagePump]r.   r   )__name__
__module____qualname____firstlineno____doc__r    r,   __static_attributes__ r"   r   r   r      s    "Gr"   r   c                     \ rS rSr% SrS\S'   S\S'   \SS j5       r\SS j5       r\SS	 j5       r\      SS
 j5       r S     SS jjr\        SS j5       r\        SS j5       r        SS jrSr	g)	query_one>   a  Create a query one property.

A query one property calls [Widget.query_one][textual.dom.DOMNode.query_one] when accessed, and returns
a widget. If the widget doesn't exist, then the property will raise the same exceptions as `Widget.query_one`.


Example:
    ```python
    from textual import getters

    class MyScreen(screen):

        # Note this is at the class level
        output_log = getters.query_one("#output", RichLog)

        def compose(self) -> ComposeResult:
            with containers.Vertical():
                yield RichLog(id="output")

        def on_mount(self) -> None:
            self.output_log.write("Screen started")
            # Equivalent to the following line:
            # self.query_one("#output", RichLog).write("Screen started")
    ```

Args:
    selector: A TCSS selector, e.g. "#mywidget". Or a widget type, i.e. `Input`.
    expect_type: The type of the expected widget, e.g. `Input`, if the first argument is a selector.

strselectorztype['Widget']expect_typec                    g)z8

Args:
    selector: A TCSS selector, e.g. "#mywidget"
Nr6   r   r;   s     r   r    query_one.__init__a   s    r"   c                    g r   r6   r>   s     r   r    r?   i   s    ;>r"   c                    g r   r6   r   r;   r<   s      r   r    r?   l       MPr"   c                    g r   r6   rB   s      r   r    r?   o   s     r"   Nc                    Uc  SSK Jn  X0l        OX l        [        U[        5      (       a  Xl        g UR                  U l        Xl        g )Nr   r   )textual.widgetr   r<   r'   r:   r;   r0   )r   r;   r<   r   s       r   r    r?   t   s>    
 -%*h$$$M$--DM'r"   c                    g r   r6   r   r)   r*   s      r   r,   query_one.__get__        r"   c                    g r   r6   rH   s      r   r,   rI      s     "%r"   c                \    Uc  U $ UR                  U R                  U R                  5      nU$ )1Get the widget matching the selector and/or type.)r8   r;   r<   )r   r)   r*   
query_nodes       r   r,   rI      s.     ;K]]4==$2B2BC
r"   )r<   r;   )r;   r:   r.   r/   )r;   type[QueryType]r.   r/   )r;   r:   r<   rO   r.   r/   )r;   rO   r<   rO   r.   r/   r   )r;   zstr | type[QueryType]r<   type[QueryType] | Noner.   r/   )r   'query_one[QueryType]'r)   r   r*   type[DOMNode]r.   r   )r   rQ   r)   r/   r*   rR   r.   rQ   )r   rQ   r)   DOMNode | Noner*   rR   r.   z QueryType | Widget | 'query_one'
r0   r1   r2   r3   r4   __annotations__r	   r    r,   r5   r6   r"   r   r8   r8   >   s!   > M  > >P P'6E	  /3('( ,( 
	(" $+2>K	  %$%+/%;H%	% %$+9ER	)r"   r8   c                      \ rS rSr% SrS\S'   S\S'   \SS j5       r\SS j5       r S     SS
 jjr\        SS j5       r\        SS j5       r        SS jrSr	g	)child_by_id   a  Create a child_by_id property, which returns the child with the given ID.

This is similar using [query_one][textual.getters.query_one] with an id selector, except that
only the immediate children are considered. It is also more efficient as it doesn't need to search the DOM.


Example:
    ```python
    from textual import getters

    class MyScreen(screen):

        # Note this is at the class level
        output_log = getters.child_by_id("output", RichLog)

        def compose(self) -> ComposeResult:
            yield RichLog(id="output")

        def on_mount(self) -> None:
            self.output_log.write("Screen started")
    ```

Args:
    child_id: The `id` of the widget to get (not a selector).
    expect_type: The type of the expected widget, e.g. `Input`.

r:   child_idztype[Widget]r<   c                    g r   r6   )r   rY   s     r   r    child_by_id.__init__   s    /2r"   c                    g r   r6   r   rY   r<   s      r   r    r[      rC   r"   Nc                :    Uc  [         U l        OX l        Xl        g r   )r   r<   rY   r]   s      r   r    r[      s    
 %D* r"   c                    g r   r6   rH   s      r   r,   child_by_id.__get__   rJ   r"   c                    g r   r6   rH   s      r   r,   r`      s     $'r"   c                J   Uc  U $ UR                  5       R                  R                  U R                  5      nUc  [	        SU R                  < 35      e[        X0R                  5      (       d4  [        SU R                  < SU R                  R                  < SU 35      eU$ )rM   zNo child found with id=zChild with id=z" is the wrong type; expected type z, found )	_get_dom_base_nodes
_get_by_idrY   r   r'   r<   r   r0   )r   r)   r*   childs       r   r,   r`      s     ;K!!#**55dmmD=5dmm5FGHH%!1!122  11STXTdTdTmTmSppxy~x  A  r"   )rY   r<   )rY   r:   r.   r/   )rY   r:   r<   rO   r.   r/   r   )rY   r:   r<   rP   r.   r/   )r   'child_by_id[QueryType]'r)   r   r*   rR   r.   r   )r   rg   r)   r/   r*   rR   r.   rg   )r   rg   r)   rS   r*   rR   r.   z"QueryType | Widget | 'child_by_id'rT   r6   r"   r   rW   rW      s    8 M2 2P P
 /3	!	! ,	! 
		! &-4@M	  '&'-1'=J'	!' '&-;GT	+r"   rW   N)r4   
__future__r   inspectr   typingr   r   r   r   r	   textual._contextr
   r   textual.css.queryr   r   r   rF   r   r&   r   textual.domr   textual.message_pumpr   r   r   r8   rW   r6   r"   r   <module>ro      sw   
 #  F F 9 = = !#0 )5
)#''
 #LX	" XvH')$ Hr"   