
    AHj	                        d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZ d d	lmZ  G d
 de      Z G d de      Zy)    )annotationsN)Syntax)work)ComposeResult)Binding)ScrollableContainer)ModalScreenScreen)Staticc                  8     e Zd ZdZdgZd fdZddZd Z xZS )
CodeScreenz
    CodeScreen {
        #code {
            border: heavy $accent;
            margin: 2 4;
            scrollbar-gutter: stable;
            Static {
                width: auto;
            }
        }
    }
    )escapedismisszDismiss codec                >    t         |           || _        || _        y )N)super__init__codetitle)selfr   r   	__class__s      I/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/demo/page.pyr   zCodeScreen.__init__   s    	
    c           	   #     K   t        d      5  t        t        | j                  ddd      d       d d d        y # 1 sw Y   y xY ww)Nr   )idpythonT)lexerindent_guidesline_numbers)expand)r   r   r   r   )r   s    r   composezCodeScreen.compose#   sJ      F+ 	IIXTPT 	 	 	 	s   A'?	AAAc                V    | j                  d      }| j                  |_        d|_        y )Nz#codezEscape to close)	query_oner   border_titleborder_subtitle)r   code_widgets     r   on_mountzCodeScreen.on_mount,   s$    nnW-#':: &7#r   )r   strr   r'   returnNone)r(   r   )	__name__
__module____qualname__DEFAULT_CSSBINDINGSr   r    r&   __classcell__)r   s   @r   r   r      s#    K 66H
8r   r   c                  P    e Zd ZdZ edddd      gZ ed      dd	       Zd
 Zy)
PageScreenzh
    PageScreen {
        width: 100%;
        height: 1fr;
        overflow-y: auto;        
    }
    c	show_codeCodez*Show the code used to generate this screen)tooltipT)threadc                    	 t        |dd      5 }|j                         cddd       S # 1 sw Y   yxY w# t        $ r Y yw xY w)z/Read code from disk, or return `None` on error.rtzutf-8)encodingN)openread	Exception)r   source_filefile_s      r   get_codezPageScreen.get_codeC   sD    	k4': $ezz|$ $ $ 		s#   6 *	6 36 6 	AAc                B  K   t        j                  | j                        }|| j                  ddd       y | j	                  |      j                          d {   }|| j                  ddd       y | j                  j                  t        d|             y 7 Aw)Nz$Could not get the code for this pagez	Show codeerror)r   severityzCode for this page)	inspectgetsourcefiler   notifyr?   waitapppush_screenr   )r   r=   r   s      r   action_show_codezPageScreen.action_show_codeL   s     ++DNN;KK6!   
 ]];/4466<KK6!    HH  ,@$!GH 7s   ABBABN)r=   r'   r(   z
str | None)	r*   r+   r,   r-   r   r.   r   r?   rI    r   r   r1   r1   2   sE    K 	@		
H 
 Ir   r1   )
__future__r   rC   rich.syntaxr   textualr   textual.appr   textual.bindingr   textual.containersr   textual.screenr	   r
   textual.widgetsr   r   r1   rJ   r   r   <module>rS      s;    "    % # 2 . " 8  8F,I ,Ir   