
    Je                         d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	m
Z
mZ ddlmZmZ ddlmZ  ej"                  e      Z G d d	ee      Zy)
z
This module contains the panel API.

Adapted from pyqode/core/api/panel.py of the
`PyQode project <https://github.com/pyQode/pyQode>`_.
Original file:
<https://github.com/pyQode/pyqode.core/blob/master/pyqode/core/api/panel.py>
    )ceilN)QWidgetQApplication)QBrushQColorQPenQPainter)QtQRect)EditorExtensionc                        e Zd ZdZ G d de      Zed        Zej                  d        ZddZ	d Z
d Zd	 Z fd
Zd Zd Z xZS )Panelz
    Base class for editor panels.

    A panel is a editor extension and a QWidget.

    .. note:: Use enabled to disable panel actions and setVisible to change the
        visibility of the panel.
    c                   4    e Zd ZdZdZdZdZdZdZe	d        Z
y)	Panel.Positionz'Enumerates the possible panel positionsr               c                 ^    | j                   | j                  | j                  | j                  gS )z2 Returns possible positions as an iterable (list) )TOPLEFTRIGHTBOTTOM)clss    2/usr/lib/python3/dist-packages/spyder/api/panel.pyiterablezPanel.Position.iterable8   s#     GGSXXsyy#**==    N)__name__
__module____qualname____doc__r   r   r   r   FLOATINGclassmethodr    r   r   Positionr   +   s0    5		> 
	>r   r%   c                     | j                   S )z
        A scrollable panel will follow the editor's scroll-bars.

        Left and right panels follow the vertical scrollbar. Top and bottom
        panels follow the horizontal scrollbar.

        :type: bool
        _scrollableselfs    r   
scrollablezPanel.scrollable=   s     r   c                     || _         y )Nr'   )r*   values     r   r+   zPanel.scrollableI   s
     r   c                     t        j                  |        t        j                  |        || _        d| _        d| _        d | _        d | _        d| _        y )NF)	r   __init__r   dynamicorder_in_zoner(   _background_brush_foreground_penposition)r*   r1   s     r   r0   zPanel.__init__M   sP      &    !%#r   c                    t        j                  | |       | j                  |       | j                  t	        j
                         j                                | j                  t	        j
                         j                                | j                  j                  j                          t        t        | j                         j                         j                                     | _        t#        t        | j                         j%                         j                                     | _        | j(                  | j*                  j,                  k(  r | j/                  t0        j2                         yy)aW  
        Extends :meth:`spyder.api.EditorExtension.on_install` method to set the
        editor instance as the parent widget.

        .. warning:: Don't forget to call **super** if you override this
            method!

        :param editor: editor instance
        :type editor: spyder.plugins.editor.widgets.codeeditor.CodeEditor
        N)r   
on_install	setParent
setPaletter   instancepalettesetFontfonteditorpanelsrefreshr   r   windowcolorr3   r   
windowTextr4   r5   r%   r"   setAttributer
   WA_TransparentForMouseEvents)r*   r>   s     r   r7   zPanel.on_install^   s    	""40v--/779:\**,1134""$!'LLN!!#))+)- ".#FLLN%%'--/%1  2 ==DMM222b==> 3r   c                    | j                         r| j                  | j                  j                  k7  rt	        t        | j                  j                              | _        t        t        | j                         j                         j                                     | _        t        |       }|j                  |j!                         | j                         yt"        j%                  d|         y)z
        Fill the panel background using QPalette.

        Notes
        -----
        Please remember to extend this method in the child class to
        paint the panel's desired information.
        z%paintEvent method must be defined in N)	isVisibler5   r%   r"   r   r   r>   sideareas_colorr3   r   r;   rC   rB   r4   r	   fillRectrectloggerdebug)r*   eventpainters      r   
paintEventzPanel.paintEventv   s     >>1G1G G%+F++-- &.D"#'))+113)5 $6D tnGUZZ\4+A+ABLL@GHr   c                 f    | j                   | j                  j                  k7  rt        d|        y)aa  
        Return the widget size hint, overriding the Qt method.

        Notes
        -----
        * This size hint will define the QSize of the panel, i.e. it is
          where its width and height are defined.
        * If the size of your panel depends on displayed text, please
          use the LineNumberArea one as reference on how to implement
          this method.
        * If the size is not dependent on displayed text, please use
          the debugger panel as reference.
        * If your panel is in a floating position, please use the
          IndentationGuide one as reference.
        z'sizeHint method must be implemented in N)r5   r%   r"   NotImplementedErrorr)   s    r   sizeHintzPanel.sizeHint   s8      ==DMM222%9$@B B 3r   c                     t         j                  d| j                         t        t        |   |       | j                  r%| j                  j                  j                          yy)z
        Shows/Hides the panel.

        Automatically call PanelsManager.refresh_panels.

        :param visible: Visible state
        z%s visibility changedN)	rK   rL   namesuperr   
setVisibler>   r?   r@   )r*   visible	__class__s     r   rV   zPanel.setVisible   sI     	,dii8eT%g.;;KK&&( r   c                      y)zReturn geometry dimensions for floating Panels.

        Note: If None is returned It'll use editor contentsRect dimensions.

        returns: x0, y0, height width.
        )r   r   NNr$   r)   s    r   geometryzPanel.geometry   s      r   c           
      |   | j                         \  }}}}||j                         }||j                         }| j                  j	                         }| j                  j                  | j                  j                               j                  |j                         |j                               j                         | j                  j                         j                         z   | j                  j                  j                  t        j                   j"                        z   }|j%                         | j                  j                  j                  t        j                   j&                        z   }| j)                  t+        t-        ||z         t-        ||z         t-        |      t-        |                   y)zSet geometry for floating panels.

        Normally you don't need to override this method, you should override
        `geometry` instead.
        N)rZ   widthheightr>   contentOffsetblockBoundingGeometryfirstVisibleBlock
translatedxyleftdocumentdocumentMarginr?   margin_sizer   r%   r   topr   setGeometryr   r   )	r*   crectx0y0r\   r]   offsetrb   rc   s	            r   set_geometryzPanel.set_geometry   s:    !%Bv=KKME>\\^F **,KK--dkk.K.K.MNZ
FHHJ/kk""$3356 kk  ,,U^^-@-@AB IIK$++,,889K9KLLtAbDz4":#E{DL: 	;r   )F)r   r   r    r!   objectr%   propertyr+   setterr0   r7   rO   rR   rV   rZ   rn   __classcell__)rX   s   @r   r   r   "   sg    >6 >$ 	  	  ! !"?0I(B() ;r   r   )r!   mathr   loggingqtpy.QtWidgetsr   r   
qtpy.QtGuir   r   r   r	   qtpy.QtCorer
   r   spyder.api.editorextensionr   	getLoggerr   rK   r   r$   r   r   <module>rz      sG      1 5 5 ! 7			8	$h;G_ h;r   