
    +d*                         d dl Z d dlZd dlmZ d dlZd dlZd dlmZ d dl	Z	ddl
mZmZmZmZ  G d de          Z G d d	e          Z G d
 de          ZdS )    N)partial)known_implementations   )ICONS	MAX_WIDTHBaseenable_widgetc                        e Zd ZdZddgdf fd	Zd Zd Zd Zed	             Z	ed
             Z
ddZddZddZddZd Zd Zd Z xZS )FileSelectora]  
    Panel interface for picking files

    The current path is stored in .path and the current selection is stored in
    .url.

    Parameters
    ----------
    filters: list of string
        extentions that are included in the list of files - correspond to
        catalog extensions.
    done_callback: func, opt
        called when the object's main job has completed. In this case,
        selecting a file.

    Attributes
    ----------
    url: str
        path to local catalog file
    children: list of panel objects
        children that will be used to populate the panel when visible
    panel: panel layout object
        instance of a panel layout (row or column) that contains children
        when visible
    watchers: list of param watchers
        watchers that are set on children - cleaned up when visible
        is set to false.
    yamlymlNc                     || _         t          j        ddd          | _        || _        t          j        d          | _         t                      j	        di | d S )NLocalmaxr   namewidth_policymarginfile )
filterspnColumnpaneldone_callbackfsspec
filesystemfssuper__init__)selfr   r   kwargs	__class__s       <lib/python3.11/site-packages/intake/interface/catalog/add.pyr    zFileSelector.__init__3   s_    YG%JJJ
*#F++""6"""""    c                    t           j                            t          j                    dz   d          | _        t           j                            t          t          t                              dd          | _
        t           j                            dd	          | _        t           j                            d
          | _        t           j                            d d          | _        t           j                            dd          | _        t           j                            ddd          | _        t           j                            ddd          | _        |                                  | j        j                            | j        d          | j
        j                            | j        d          | j        j                            | j        d          | j        j                            | j        d          | j        j                            | j        dg          g| _        t          j        | j
        | j                  t          j        | j        | j        | j        | j        d          | j        g| _        d S )N/r   )valuer   r   protocol)optionsr(   r   r"   z{})r   r(   u   ⇨)r      width   )sizer   u   🏠(      )r   r-   heightu   ‹clicksr(   r   )r   ) r   widgets	TextInputosgetcwd	path_textSelectlistsortedr   r)   storage_optionsButtongopaneSVG	validatorMultiSelectmainhomeupmake_optionsparamwatch
go_clickedprotocol_changedgo_homemove_up	move_downwatchersRowchildrenr!   s    r$   setupzFileSelector.setup:   s   --BIKK#4ETY-ZZ
))$v>S7T7T2U2U]cjt)uu!z333NN*###//T44J***GG	J%%6B%GG	*##b#DD GM::M%%d&;WEE IO!!$,99GMh77IO!!$.7)<<
 t/CDDbfTYX\X_aeaoquqx  BC  GD  GD  GD  FJ  FO  Pr%   c                 N    d| j         _        g | j        _        g | j        _        d S )N )r8   r(   rC   r*   r!   _s     r$   rJ   zFileSelector.protocol_changedR   s#    !		r%   c                     t          j        | j        j        fi t	          j        | j        j                  | _        |                                  d S N)	r   r   r)   r(   astliteral_evalr<   r   rF   rU   s     r$   rI   zFileSelector.go_clickedW   sJ    #DM$7hh3;KDL`Lf;g;ghhr%   c                     | j         j        S rX   )r8   r(   rQ   s    r$   pathzFileSelector.path[   s    ~##r%   c                     | j         j        dz   t          j                            | j        | j        j        d                   z   S )zPath to local catalog filez://r   )r)   r(   r6   r\   joinrC   rQ   s    r$   urlzFileSelector.url_   s5     }"U*RW\\$)TY_UVEW-X-XXXr%   c                     | j                             | j        j                  | j        _        |                                  d S rX   )r   _parentr8   r(   rF   r!   args     r$   rL   zFileSelector.move_upd   s7    #wt~/CDDr%   c                 |    d| j         _        t          j                    t          j        j        z   | j        _        d S )Nr   )r)   r(   r6   r7   r\   sepr8   rb   s     r$   rK   zFileSelector.go_homeh   s+    $!y{{RW[8r%   c                     t           j                            | j                  rd| j        _        dS t
          d         | j        _        dS )z=Check that inputted path is valid - set validator accordinglyNerror)r6   r\   isdirrA   objectr   rb   s     r$   validatezFileSelector.validatel   s>    7==## 	3$(DN!!!$)'NDN!!!r%   c                    | j         r|                      d           g }	 | j                            | j        d          D ]}t          j                            |d                             d                                        d          rP|d         dk    r|                    dz              u| j	        r t          fd| j	        D                       r|                               n&# t          $ r}t          |           Y d }~nd }~ww xY wg | j        _        t          |          | j        _        d S )	NFTr   r'   .type	directoryc              3   B   K   | ]}                     |          V  d S rX   )endswith).0extbns     r$   	<genexpr>z,FileSelector.make_options.<locals>.<genexpr>~   s/      ,V,V#R[[-=-=,V,V,V,V,V,Vr%   )r   r   lsr\   r6   basenamerstrip
