File Viewer

Download
a

�<�en�@s�ddlmZddlmZddlmZddlmZmZm	Z	ddl
mZmZm
Z
mZmZddlmZdd	lmZGd
d�de�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)�)�ASSETS_PATH)�download_image�)�Node)�Line�	Rectangle�UnknownElement)�Button�Text�Image�	TextEntry�ButtonHover�)�Template)�PathcsVeZdZd�fdd�	Zdd�Zedd��Zed�d	d
�Ze	d�dd�Z
d
d�Z�ZS)�Framercs�t��|����\�_�_����_i�_|�_|�_	|t
d|���_�j	jddd��jjddd��fdd��j
D��_dS)N�frameT)�parents�exist_okcs g|]}t|�jr��|��qS�)rZvisible�create_element)�.0�child��selfr�I/Users/pranavzagade/PycharmProjects/LuciaVision/tkdesigner/figma/frame.py�
<listcomp>s
�z"Frame.__init__.<locals>.<listcomp>)�super�__init__�size�width�height�colorZbg_color�counter�
figma_file�output_pathr�assets_path�mkdir�children�elements)r�noder$r%Z
frameCount��	__class__rrr
s

�zFrame.__init__cCs�|d����}|d����}td|�d|�d��|dkr�|j�td�d|jt<|d	}|j�|�}|jd
|jt�d�}t	||�|�
|j�}t||||jt�d�S|d
k�r |j�td�d|jt<|d	}|j�|�}|jd|jt�d�}t	||�|�
|j�}t|||�S|dv�r�|j�td�d|jt<|d	}|j�|�}|jd|jt�d�}t	||�|�
|j�}t||||jt�d�S|dk�r|j�t
d�d|jt
<|d	}|j�|�}|jd|jt
�d�}t	||�|�
|j�}t
||||jt
�d�S|dk�s,|dk�r6t||�S|dk�sJ|dk�rTt||�S|dk�rht||�Std|�d��t||�SdS)N�name�typezCreating Element { name: z, type: z }�buttonrr�idZbutton_z.png)Zid_ZbuttonhoverZ
button_hover_)ZtextboxZtextareaZentry_�imageZimage_�	rectangle�line�textzElement with the name: `z9` cannot be parsed. Would be displayed as Black Rectangle)�strip�lower�printr#�getr	r$�	get_imager&r�relative_tor
rrrrr
r)r�elementZelement_nameZelement_type�item_idZ	image_urlZ
image_pathrrrr#s|����
�
�
�
�
�

�




�zFrame.create_elementcCs|j�d�S)Nr(�r*r8rrrrr(sszFrame.children��returncs`zF|jddd��fdd�dD�^}}}}d|d�|d�|d��WStyZYd	S0d
S)z4Returns HEX form of element RGB color (str)
        Zfillsrr"cs g|]}t��|d�d��qS)r�)�intr8)r�i�r"rrr}�zFrame.color.<locals>.<listcomp>Zrgba�#Z02Xz#FFFFFFN)r*�	Exception)r�r�g�b�_rrCrr"xszFrame.colorcCs*|jd}|d}|d}t|�t|�fS)zCReturns element dimensions as width (int) and height (int)
        ZabsoluteBoundingBoxr r!)r*rA)r�bboxr r!rrrr�s
z
Frame.sizecCst|�}|j||j|jd�S)N)�windowr)r&)rZrenderr)r&)r�template�trrr�to_code�s
�z
Frame.to_code)r)
�__name__�
__module__�__qualname__rr�propertyr(�strr"�tuplerrO�
__classcell__rrr+rrsP

rcseZdZ�fdd�Z�ZS)�Groupcst��|�dS�N�rr�rr*r+rrr�szGroup.__init__�rPrQrRrrVrrr+rrW�srWcseZdZ�fdd�Z�ZS)�	Componentcst��|�dSrXrYrZr+rrr�szComponent.__init__r[rrr+rr\�sr\cseZdZ�fdd�Z�ZS)�ComponentSetcst��|�dSrXrYrZr+rrr�szComponentSet.__init__r[rrr+rr]�sr]cs.eZdZ�fdd�Zeed�dd��Z�ZS)�Instancecst��|�dSrXrYrZr+rrr�szInstance.__init__r>cCs|j�d�dS)NZcomponentIdr=rrrr�component_id�szInstance.component_id)rPrQrRrrSrTr_rVrrr+rr^�sr^N)�	constantsr�utilsrr*rZvector_elementsrrrZcustom_elementsr	r
rrr
Zjinja2r�pathlibrrrWr\r]r^rrrr�<module>s