
    lj              
         d Z ddlmZ ddlZddlmZ ddlmZ ddlZddl	Z	ddl
mZ ddlmZmZmZ ddlmZmZmZmZ d	d
ddddZg dZd1dZd2dZ e	j        ee           e	j        d e	j        e          d           e	j        ddd d!d"d#          d3d'                                    Z e	j        ed!e(           e	j        d)ed!           e	j        d*ed          d4d+                                    Z e	j        ed!d!ed,-          e	j         d5d0                        Z!e!"                    e           e!"                    e           dS )6zManim's init subcommand.

Manim's init subcommand is accessed in the command-line interface via ``manim
init``. Here you can specify options, subcommands, and subgroups for the init
group.

    )annotationsN)Path)Any)console)CONTEXT_SETTINGSEPILOG	QUALITIES)add_import_statementcopy_template_filesget_template_namesget_template_path   BLACK   Default)i  i8  )
frame_ratebackground_colorbackground_opacityscene_names
resolution)select_resolution
update_cfgprojectscenereturntuple[int, int]c                     d t          j                    D             } |                                  t          j        dt          j        d | D                       dd          fd| D             }|d         S )	zPrompts input of type click.Choice from user. Presents options from QUALITIES constant.

    Returns
    -------
    tuple[int, int]
        Tuple containing height and width.
    c                F    g | ]}|d          d         |d          d         fS )r   pixel_heightpixel_width ).0qualitys     R/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/cli/init/commands.py
<listcomp>z%select_resolution.<locals>.<listcomp>.   s?     1 1 1 
N	#WQZ%>?1 1 1    z
Select resolution:
c                $    g | ]}|d           dS r   pr!   )r"   is     r$   r%   z%select_resolution.<locals>.<listcomp>5   s"    BBB!ad:::BBBr&   F480p)typeshow_defaultdefaultc                2    g | ]}|d           dk    |S r(   r!   )r"   reschoices     r$   r%   z%select_resolution.<locals>.<listcomp>9   s-    KKKss1vLLLF4J4Js4J4J4Jr&   r   )r	   itemspopclickpromptcloupChoice)resolution_optionsmatchesr1   s     @r$   r   r   &   s    1 1 ((1 1 1 \ \BB/ABBBCC	  F LKKK0KKKG1:r&   cfg_dictdict[str, Any]project_cfg_pathr   Nonec                   t          j                    }|                    |           |d         }|                                 D ]N\  }}|dk    r1t	          |d                   |d<   t	          |d                   |d<   <t	          |          ||<   O|                    d          5 }|                    |           ddd           dS # 1 swxY w Y   dS )	a%  Update the ``manim.cfg`` file after reading it from the specified
    ``project_cfg_path``.

    Parameters
    ----------
    cfg_dict
        Values used to update ``manim.cfg`` which is found in
        ``project_cfg_path``.
    project_cfg_path
        Path of the ``manim.cfg`` file.
    CLIr   r   r   r   r    wN)configparserConfigParserreadr2   stropenwrite)r:   r<   config
cli_configkeyvalueconfs          r$   r   r   =   s    &((F
KK !!!Jnn&& ) )
U,),U1XJ~&(+E!HJ}%%!%jjJsOO			s	#	# tT                 s   )CCC)context_settingsepilogproject_name)	path_typeF)r,   requiredz-dz	--defaultdefault_settingsTz&Default settings for project creation.)is_flaghelpnargsboolkwargsr   c                2   |d         r	|d         }nt          j        dt                    }t          j        dt          j        t	                      d          d          }|                                rt          j        d| d	           dS |                                 i }t          j	        |d
z            }| st                                          D ]H\  }}|dk    r	|dz   ||<   |dk    rt                      ||<   ,t          j        d| |          ||<   It          j        d|           t          j        ddd          r"t          ||           t          ||           dS dS t          ||           t          t          |           dS )zuCreates a new project.

    PROJECT_NAME is the name of the folder in which the new project will be initialized.
    rN   zProject Name)r,   TemplateFr   r,   r.   z
Folder [red]z([/red] exists. Please type another name
z	manim.cfgr   r   
)r.   zDo you want to continue?T)r.   abortN)r4   r5   r   r7   r   is_dirr   printmkdirresolveCFG_DEFAULTSr2   r   confirmr   r   )rQ   rV   rN   template_namenew_cfgnew_cfg_pathrI   rJ   s           r$   r   r   W   s   & n ?n-|N>>> L\,..66  M  3T\TTT	
 	
 	
 	
 	
 	"$|L;$>?? 	3*0022 K K
U-''#0:#=GCLLL((#4#6#6GCLL#(<
S

E#J#J#JGCLLM$(((}7TRRR 2#L-@@@7L111112 2  m<<<|\22222r&   )rL   no_args_is_helprM   
scene_name	file_namec                 \   t          j        dt          j        t                      d          d          }t	                      | dz                                                                  }|                    |dz   | d         d          }| d	         rt          | d	                   }|j	        d
k    r|
                    |j	        d
z             }|                                rH|                    d          5 }|                    d|z              ddd           dS # 1 swxY w Y   dS |                    d|z              t          |           dS t          d                              d          5 }|                    d|z              ddd           dS # 1 swxY w Y   dS )zInserts a SCENE to an existing FILE or creates a new FILE.

    SCENE is the name of the scene that will be inserted.

    FILE is the name of file in which the SCENE will be inserted.
    templateFr   rY   z.mtprX   rf   r   rg   z.pyaz


Nzmain.py)r4   r5   r7   r   r   r_   	read_textreplacer   suffixwith_suffixis_filerE   rF   
write_textr
   )rV   rb   r   rg   fs        r$   r   r      s1    \,..66  M
   m#9#9#99BBDDNNPPEMM-*4f\6JANNEk &,--	u$$!--i.>.FGGI 	,$$ *5()))* * * * * * * * * * * * * * * * * *   E!1222 +++++ )__!!#&& 	&!GGHu$%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s$   =D##D'*D';F!!F%(F%z+Create a new project or insert a new scene.)rL   invoke_without_commandre   rM   rS   ctxcloup.Contextc                    d S )Nr!   )rs   s    r$   initrv      s	     	Dr&   )r   r   )r:   r;   r<   r   r   r=   )rQ   rU   rV   r   r   r=   )rV   r   r   r=   )rs   rt   r   r=   )#__doc__
__future__r   rA   pathlibr   typingr   r4   r6   manim._configr   manim.constantsr   r   r	   manim.utils.file_opsr
   r   r   r   r`   __all__r   r   commandargumentoptionr   rD   r   grouppass_contextrv   add_commandr!   r&   r$   <module>r      s    # " " " " "                   ! ! ! ! ! ! ? ? ? ? ? ? ? ? ? ?              B
A
A   .   4 %   ZUZ$%?%?%?%PPP	1
  *3 *3 *3  QP	 *3Z %  
 3666#666"& "& "& 76 76 "&J %	6   	 	 	  	              r&   