startswithappendr   any	ExceptionprintrC   r(   r;   r*   )r!   rc   outfers   s        @r$   rF   zFileSelector.make_optionss   sQ    	&u%%%
	WZZ	400 # #W%%ai&6&6s&;&;<<==%% #vY+- #JJrCx(((( #,V,V,V,V,V,V,V)V)V #JJrNNN#  	 	 	!HHHHHHHH	 	"3KK	s   CC4 4
D>DDc                    |D ]}|j         dk    rt          |j                  dk    r|j        d         }|                    d          rb| j        j        r5t          j                            | j        j        |          | j        _        n|| j        _        | 	                                 | j
        r| 
                    d           d S )Nr(   r   r'   T)r   lennewrp   r8   r(   r6   r\   r^   rF   r   )r!   eventseventfns       r$   rM   zFileSelector.move_down   s     
	- 
	-EzW$ 	-UY!); 	-Yq\;;s## -~+ 2/1w||DN<PRT/U/U,,/1,%%''''' -&&t,,,
	- 
	-r%   c                 *    | j         | j        j        dS )*Serialize the current state of the object.)r\   selected)r\   rC   r(   rQ   s    r$   __getstate__zFileSelector.__getstate__   s    	ty???r%   c                 N    |d         | j         _        |d         | j        _        | S )Set the current state of the object from the serialized version.
        Works inplace. See ``__getstate__`` to get serialized version and
        ``from_state`` to create a new object.r\   r   )r8   r(   rC   r!   states     r$   __setstate__zFileSelector.__setstate__   s%      %V}
+	r%   rX   )__name__
__module____qualname____doc__r    rR   rJ   rI   propertyr\   r_   rL   rK   rj   rF   rM   r   r   __classcell__r#   s   @r$   r   r      s;        : !'d # # # # # #P P P0  
   $ $ X$ Y Y XY   9 9 9 93 3 3 3( ( ( (&- - -@ @ @      r%   r   c                   J     e Zd ZdZ fdZd Zed             Zd Zd Z	 xZ
S )URLSelectora1  
    Panel interface for inputting a URL to a remote catalog

    The inputted URL is stored in .url.

    Attributes
    ----------
    url: str
        url to remote files (including protocol)
    children: list of panel objects
        children that will be used to populate the panel when visible
    panel: panel layout object
        instance of a panel layout (row or column) that contains children
        when visible
    watchers: list of param watchers
        watchers that are set on children - cleaned up when visible
        is set to false.
    c                 r    t          j        ddd          | _         t                      j        di | d S )NURLr   r   r   r   )r   rO   r   r   r    )r!   r"   r#   s     r$   r    zURLSelector.__init__   s>    VU1EEE
