B
    nôb\Ú   ã               @   sê   d Z ddlmZ ddlmZmZmZ ddlmZm	Z	m
Z
 ddlmZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ G d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZ G dd„ deƒZ!dd„ Z"e#dkræe"ƒ  dS )z
Helper widgets.
é    )ÚPYQT5)ÚQPointÚQSizeÚQt)ÚQAbstractTextDocumentLayoutÚQPainterÚQTextDocument)ÚQApplicationÚ	QCheckBoxÚ	QLineEditÚQMessageBoxÚQSpacerItemÚQStyleÚQStyledItemDelegateÚQStyleOptionViewItemÚQToolButtonÚQToolTipÚQVBoxLayout)Ú_)Úicon_manager)Úget_std_iconc               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚHelperToolButtonzFSubclasses QToolButton, to provide a simple tooltip on mousedown.
    c             C   s*   t  | ¡ |  tdƒ¡ d}|  |¡ d S )NZMessageBoxInformationa  
            QToolButton {
              border: 1px solid grey;
              padding:0px;
              border-radius: 2px;
              background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                  stop: 0 #f6f7fa, stop: 1 #dadbde);
            }
            )r   Ú__init__ÚsetIconr   ÚsetStyleSheet)ÚselfÚstyle© r   ú;lib/python3.7/site-packages/spyder/widgets/helperwidgets.pyr      s    
	zHelperToolButton.__init__c             C   s
   || _ d S )N)Ú	_tip_text)r   Útextr   r   r   Ú
setToolTip+   s    zHelperToolButton.setToolTipc             C   s   | j S )N)r   )r   r   r   r   ÚtoolTip.   s    zHelperToolButton.toolTipc             C   s   t  ¡  d S )N)r   ZhideText)r   Úeventr   r   r   ÚmousePressEvent1   s    z HelperToolButton.mousePressEventc             C   s"   t  |  td|  ¡ ƒ¡| j¡ d S )Nr   )r   ZshowTextZmapToGlobalr   Úheightr   )r   r#   r   r   r   ÚmouseReleaseEvent4   s    z"HelperToolButton.mouseReleaseEventN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r!   r"   r$   r&   r   r   r   r   r      s   r   c                   sP   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
‡  ZS )ÚMessageCheckBoxz†
    A QMessageBox derived widget that includes a QCheckBox aligned to the right
    under the message and on top of the buttons.
    c                s„   t t| ƒj||Ž tƒ | _d}tƒ }| t||ƒ¡ | | jdt	j
¡ | t||ƒ¡ |  ¡ }trr| |dd¡ n| |dd¡ d S )Né	   r   é   é   )Úsuperr+   r   r
   Ú	_checkboxr   ZaddItemr   Z	addWidgetr   Z
AlignRightÚlayoutr   Z	addLayout)r   ÚargsÚkwargsÚsizeZcheck_layoutr1   )Ú	__class__r   r   r   >   s    zMessageCheckBox.__init__c             C   s
   | j  ¡ S )N)r0   Z	isChecked)r   r   r   r   Ú
is_checkedS   s    zMessageCheckBox.is_checkedc             C   s   | j  |¡S )N)r0   Z
setChecked)r   Úvaluer   r   r   Úset_checkedV   s    zMessageCheckBox.set_checkedc             C   s   | j  |¡ d S )N)r0   Z
setVisible)r   r7   r   r   r   Úset_check_visibleY   s    z!MessageCheckBox.set_check_visiblec             C   s   | j  ¡  d S )N)r0   Z	isVisible)r   r   r   r   Úis_check_visible\   s    z MessageCheckBox.is_check_visiblec             C   s   | j  ¡  d S )N)r0   r    )r   r   r   r   Úcheckbox_text_   s    zMessageCheckBox.checkbox_textc             C   s   | j  |¡ d S )N)r0   ÚsetText)r   r    r   r   r   Úset_checkbox_textb   s    z!MessageCheckBox.set_checkbox_text)r'   r(   r)   r*   r   r6   r8   r9   r:   r;   r=   Ú__classcell__r   r   )r5   r   r+   9   s   r+   c                   s2   e Zd ZdZd	‡ fdd„	Zdd„ Zdd„ Z‡  ZS )
ÚHTMLDelegatez‡With this delegate, a QListWidgetItem or a QTableItem can render HTML.

    Taken from https://stackoverflow.com/a/5443112/2399799
    r   c                s   t t| ƒ |¡ || _d S )N)r/   r?   r   Ú_margin)r   ÚparentZmargin)r5   r   r   r   k   s    zHTMLDelegate.__init__c       	      C   s>  t |ƒ}|  ||¡ |jd kr&t ¡ n|j ¡ }tƒ }| | j¡ | |j	¡ d|_	| 
