o
    i'                     @  s  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	 e
 ZG dd dejZG dd	 d	ejZG d
d dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd deZdddZdS )    )annotations)	TypedDict)override)ComfyExtensionio)_ioc                   @  s4   e Zd Zedd Zed
ddZeddd	ZdS )
SwitchNodec                 C  sZ   t jd}t jddddt jdt jjd|ddt jjd|ddgt jj|d	d
gdS )NswitchComfySwitchNodeSwitchlogicTon_false)templatelazyon_trueoutputr   display_namenode_idr   categoryis_experimentalinputsoutputsr   	MatchTypeTemplateSchemaBooleanInputOutputclsr    r#   6/mnt/c/Users/fbmor/ComfyUI/comfy_extras/nodes_logic.pydefine_schema   s   
zSwitchNode.define_schemaNc                 C  s,   |r	|d u r	dgS |s|d u rdgS d S d S Nr   r   r#   r"   r	   r   r   r#   r#   r$   check_lazy_status   s
   zSwitchNode.check_lazy_statusreturnio.NodeOutputc                 C  s   t |r|S |S Nr   
NodeOutputr"   r	   r   r   r#   r#   r$   execute%   s   zSwitchNode.execute)NNr)   r*   )__name__
__module____qualname__classmethodr%   r(   r/   r#   r#   r#   r$   r      s    
r   c                   @  sP   e Zd Zedd ZeeefddZeeefddZeeefdd	d
ZdS )SoftSwitchNodec                 C  s^   t jd}t jddddt jdt jjd|dddt jjd|dddgt jj|d	d
gdS )Nr	   ComfySoftSwitchNodezSoft Switchr   Tr   )r   r   optionalr   r   r   r   r   r!   r#   r#   r$   r%   +   s   
zSoftSwitchNode.define_schemac                 C  sH   |t u rdgS |t u rdgS |r|d u rdgS |s |d u r"dgS d S d S r&   MISSINGr'   r#   r#   r$   r(   =   s   z SoftSwitchNode.check_lazy_statusc                 C  s   |t u r
|t u r
dS dS )NzDAt least one of on_false or on_true must be connected to Switch nodeTr8   r'   r#   r#   r$   validate_inputsM   s   zSoftSwitchNode.validate_inputsr)   r*   c                 C  s8   |t u r	t|S |t u rt|S t|r|S |S r+   )r9   r   r-   r.   r#   r#   r$   r/   U   s
   

zSoftSwitchNode.executeNr0   )	r1   r2   r3   r4   r%   r9   r(   r:   r/   r#   r#   r#   r$   r5   *   s    
r5   c                   @  s<   e Zd ZdZedd ZeddddZeddddZdS )CustomComboNodez
    Frontend node that allows user to write their own options for a combo.
    This is here to make sure the node has a backend-representation to avoid some annoyances.
    c              
   C  s>   t jddddt jjdg dgt jjddt jjd	dgdd
S )NCustomCombozCustom ComboutilsTchoiceoptionsSTRING)r   INDEX)r   r   r   r   r   r   accept_all_inputs)r   r   Combor   Stringr    Intr"   r#   r#   r$   r%   c   s   zCustomComboNode.define_schemar   r>   io.Combo.Typeindexintr)   boolc                 K  s   dS )NTr#   r"   r>   rI   kwargsr#   r#   r$   r:   r   s   zCustomComboNode.validate_inputsr*   c                 K     t ||S r+   r,   rL   r#   r#   r$   r/   y      zCustomComboNode.executeN)r   )r>   rH   rI   rJ   r)   rK   )r>   rH   rI   rJ   r)   r*   )r1   r2   r3   __doc__r4   r%   r:   r/   r#   r#   r#   r$   r;   ^   s    
r;   c                   @  s6   e Zd ZG dd deZedd Zeddd	Zd
S )
DCTestNodec                   @  s6   e Zd ZU ded< ded< ded< ded< ded	< d
S )zDCTestNode.DCValuesstrcombostringrJ   integerzio.Image.Typeimagez	dict[str]subcomboN)r1   r2   r3   __annotations__r#   r#   r#   r$   DCValues   s   
 rY   c                 C  s   t jddddt jjdt jdt jdgt jdt jd	gt jd
t jdgt jdt jjdt jdt jdt jdgt jdt j	jdddggdggdgt j
 gdS )NrQ   DCTestr   TrS   option1rT   option2rU   option3rV   option4rW   opt1float_xfloat_yopt2mask1)r7   r?   )r   r   r   is_output_noder   r   )r   r   DynamicCombor   OptionrE   rF   ImageFloatMaskAnyTyper    rG   r#   r#   r$   r%      s$    