""6"""""r%   c                 n    t           j                            dd          | _        d| j        g| _        d S )NzFull URL with protocolr   )placeholderr   zURL:)r   r4   r5   rC   rP   rQ   s    r$   rR   zURLSelector.setup   s2    J((5M\a(bb	+r%   c                     | j         j        S )z(URL to remote files (including protocol)rC   r(   rQ   s    r$   r_   zURLSelector.url   s     yr%   c                     d| j         iS )r   r_   )r_   rQ   s    r$   r   zURLSelector.__getstate__   s    tx  r%   c                 *    |d         | j         _        | S )r   r_   r   r   s     r$   r   zURLSelector.__setstate__   s      ,	r%   )r   r   r   r   r    rR   r   r_   r   r   r   r   s   @r$   r   r      s         &# # # # #, , ,   X! ! !      r%   r   c                   z     e Zd ZdZdZd fd	Zd Zed             Zed             Z	ddZ
d Zd	 Zd
 Zd Z xZS )CatAddera  Panel for adding new cats from local file or remote

    Parameters
    ----------
    done_callback: function with cat as input
        function that is called when the "Add Catalog" button is clicked.

    Attributes
    ----------
    cat_url: str
        url to remote files or path to local files. Depends on active tab
    cat: catalog
        catalog object initialized from from cat_url
    children: list of panel objects
        children that will be used to populate the panel when visible
    panel: panel layout object
        instance of a panel layout (row or column) that contains children
        when visible
    watchers: list of param watchers
        watchers that are set on children - cleaned up when visible
        is set to false.
    Nc                 Z   || _         t          j        ddt          d          | _        t          j                            ddd          | _        t          t          t          | j                            | _        t                      | _         t                      j        d	i | d S )
NzAdd Catalogr   r   )r   r   	max_widthr   Tmin)r   disabledr   )r   r   )r   r   r   r   r   r4   r=   widgetr   r   r	   r   r   r_   r   r    )r!   r   r"   r#   s      r$   r    zCatAdder.__init__   s    *YMQZcdeee
j'']TX]'^^W]DK-P-PQQQ==""6"""""r%   c                 ^   | j         | j        g| _        t          j        t          d | j                   | _        t          j                            d d          | _	        | j
        j                            | j        d          | j        j                            | j        d          | j         j        j                            | j        d          | j        j        j                            | j        d          g| _        | j        t          j        | j
        | j	                  g| _        d S )Nc                     | j         S rX   )r   )xs    r$   <lambda>z CatAdder.setup.<locals>.<lambda>   s    17 r%   r+   r,   r3   activer(   )r   r_   	selectorsr   Tabsmaptabsr?   r@   rA   r   rG   rH   add_cat
tab_changerC   remove_errorrN   rO   rP   rQ   s    r$   rR   zCatAdder.setup   s    '48,GS!2!2DNCCD	T44 K##DL(;;IO!!$/8<<GL$$T%6@@HM%%d&7AA	
 BF4;$G$GHr%   c                     | j         | j        j                 j        }| j         | j        j                 | j        u r| j        j        }nd}||fS )zBURL to remote files or path to local files. Depends on active tab.N)r   r   r   r_   r   r!   r_   r   s      r$   cat_urlzCatAdder.cat_url   sL     nTY-.2>$)*+tw6 	BBBBwr%   c                 n    | j         \  }}|rt          j        ||          S t          j        |          S )z,Catalog object initialized from from cat_url)r   )r   intakeopen_catalogr   s      r$   catzCatAdder.cat  s>     ,R 	,&sr2222&s+++r%   c                     	 |                      | j                   d| _        dS # t          $ r}t          d         | j        _        |d}~ww xY w)zAdd cat and close panelFrg   N)r   r   visibler{   r   rA   ri   )r!   rc   r   s      r$   r   zCatAdder.add_cat  sZ    	tx((( DLLL 	 	 	$)'NDN!G	s   !% 
AAAc                     d| j         _        dS )zRemove error from the widgetN)rA   ri   )r!   argss     r$   r   zCatAdder.remove_error  s     $r%   c                 `    |                                   |j        dk    rd| j        _        dS dS )z>When tab changes remove error, and enable widget if on url tab   FN)r   r   r   r   )r!   r   s     r$   r   zCatAdder.tab_change  s<    9> 	)#(DK   	) 	)r%   c                     | j         | j                                        | j                                        | j        r| j        j        nddS )z)Serialize the current state of the objectr   )r   localremoter   )r   r   r   r_   r   r   rQ   s    r$   r   zCatAdder.__getstate__$  so    <$'2F2F2H2HTXT\TiTiTkTk  LP  LU  x\w{  xA  xH  xH  [\  ]  ]  	]r%   c                     | j                             |d                    | j                            |d                    |                    dd          | _        | j        r|d         | j        _        | S )r   r   r   r   Tr   )r   r   r_   getr   r   r   r   s     r$   r   zCatAdder.__setstate__(  sj     	U7^,,,eHo...yyD11< 	/$XDIr%   rX   )r   r   r   r   r   r    rR   r   r   r   r   r   r   r   r   r   r   s   @r$   r   r      s         . D# # # # # #I I I   X , , X,   % % %) ) )] ] ]	 	 	 	 	 	 	r%   r   )rY   r6   	functoolsr   r   r   r   fsspec.registryr   r   baser   r   r   r	   r   r   r   r   r%   r$   <module>r      s   


 				            1 1 1 1 1 1  8 8 8 8 8 8 8 8 8 8 8 8H H H H H4 H H HV* * * * *$ * * *Zd d d d dt d d d d dr%   