
    Je6                        d Z ddlZddlZddlmZ ddlmZmZm	Z	m
Z
mZ ddlmZmZmZ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mZ ddl m!Z! ddl"m#Z# dd	l$m%Z% dd
l&m'Z' dZ(djS                  e(      Z* G d de      Z+ G d de      Z, G d de      Z- G d de      Z. G d de      Z/ G d de      Z0 G d de
      Z1d Z2e3dk(  r e2        yy)z
Helper widgets.
    N)PYQT5)QPointQRegExpQSizeQSortFilterProxyModelQt)QAbstractTextDocumentLayoutQColorQFontMetricsQPainterQRegExpValidatorQTextDocument)QApplication	QCheckBox	QLineEditQMessageBoxQSpacerItemQStyleQStyledItemDelegateQStyleOptionFrameQStyleOptionViewItemQToolButtonQToolTipQVBoxLayout)_)ima)get_search_regex)QStylePaletteuS   ÁÉÍOÚáéíúóàèìòùÀÈÌÒÙâêîôûÂÊÎÔÛäëïöüÄËÏÖÜñÑz[A-Za-z\s{0}]c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)HelperToolButtonzFSubclasses QToolButton, to provide a simple tooltip on mousedown.
    c                     t        j                  |        | j                  t        j                  d             d}| j                  |       y )NMessageBoxInformationzr
            QToolButton {
              padding:0px;
              border-radius: 2px;
            }
            )r   __init__setIconr   get_std_iconsetStyleSheet)selfstyles     >/usr/lib/python3/dist-packages/spyder/widgets/helperwidgets.pyr#   zHelperToolButton.__init__'   s?    T"S%%&=>? 	5!    c                     || _         y N	_tip_textr'   texts     r)   
setToolTipzHelperToolButton.setToolTip2   s	    r*   c                     | j                   S r,   r-   r'   s    r)   toolTipzHelperToolButton.toolTip5   s    ~~r*   c                 ,    t        j                          y r,   )r   hideTextr'   events     r)   mousePressEventz HelperToolButton.mousePressEvent8   s    r*   c           	          t        j                  | j                  t        d| j	                                     | j
                         y )Nr   )r   showTextmapToGlobalr   heightr.   r7   s     r)   mouseReleaseEventz"HelperToolButton.mouseReleaseEvent;   s1    $**6!T[[]+CD..	*r*   N)	__name__
__module____qualname____doc__r#   r1   r4   r9   r>    r*   r)   r    r    $   s     	"*r*   r    c                   F     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
 x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                    t        t        | 
  |i | | j                  t        j
                         t        |       | _        d}t               }|j                  t        ||             |j                  | j                  dt        j                         |j                  t        ||             | j                         }t        r|j                  |dd       y |j                  |dd       y )N	   r         )superrE   r#   setWindowModalityr   NonModalr   	_checkboxr   addItemr   	addWidget
