B
    £ �a^  ã               @   sj   d dl mZ d dlmZmZmZ G dd„ deeƒƒZ	G dd„ dƒZG dd„ deƒZ
G d	d
„ d
ƒZeƒ ZdS )é    )Úwraps)ÚQObjectÚPropertyÚSignalc                   s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚPropertyMetaz-Lets a class succinctly define Qt properties.c       	         s‚   xnt | ¡ ƒD ]^}|| }t|tƒs&qt dtdi}| |j|j¡}t|ƒ}||d|› d�< t|||d�||< qW t	ƒ  
| |||¡S )NZQVariantListZQVariantMapÚ_Ú_changed)Útype_ÚnameÚnotify)ÚlistÚkeysÚ
isinstancer   ÚdictÚgetr	   Ú
pyqtSignalÚPropertyImplÚsuperÚ__new__)	Úclsr
   ÚbasesZattrsÚkeyÚattrÚtypesr	   Znotifier)Ú	__class__© ú/home/debian/UI/properties.pyr      s    
zPropertyMeta.__new__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   )r   r   r   	   s   r   c               @   s   e Zd ZdZdd„ ZdS )r   z‰Property definition.

    Instances of this class will be replaced with their full
    implementation by the PropertyMeta metaclass.
    c             C   s
   || _ d S )N)r	   )Úselfr	   r   r   r   Ú__init__!   s    zProperty.__init__N)r   r   r   r    r#   r   r   r   r   r      s   r   c                   s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )r   z<Property implementation: gets, sets, and notifies of change.c                s"   t ƒ j|| j| j|d� || _d S )N)r   )r   r#   ÚgetterÚsetterr
   )r"   r	   r
   r   )r   r   r   r#   '   s    zPropertyImpl.__init__c             C   s   t |d| j› �ƒS )Nr   )Úgetattrr
   )r"   Úinstancer   r   r   r$   +   s    zPropertyImpl.getterc             C   sP   t |d| j› d�ƒ}t|ƒtthkr.t||ƒ}t|d| j› �|ƒ | |¡ d S )Nr   r   )r&   r
   Útyper   r   Úmake_notifiedÚsetattrÚemit)r"   r'   ÚvalueÚsignalr   r   r   r%   /   s
    
zPropertyImpl.setter)r   r   r   r    r#   r$   r%   r!   r   r   )r   r   r   %   s   r   c               @   sj   e Zd ZdZedddddddd	d
ddgeddddd	dddgiZdd„ Zdd„ Ze	dd„ ƒZ
edd„ ƒZdS )ÚMakeNotifiedzvAdds notifying signals to lists and dictionaries.

    Creates the modified classes just once, on initialization.
    Ú__delitem__Ú__iadd__Ú__imul__Ú__setitem__ÚappendÚextendÚinsertÚpopÚremoveÚreverseÚsortÚ__ior__ÚclearÚpopitemÚ
setdefaultÚupdatec                s6   t tdƒsˆ jt  d¡ ‡ fdd„ttgD ƒˆ _d S )Nr:   c                s   i | ]}ˆ   |¡|“qS r   )Úmake_notified_class)Ú.0r	   )r"   r   r   ú
<dictcomp>K   s   z)MakeNotified.__init__.<locals>.<dictcomp>)Úhasattrr   Úchange_methodsr7   r   Únotified_class)r"   r   )r"   r   r#   G   s    

zMakeNotified.__init__c             C   s    | j t|ƒ }||ƒ}||_|S )z9Returns a notifying version of the supplied list or dict.)rD   r(   r-   )r"   Úseqr-   rD   Znotified_seqr   r   r   Ú__call__N   s    zMakeNotified.__call__c             C   sP   t d|j› �|fi ƒ}x4| j| D ]&}t||ƒ}|  ||¡}t|||ƒ q"W |S )NZ	notified_)r(   r   rC   r&   Úmake_notified_methodr*   )r   ÚparentrD   Zmethod_nameZoriginalÚnotified_methodr   r   r   r?   U   s    
z MakeNotified.make_notified_classc                s   t ˆ ƒ‡ ‡fdd„ƒ}|S )Nc                s(   t ˆˆ jƒ| f|ž|Ž}| j | ¡ |S )N)r&   r   r-   r+   )r"   ÚargsÚkwargsÚresult)ÚmethodrH   r   r   rI   `   s    z:MakeNotified.make_notified_method.<locals>.notified_method)r   )rM   rH   rI   r   )rM   rH   r   rG   ^   s    z!MakeNotified.make_notified_methodN)r   r   r   r    r   r   rC   r#   rF   Úclassmethodr?   ÚstaticmethodrG   r   r   r   r   r.   ;   s   	r.   N)Ú	functoolsr   ÚPySide2.QtCorer   r   ZpyqtPropertyr   r   r(   r   r   r.   r)   r   r   r   r   Ú<module>   s   
-