a
    AdB                     @   sb   d dl Zd dlmZmZmZmZ dZdZdd Z	dd Z
d	d
 Zdd Zdd ZG dd dZdS )    N)shared	ui_commonui_componentsstylesu   🖌️u   📋c                 C   s^   t jj| }|d u}|  }|r&|jnt }|r8|jnt }||tj|dtj| dfS )Nvisible)r   prompt_stylesr   getpromptgrupdatenegative_prompt)namestyleexistingemptyr
   r    r   @/var/www/html/stable-diffusion-webui/modules/ui_prompt_styles.pyselect_style	   s    r   c                 C   sF   | st jddS t| ||}|tjj|j< tjtj t jddS )NFr   T)	r   r   r   PromptStyler   r   r   save_stylesstyles_filename)r   r
   r   r   r   r   r   
save_style   s    r   c                 C   s.   | dkrd S t jj| d  t jt j dS )N )r   r   r   )r   r   r   popr   r   )r   r   r   r   delete_style   s
    r   c                 C   sD   t j| |} t j||}tjj| dtjj|dtjjg dgS )N)value)r   r   apply_styles_to_promptapply_negative_styles_to_promptr   Textboxr   Dropdown)r
   r   r   r   r   r   materialize_styles)   s    r!   c                   C   s(   t jttjjdt jttjjdfS )N)choices)r   r   listr   r   r   r   r   r   r   refresh_styles0   s    r$   c                   @   s   e Zd Zdd ZdS )UiPromptStylesc              
   C   s$  || _ tj| ddN tjdd| dttjjg ddd| _t	j
t| dd	d
}W d    n1 sl0    Y  tj| ddd}t v tjd| dttjjg ddd| _t| j| jgtjjdd d| d t	j
t| ddd
| _W d    n1 s0    Y  t * tjdd| ddd| _W d    n1 sX0    Y  t * tjdd| ddd| _W d    n1 s0    Y  t \ tjdd| ddd| _tjd d| d!dd| _tjd"d#| d$d%| _W d    n1 s0    Y  W d    n1 s20    Y  | jjt| jg| j| j| j| jgdd& | jjt| j| j| jg| jgdd&jt| j| jgdd' | jjt d(| jg| j| j| jgdd)jt| j| jgdd' | jjt!||| jg||| jgdd&jd d*| d+ dd, tj"||| jd- d S ).NZ_styles_row)elem_idZStylesF_stylesT)label
show_labelr&   r"   r   multiselecttooltipZ_styles_edit_buttonzEdit styles)r   r&   r+   Z_styles_dialogzpopup-dialog)r&   elem_classesZ_styles_edit_selectzStyles allow you to add custom text to prompt. Use the {prompt} token in style text, and it will be replaced with user's prompt when applying style. Otherwise, style's text will be added to the end of the prompt.)r(   r&   r"   r   allow_custom_valueinfoc                   S   s   dt tjjiS )Nr"   )r#   r   r   r   r   r   r   r   <lambda>?       z)UiPromptStyles.__init__.<locals>.<lambda>refresh_Z_style_applyzTApply all selected styles from the style selction dropdown in main UI to the prompt.PromptZ_edit_style_prompt   )r(   r)   r&   lineszNegative promptZ_edit_style_neg_promptSaveprimaryZ_edit_style_save)variantr&   r   DeleteZ_edit_style_deleteClose	secondaryZ_edit_style_close)r7   r&   )fninputsoutputsshow_progress)r=   r>   zefunction(name){ if(name == "") return ""; return confirm("Delete style " + name + "?") ? name : ""; })r;   _jsr<   r=   r>   zfunction(){update_z_tokens(); closePopup();})r;   r?   r>   )button_showdialogbutton_close)#tabnamer   Rowr    r#   r   r   r   dropdownr   
ToolButtonstyles_edit_symbolBox	selectionr   create_refresh_buttonreloadstyles_materialize_symbolmaterializer   r
   Z
neg_promptButtonsavedeleteclosechanger   clickr   thenr$   r   r!   setup_dialog)selfrC   Zmain_ui_promptZmain_ui_negative_promptZedit_buttonZstyles_dialogr   r   r   __init__5   sb    (4
&(8
:
:
X

zUiPromptStyles.__init__N)__name__
__module____qualname__rW   r   r   r   r   r%   4   s   r%   )gradior   modulesr   r   r   r   rG   rL   r   r   r   r!   r$   r%   r   r   r   r   <module>   s   