zDCTestNode.define_schemarS   r)   r*   c                 C  sp   |d }|dkrt |d S |dkrt |d S |dkr%t |d S |dkr1t |d	  S td
| )NrS   r[   rT   r\   rU   r]   rV   r^   rW   zInvalid combo: )r   r-   
ValueError)r"   rS   	combo_valr#   r#   r$   r/      s   zDCTestNode.executeN)rS   rY   r)   r*   )r1   r2   r3   r   rY   r4   r%   r/   r#   r#   r#   r$   rQ   ~   s    
rQ   c                   @  &   e Zd Zedd Zed
ddZd	S )AutogrowNamesTestNodec                 C  sF   t jjtjdg dd}tjdddt jjd|dgtj gd	S )
Nfloat)abc)inputnamesrn   AutogrowNamesTestr   autogrowr   r   r   r   r   r   )	r   AutogrowTemplateNamesr   rh   r   r   rE   r    r!   r#   r#   r$   r%         
z#AutogrowNamesTestNode.define_schemarv   _io.Autogrow.Typer)   r*   c                 C  *   t | }ddd |D }t|S )N,c                 S     g | ]}t |qS r#   rR   .0xr#   r#   r$   
<listcomp>       z1AutogrowNamesTestNode.execute.<locals>.<listcomp>listvaluesjoinr   r-   r"   rv   valscombinedr#   r#   r$   r/         
zAutogrowNamesTestNode.executeNrv   r|   r)   r*   r1   r2   r3   r4   r%   r/   r#   r#   r#   r$   rn      
    
rn   c                   @  rm   )AutogrowPrefixTestNodec                 C  sF   t jjtjddddd}tjdddt jjd|d	gtj gd
S )Nro      
   )rs   prefixminmaxr   AutogrowPrefixTestr   rv   rw   rx   )	r   ry   TemplatePrefixr   rh   r   r   rE   r    r!   r#   r#   r$   r%      r{   z$AutogrowPrefixTestNode.define_schemarv   r|   r)   r*   c                 C  r}   )Nr~   c                 S  r   r#   r   r   r#   r#   r$   r      r   z2AutogrowPrefixTestNode.execute.<locals>.<listcomp>r   r   r#   r#   r$   r/      r   zAutogrowPrefixTestNode.executeNr   r   r#   r#   r#   r$   r      r   r   c                   @  s&   e Zd Zedd Zeddd	Zd
S )ComboOutputTestNodec              	   C  sH   t jdddt jjdg ddt jjdg ddgt j t j gd	S )
NComboOptionTestNodeComboOptionTestr   rS   )r[   r\   r]   r?   combo2)r^   option5option6rx   )r   r   rD   r   r    rG   r#   r#   r$   r%      s   z!ComboOutputTestNode.define_schemarS   rH   r   r)   r*   c                 C  rN   r+   r,   )r"   rS   r   r#   r#   r$   r/      rO   zComboOutputTestNode.executeN)rS   rH   r   rH   r)   r*   r   r#   r#   r#   r$   r      
    

r   c                   @  rm   )ConvertStringToComboNodec                 C  s,   t jdddgddt jdgt j gdS )Nr   zstring to dropdownztext to combozConvert String to Combor   rT   r   search_aliasesr   r   r   r   )r   r   rE   r   rD   r    rG   r#   r#   r$   r%         
z&ConvertStringToComboNode.define_schemarT   rR   r)   r*   c                 C  s
   t |S r+   r,   )r"   rT   r#   r#   r$   r/      s   
z ConvertStringToComboNode.executeN)rT   rR   r)   r*   r   r#   r#   r#   r$   r      r   r   c                   @  rm   )InvertBooleanNodec                 C  s,   t jdg dddt jdgt j gdS )Nr   )nottogglenegatezflip booleanzInvert Booleanr   booleanr   )r   r   r   r   r    rG   r#   r#   r$   r%      r   zInvertBooleanNode.define_schemar   rK   r)   r*   c                 C  s   t | S r+   r,   )r"   r   r#   r#   r$   r/      rO   zInvertBooleanNode.executeN)r   rK   r)   r*   r   r#   r#   r#   r$   r      r   r   c                   @  s   e Zd ZedddZdS )LogicExtensionr)   list[type[io.ComfyNode]]c                   s
   t tgS r+   )r   r;   )selfr#   r#   r$   get_node_list  s   zLogicExtension.get_node_listN)r)   r   )r1   r2   r3   r   r   r#   r#   r#   r$   r     s    r   r)   c                     s   t  S r+   )r   r#   r#   r#   r$   comfy_entrypoint  s   r   N)r)   r   )
__future__r   typingr   typing_extensionsr   comfy_api.latestr   r   r   objectr9   	ComfyNoder   r5   r;   rQ   rn   r   r   r   r   r   r   r#   r#   r#   r$   <module>   s"    4 ,