AlignRightlayoutr   	addLayout)r'   argskwargssizecheck_layoutrQ   	__class__s         r)   r#   zMessageCheckBox.__init__E   s    ot-t>v>r{{+"4 "}[t45t~~q"--@[t45 \1a0\1a0r*   c                 6    | j                   j                         S r,   )rM   	isCheckedr3   s    r)   
is_checkedzMessageCheckBox.is_checked[   s    ~~''))r*   c                 8    | j                   j                  |      S r,   )rM   
setCheckedr'   values     r)   set_checkedzMessageCheckBox.set_checked^   s    ~~((//r*   c                 :    | j                   j                  |       y r,   )rM   
setVisibler]   s     r)   set_check_visiblez!MessageCheckBox.set_check_visiblea   s    !!%(r*   c                 8    | j                   j                          y r,   )rM   	isVisibler3   s    r)   is_check_visiblez MessageCheckBox.is_check_visibled   s      "r*   c                 8    | j                   j                          y r,   )rM   r0   r3   s    r)   checkbox_textzMessageCheckBox.checkbox_textg   s    r*   c                 :    | j                   j                  |       y r,   )rM   setTextr/   s     r)   set_checkbox_textz!MessageCheckBox.set_checkbox_textj   s    t$r*   )r?   r@   rA   rB   r#   rZ   r_   rb   re   rg   rj   __classcell__rW   s   @r)   rE   rE   @   s+    1,*0)#%r*   rE   c                   6     e Zd ZdZd fd	Zd Zd Zd Z xZS )HTMLDelegatezWith this delegate, a QListWidgetItem or a QTableItem can render HTML.

    Taken from https://stackoverflow.com/a/5443112/2399799
    c                 :    t         t        |   |       || _        y r,   )rJ   rn   r#   _margin)r'   parentmarginrW   s      r)   r#   zHTMLDelegate.__init__t   s    lD*62r*   c                     t        |      }| j                  ||       t               }|j                  | j                         |j                  |j                         ||fS r,   )r   initStyleOptionr   setDocumentMarginrp   setHtmlr0   r'   optionindexoptionsdocs        r)   _prepare_text_documentz#HTMLDelegate._prepare_text_documentx   sO    &v.We,odll+GLL!|r*   c                 f   | j                  ||      \  }}|j                  t        j                         n|j                  j                         }d|_        |j                  t        j                  |||j                         t        j                         }|j                  t        j                  |d       }|j                          t        |j                  d      r|j                         dv rc|j                  j                  r-|j!                  |j#                         t%        dd      z          n|j!                  |j#                                n|j                  j                  r-|j!                  |j#                         t%        dd      z          nY|j!                  |j#                         t%        dd      z          n,|j!                  |j#                         t%        dd      z          |j'                         }	t)        |	      t        u r|	j+                  ||       |j-                          y )	N 
files_list)oxygenqtcurvebreeze   irI   r   )r|   widgetr   r(   r0   drawControlr   CE_ItemViewItemr	   PaintContextsubElementRectSE_ItemViewItemTextsavehasattr
objectNamer   	translatetopLeftr   documentLayouttypedrawrestore)
r'   painterrx   ry   rz   r{   r(   ctxtextRect	docLayouts
             r)   paintzHTMLDelegate.paint   s   2265A)0)?##%nn**, 	 	&00'7!..	* *668''(B(B(/7 7>><0!%DD>>,,%%h&6&6&86!R=&HI%%h&6&6&89>>,,%%h&6&6&86!Q<&GH%%h&6&6&86!Q<&GHh..06!R=@A
 &&(		?99NN7C(r*   c                     | j                  ||      \  }}t        t        |j                               t        |j	                         j                         dz
              S )NrI   )r|   r   round
idealWidthrU   r=   )r'   rx   ry   __r{   s        r)   sizeHintzHTMLDelegate.sizeHint   sJ    --fe<CU3>>+,eCHHJ4E4E4G!4K.LMMr*   )r   )	r?   r@   rA   rB   r#   r|   r   r   rk   rl   s   @r)   rn   rn   n   s    
*XNr*   rn   c                       e Zd Zd Zd Zd Zy)ItemDelegatec                 0    t        j                  | |       y r,   )r   r#   )r'   rq   s     r)   r#   zItemDelegate.__init__   s    $$T62r*   c                    t        |      }| j                  ||       |j                  t        j                         n|j                  j	                         }t               }|j                  d       |j                  |j                         d|_        |j                  t        j                  ||       t        j                         }|j                  t        j                  |d       }|j!                          |j#                  |j%                                |j'                  |j)                  |j%                                       |j+                         j-                  ||       |j/                          y )Nr   r~   )r   rt   r   r   r(   r   ru   rv   r0   r   r   r   r	   r   r   r   r   r   r   setClipRect
translatedr   r   r   )	r'   r   rx   ry   rz   r(   r{   r   r   s	            r)   r   zItemDelegate.paint   s   &v.We,)0)?##%nn**, 	 oa GLL!&00'7C)668''(B(B(/7(**,-H//1A1A1C0CDE!!'3/r*   c                 h   t        |      }| j                  ||       t               }|j                  |j                         |j                  |j                  j                                t        t        |j                               t        |j                         j                                     S r,   )r   rt   r   rv   r0   setTextWidthrectwidthr   intr   rU   r=   rw   s        r)   r   zItemDelegate.sizeHint   s{    &v.We,oGLL!++-.S)*C
0A0A0C,DEEr*   N)r?   r@   rA   r#   r   r   rC   r*   r)   r   r      s    32Fr*   r   c                   r     e Zd ZdZdej
                  f fd	Zd Zd Zd Z	d Z
 fdZ fd	Z fd
Z xZS )IconLineEditzr
    Custom QLineEdit that includes an icon representing a validation for its
    text and can also elide it.
    Fc                 B   t         |   |       || _        || _        d| _        d| _        d| _        t        j                  d      | _	        t        j                  d      | _
        t        j                  d      | _        | j                          d| _        d| _        y )NTFtodowarning	todo_listr   )rJ   r#   
