
    {h                         d dl mZ d dlmZ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 d dlZd d	lmZmZmZmZmZ d d
lmZ d dlmZmZ d dlmZ d dlmZ d dlm Z   G d de      Z!y)    )ComposeResult)StaticFooter)Binding)Screen)Message)on)PathN)BORDER_STYLEGITHUB_BRANCHPRIMARY_COLORModeGITHUB_BASE_URL)FileExplorerScreen)AtomicToolManagerGithubRepoCloner)GenericList)ToolInfoScreen)ConfirmationModalc                   z    e Zd ZdZde dZ edddd       ed	d
d      gZ G d de      Z	 fdZ
d Zd ZdefdZd#dZd Zd ZdedefdZ eej.                        dej.                  ddfd       Z eej2                        dej2                  fd       Zd ZdefdZdefdZd  Zdefd!Z d" Z! xZ"S )$AtomicToolExplorerScreenz2Screen for exploring and downloading atomic tools.z
    Screen {
        align: center middle;
    }

    #title {
        dock: top;
        padding: 1 2;
        color: $text;
        text-align: center;
        text-style: bold;
        border: solid zg;
    }

    #current-tool {
        padding: 1 2;
    }

    Footer {
        color: $text;
    }
    escapezapp.pop_screenExitT)showishow_tool_infoz	Tool Infoc                   ,     e Zd ZdZdeddf fdZ xZS )%AtomicToolExplorerScreen.ToolSelectedz(Message emitted when a tool is selected.	tool_inforeturnNc                 0    || _         t        | 	          y N)r   super__init__)selfr   	__class__s     n/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/atomic_assembler/screens/atomic_tool_explorer.pyr$   z.AtomicToolExplorerScreen.ToolSelected.__init__4   s    &DNG    )__name__
__module____qualname____doc__dictr$   __classcell__r&   s   @r'   ToolSelectedr   1   s    6	d 	t 	 	r(   r0   c                 d    t        |   |i | | j                          | j                          y r"   )r#   r$   _initialize_components_setup_github_repo)r%   argskwargsr&   s      r'   r$   z!AtomicToolExplorerScreen.__init__8   s-    $)&)##%!r(   c                     t        dd      | _        t        dd      | _        t        | j                        | _        t               | _        t               | _	        d | _
        d | _        y )NzAtomic Tool Explorertitle)id zcurrent-tool)item_renderer)r   title_widgetcurrent_tool_widgetr   _render_tool_item	tool_listr   footerr   atomic_tool_managercurrent_toolhighlighted_toolr%   s    r'   r2   z/AtomicToolExplorerScreen._initialize_components=   sW    "#9gF#)"#@ $43I3IJh#4#6   $r(   c                     t        t        t              | _        	 | j                  j	                          t        j                  d       y # t        $ r8}t        j                  d|        | j                  d| d       Y d }~y d }~ww xY w)N)branchzRepository cloned successfullyzFailed to clone repository: error)severity)