tj||¡ t ¡ }| tj|¡}| ¡  t|jdƒr
| ¡ dkrÎ|jjr¾| | ¡ tddƒ ¡ n| | ¡ ¡ n:|jjrð| | ¡ tddƒ ¡ n| | ¡ tddƒ ¡ n| | ¡ tddƒ ¡ | ¡  ||¡ | ¡  d S )	NÚ Ú
files_list)ÚoxygenZqtcurveZbreezeé   i÷ÿÿÿr.   r   éýÿÿÿ)r   ÚinitStyleOptionZwidgetr	   r   r   ZsetDocumentMarginr@   ÚsetHtmlr    ZdrawControlr   ZCE_ItemViewItemr   ZPaintContextZsubElementRectZSE_ItemViewItemTextZsaveÚhasattrÚ
objectNamerC   Ú	translateZtopLeftr   ZdocumentLayoutZdrawZrestore)	r   ÚpainterÚoptionÚindexÚoptionsr   ÚdocZctxZtextRectr   r   r   Úpainto   s.    
zHTMLDelegate.paintc             C   s@   t |ƒ}|  ||¡ tƒ }| |j¡ t| ¡ | ¡  ¡ d ƒS )Nr.   )	r   rG   r   rH   r    r   Z
idealWidthr4   r%   )r   rM   rN   rO   rP   r   r   r   ÚsizeHint“   s
    zHTMLDelegate.sizeHint)r   )r'   r(   r)   r*   r   rQ   rR   r>   r   r   )r5   r   r?   f   s   $r?   c                   sL   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Z‡ fdd„Z	‡  Z
S )ÚIconLineEditzCCustom QLineEdit that includes an icon representing the validation.c                sh   t t| ƒj||Ž d| _d| _t d¡| _t d¡| _t d¡| _	t
 ¡  ¡ | _|  ¡  d| _d| _d S )NTZtodoZwarningZ	todo_listr   F)r/   rS   r   Ú_statusÚ_status_setÚimaZiconÚ_valid_iconÚ_invalid_iconÚ	_set_iconr	   r   rJ   Ú_application_styleÚ_refreshÚ_paint_countÚ_icon_visible)r   r2   r3   )r5   r   r   r       s    zIconLineEdit.__init__c             C   sF   |   ¡ }d}d}| jdkr |}n|}|j|d}|  |¡ |  ¡  dS )ziAfter an application style change, the paintEvent updates the
        custom defined stylesheet.
        z°QLineEdit {{
                                 border: none;
                                 padding-right: {padding}px;
                                 }}
                   zÐQLineEdit {{background: transparent;
                                   border: none;
                                   padding-right: {padding}px;
                                   }}
                     rD   )ÚpaddingN)r%   rZ   Úformatr   Úupdate)r   r^   Zcss_baseZ
css_oxygenZcss_templateZcssr   r   r   r[   ­   s    

zIconLineEdit._refreshc             C   s   d| _ |  ¡  |  ¡  dS )zShow the status icon.FN)r]   Úrepaintr`   )r   r   r   r   Úhide_status_iconÅ   s    zIconLineEdit.hide_status_iconc             C   s   d| _ |  ¡  |  ¡  dS )zHide the status icon.TN)r]   ra   r`   )r   r   r   r   Úshow_status_iconË   s    zIconLineEdit.show_status_iconc             C   s    || _ || _|  ¡  |  ¡  dS )z@Update the status and set_status to update the icons to display.N)rT   rU   ra   r`   )r   r7   Z	value_setr   r   r   Úupdate_statusÑ   s    zIconLineEdit.update_statusc       	         sä   t t| ƒ |¡ t| ƒ}|  ¡ }t| ¡ d ƒ}| ¡ | }| ¡ | }| jrœ| j	rj| j
rj| j ||¡}n$| j	r€| j ||¡}n| j ||¡}| |||¡ t ¡  ¡ }| j|krÀ|| _|  ¡  | jdk rà|  jd7  _|  ¡  dS )zVQt Override.

        Include a validation icon to the left of the line edit.
        é   é   r-   N)r/   rS   Ú
paintEventr   ZgeometryÚintr%   Úwidthr]   rT   rU   rY   ÚpixmaprW   rX   Z
drawPixmapr	   r   rJ   rZ   r[   r\   )	r   r#   rL   ZrectZspaceÚhÚwrj   Zapplication_style)r5   r   r   rg   Ø   s(    

zIconLineEdit.paintEvent)r'   r(   r)   r*   r   r[   rb   rc   rd   rg   r>   r   r   )r5   r   rS      s   rS   c              C   sj   ddl m}  | ƒ }tƒ }| tdƒ¡ | d¡ | d¡ | tj	¡ | 
tj	¡ | tj¡ | ¡  d S )Nr   )ÚqapplicationzSpyder updateszTesting checkboxzCheck for updates on startup?)Úspyder.utils.qthelpersrm   r+   ZsetWindowTitler   r<   r=   ZsetStandardButtonsr   ZOkZsetDefaultButtonr   ZInformationZexec_)rm   ZappZboxr   r   r   Útest_msgcheckboxú   s    

ro   Ú__main__N)$r*   Zqtpyr   Zqtpy.QtCorer   r   r   Z
qtpy.QtGuir   r   r   Zqtpy.QtWidgetsr	   r
   r   r   r   r   r   r   r   r   r   Zspyder.config.baser   Zspyder.utilsr   rV   rn   r   r   r+   r?   rS   ro   r'   r   r   r   r   Ú<module>	   s   4-7]