elide_textellipsis_place_status_status_set	_focus_inr   icon_valid_icon_invalid_icon	_set_icon_refresh_paint_count_icon_visible)r'   rq   r   r   rW   s       r)   r#   zIconLineEdit.__init__   s     $,88F+ XXi0+."r*   c                 2   | j                         }| j                  r| j                  sd}t        j                  j                         }|j                  j                  d| d       | j                  |j                                | j                          y)zm
        This makes space for the right validation icons after focus is given to
        the widget.
        r   nonepx)borderpaddingRightN)r=   r   r   	qstylizerr(   
StyleSheetr   	setValuesr&   toStringupdate)r'   paddingcsss      r)   r   zIconLineEdit._refresh   su    
 ++-??4>>Goo((*#9B 	  	

 	3<<>*r*   c                 R    d| _         | j                          | j                          y)zShow the status icon.FNr   repaintr   r3   s    r)   hide_status_iconzIconLineEdit.hide_status_icon  s    "r*   c                 R    d| _         | j                          | j                          y)zHide the status icon.TNr   r3   s    r)   show_status_iconzIconLineEdit.show_status_icon  s    !r*   c                 `    || _         || _        | j                          | j                          y)z@Update the status and set_status to update the icons to display.N)r   r   r   r   )r'   r^   	value_sets      r)   update_statuszIconLineEdit.update_status  s#    $r*   c                    | j                   r,| j                  st        |       }t               }| j	                  |       | j                         j                  t        j                  ||       }|j                  dddd       t        | j                               }|j                  | j                         | j                  |j                               }|j!                  t#        t$        j&                               |j)                  |t+        t,        j.                  t,        j0                  z        |       yt2        | i  |       t        |       }| j7                         }t+        |j9                         dz        }|j9                         |z
  }	|j                         |	z
  }
| j:                  r| j<                  r)| j>                  r| j@                  jC                  |	|	      }nE| j<                  r| jD                  jC                  |	|	      }n| jF                  jC                  |	|	      }|jI                  |
d|       | jJ                  dk  r&| xjJ                  dz  c_%        | jM                          yy)zm
        Include a validation icon to the left of the line edit and elide text
        if requested.
        r   N   rI      rH   )'r   r   r   r   rt   r(   r   r   SE_LineEditContentsadjustr   font
elidedTextr0   r   r   setPenr
   r   COLOR_TEXT_1drawTextr   r   	AlignLeftAlignVCenterrJ   