r   r   r   github_repo_clonerclonelogginginfo	ExceptionrF   notify)r%   es     r'   r3   z+AtomicToolExplorerScreen._setup_github_repoF   sw    "2?="Y	N##))+LL9: 	NMM8<=KK6qc:WKMM	Ns   /A 	B.BBr    c              #   |   K   | j                    | j                   | j                   | j                   y wr"   )r;   r<   r>   r?   rC   s    r'   composez AtomicToolExplorerScreen.composeO   s2     &&&nnkks   :<Nc                 \    | j                          t        j                         d   | _        y )N)refresh_tool_listr   splitborder_colorrC   s    r'   on_screen_resumez)AtomicToolExplorerScreen.on_screen_resumeU   s$     (..04r(   c                 8    | j                   j                          y r"   )rH   cleanuprC   s    r'   
on_unmountz#AtomicToolExplorerScreen.on_unmountY   s    '')r(   c                     | j                   j                  | j                  j                        }| j                  j                  |       y r"   )r@   get_atomic_toolsrH   
tools_pathr>   update_list)r%   toolss     r'   rS   z*AtomicToolExplorerScreen.refresh_tool_list\   s6    ((99$:Q:Q:\:\]""5)r(   toolc                     d|d    S )Nu   🔧 name r%   r_   s     r'   r=   z*AtomicToolExplorerScreen._render_tool_item`   s    tF|n%%r(   eventc                 &    |j                   | _        y r"   )itemrB   r%   rd   s     r'   handle_tool_highlightedz0AtomicToolExplorerScreen.handle_tool_highlightedc   s     %

r(   c                     |j                   | _        t        j                  d| j                  d           | j	                  | j                  | j                               | j                          y )NzTool selected: ra   )rf   rA   rJ   rK   post_messager0   !_open_file_explorer_for_directoryrg   s     r'   handle_tool_selectedz-AtomicToolExplorerScreen.handle_tool_selectedg   sX    !JJt'8'8'@&ABC$++D,=,=>?..0r(   c                     t        j                  d       | j                  j                  t	        t
        j                  | j                               y )Nz,Opening FileExplorerScreen in directory mode)modecallback)rJ   rK   apppush_screenr   r   DIRECTORY_MODEhandle_directory_selectionrC   s    r'   rk   z:AtomicToolExplorerScreen._open_file_explorer_for_directoryn   s6    CD/T5H5HSWSrSrstr(   selected_dirc                     t        j                  d|        | j                  r|r| j                  |       y t        j                  d       | j                  d       y )NzDirectory selected: z'No tool selected or no directory chosen)rJ   rK   rA   _copy_tool_to_directorywarningrM   )r%   rt   s     r'   rs   z3AtomicToolExplorerScreen.handle_directory_selectionr   sI    +L>:;((6OOEFKKABr(   c                    	 | j                   j                  | j                  d   |      }t        j                  d|        t        d| dd d      }| j                  j                  |       y # t        $ rJ}t        j                  dt        |       d	
       | j                  dt        |              Y d }~y d }~ww xY w)NpathzTool successfully copied to zTool copied to z. Press any key to continue.c                      y r"   rb   )_s    r'   <lambda>zBAtomicToolExplorerScreen._copy_tool_to_directory.<locals>.<lambda>   s    r(   continue)ro   rn   zError copying tool: T)exc_info)r@   copy_atomic_toolrA   rJ   rK   r   rp   rq   rL   rF   strrM   )r%   rt   local_tool_pathmodalrN   s        r'   rv   z0AtomicToolExplorerScreen._copy_tool_to_directoryz   s    	9"66GGHYHYZ`HacopOLL77HIJ%!/!22NO'E
 HH  ' 	9MM0Q9DIKK.s1vh788	9s   A/A2 2	C;A C  Cc                     | j                   r]| j                   j                  }| j                  j                  |d         }| j                  j                  t        |d   |             y | j                  dd       y )Nry   ra   zNo tool highlighted.Warning)r7   )rB   	item_datar@   read_readmerp   rq   r   rM   )r%   	tool_datareadme_contents      r'   action_show_tool_infoz.AtomicToolExplorerScreen.action_show_tool_info   sf      --77I!55AA)FBSTNHH  	&0A>!RSKK.iK@r(   c           	          |r1| j                   j                  dt         d|d    dt         d       y | j                   j                  d       y )NzCurrent tool: [bold ]ra   z[/bold r9   )r<   updater   rc   s     r'   update_current_toolz,AtomicToolExplorerScreen.update_current_tool   sP    $$++.B=/QRSWX^S_R``ghugvvw,xy$$++B/r(   c                 X    |j                   dk(  r| j                  j                          y y )Nr   )keyrp   
pop_screenrg   s     r'   on_keyzAtomicToolExplorerScreen.on_key   s#    99 HH! !r(   )r    N)#r)   r*   r+   r,   r   CSSr   BINDINGSr   r0   r$   r2   r3   r   rP   rV   rY   rS   r-   r   r=   r	   r   Highlightedrh   ItemSelectedrl   rk   r
   rs   rv   r   r   r   r.   r/   s   @r'   r   r      s#   < %o 
&C0 	*F>%{3H
w "
%N 5**&d &s &  +[-D-D + + !+   !1+*B*B 1 "1uCt C9D 9A0 0"r(   r   )"textual.appr   textual.widgetsr   r   textual.bindingr   textual.screenr   textual.messager   textualr	   pathlibr
   rJ   atomic_assembler.constantsr   r   r   r   r   &atomic_assembler.screens.file_explorerr   atomic_assembler.utilsr   r   %atomic_assembler.widgets.generic_listr   )atomic_assembler.screens.tool_info_screenr   +atomic_assembler.widgets.confirmation_modalr   r   rb   r(   r'   <module>r      s@    % * # ! #    h h E F = D IF"v F"r(   