paintEventgeometryr=   r   r   r   r   pixmapr   r   
drawPixmapr   r   )r'   r8   r   rx   	text_rectfmr0   r   spacehwr   rW   s               r)   r   zIconLineEdit.paintEvent  s    ??4>>
 tnG&(F  (

33**FD:IQ2q)diik*B==d.A.A!*!24DNN6-"<"<=>YBLL2??,J(K!#5!4.}}T[[]A%&KKME!JJL1|| 0 0..q!4))00A6++221a8q!V, q "MMO !r*   c                 R    d| _         | j                          t        |   |       y)z:Reimplemented to know when this widget has received focus.TN)r   r   rJ   focusInEventr'   r8   rW   s     r)   r   zIconLineEdit.focusInEventE  s     U#r*   c                 R    d| _         | j                          t        |   |       y)z6Reimplemented to know when this widget has lost focus.FN)r   r   rJ   focusOutEventr   s     r)   r   zIconLineEdit.focusOutEventK  s     e$r*   )r?   r@   rA   rB   r   	ElideLeftr#   r   r   r   r   r   r   r   rk   rl   s   @r)   r   r      sA    
 +0 #$.`$% %r*   r   c                   :     e Zd ZdZddef fd	Zd Z fdZ xZS )FinderLineEditz=QLineEdit for filtering listed elements in the parent widget.Nc                     t         t        |   |       || _        || _        t        |dz         }| j                  t        |             |r| j                  j                  |       y y )Nz{100})
rJ   r   r#   _parentmainr   setValidatorr   textChangedconnect)r'   rq   callbackr   
regex_baseregexrW   s         r)   r#   zFinderLineEdit.__init__U  sc    nd,V4	 
W,-*512 $$X. r*   c                 l    |j                         }| j                         |z   }| j                  |       y)zSet the filter text.N)stripr0   ri   )r'   r0   new_texts      r)   set_textzFinderLineEdit.set_textc  s)    zz|99;%Xr*   c                 ~   |j                         }|t        j                  fv r| j                  j	                          y|t        j
                  fv r| j                  j                          y|t        j                  t        j                  fv r| j                  j                          yt        t        | 3  |       y)z
        Qt Override.

        The parent needs to implement the methods to handle focus on the
        next/previous row and a action over the selected element.

        This should be override.
        N)keyr   Key_Upr   previous_rowKey_Downnext_row	Key_Enter
Key_Returnselected_elementrJ   r   keyPressEvent)r'   r8   r   rW   s      r)   r  zFinderLineEdit.keyPressEventi  s     iik299+LL%%'R[[M!LL!!#R\\2==11LL))+.$5e<r*   )	r?   r@   rA   rB   VALID_FINDER_CHARSr#   r   r  rk   rl   s   @r)   r   r   R  s"    G(,4./= =r*   r   c                   0     e Zd ZdZd fd	Zd Zd Z xZS )CustomSortFilterProxyz$Custom column filter based on regex.c                 n    t         t        |   |       || _        t	        j
                  d      | _        y )Nr~   )rJ   r  r#   r   recompilepattern)r'   rq   rW   s     r)   r#   zCustomSortFilterProxy.__init__  s)    #T3F;zz#r*   c                     t        |      | _        | j                  r|r| j                  j                  d       n| j                  j                  d       | j	                          y)z"Set regular expression for filter.FTN)r   r  r   setSortingEnabledinvalidateFilterr/   s     r)   
set_filterz CustomSortFilterProxy.set_filter  sG    '-<<DLL**51LL**40r*   c                     | j                         }|j                  |      j                  }t        j                  | j
                  |      }|yy)zbQt override.

        Reimplemented from base class to allow the use of custom filtering.
        FT)sourceModelrownamer	  searchr  )r'   row_numrq   modelr  rs         r)   filterAcceptsRowz&CustomSortFilterProxy.filterAcceptsRow  sE    
   "yy!&&IIdllD)9r*   r,   )r?   r@   rA   rB   r#   r  r  rk   rl   s   @r)   r  r  }  s    .'
 r*   r  c                     ddl m}   |        }t               }|j                  t	        d             |j                  d       |j                  d       |j                  t        j                         |j                  t        j                         |j                  t        j                         |j                          y )Nr   )qapplicationzSpyder updateszTesting checkboxzCheck for updates on startup?)spyder.utils.qthelpersr  rE   setWindowTitler   ri   rj   setStandardButtonsr   OksetDefaultButtonr$   Informationexec_)r  appboxs      r)   test_msgcheckboxr$    s    3
.C

Cq)*+KK"#9:;>>*(KK''(IIKr*   __main__)4rB   r	  qstylizer.styler   qtpyr   qtpy.QtCorer   r   r   r   r   
qtpy.QtGuir	   r
   r   r   r   r   qtpy.QtWidgetsr   r   r   r   r   r   r   r   r   r   r   r   spyder.config.baser   spyder.utils.icon_managerr   spyder.utils.stringmatchingr   spyder.utils.paletter   VALID_ACCENT_CHARSformatr  r    rE   rn   r   r   r   r  r$  r?   rC   r*   r)   <module>r1     s   
 
   I IE E@ @ @ @ ! ) 8 . k %,,-?@ *{ *8+%k +%\BN& BNJ%F& %FPt%9 t%n(=Y (=V1 @
 z r*   