
    G@d                         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dS )
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                   <    e Zd ZdZdZdZdZdZdZe	d             Z
dS )	Panel.Positionz'Enumerates the possible panel positionsr               c                 6    | j         | j        | j        | j        gS )z2 Returns possible positions as an iterable (list) )TOPLEFTRIGHTBOTTOM)clss    0lib/python3.11/site-packages/spyder/api/panel.pyiterablezPanel.Position.iterable8   s     GSXsy#*==    N)__name__
__module____qualname____doc__r   r   r   r   FLOATINGclassmethodr    r   r   Positionr   +   sL        5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                     || _         d S )Nr'   )r*   values     r   r+   zPanel.scrollableI   s     r   Fc                     t          j        |            t          j        |            || _        d| _        d| _        d | _        d | _        d| _        d S )NF)	r   __init__r   dynamicorder_in_zoner(   _background_brush_foreground_penposition)r*   r1   s     r   r0   zPanel.__init__M   sZ     &&&    !%#r   c                 >   t          j        | |           |                     |           |                     t	          j                                                               |                     t	          j                                                               | j	        j
                                         t          t          |                                                                                                                     | _        t#          t          |                                                                                                                     | _        | j        | j        j        k    r!|                     t0          j                   dS dS )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^   sI    	"4000v-//7799:::\*,,1133444""$$$!'LLNN!!##))++)- )- ". ".#FLLNN%%''--//%1 %1  2  2 =DM222b=>>>>> 32r   c                    |                                  r| j        | j        j        k    rt	          t          | j        j                            | _        t          t          | 
                                                                                                                    | _        t          |           }|                    |                                | j                   dS t"                              d|             dS )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     >> 		I1G G G%+F+-- -- &. &.D"#'))++1133)5 )5 $6 $6D tnnGUZZ\\4+ABBBBBLLGGGHHHHHr   c                 T    | j         | j        j        k    rt          d|            dS )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   s>      =DM222%@$@@B B B 32r   c                     t                               d| j                   t          t          |                               |           | j        r | j        j                                         dS dS )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   sk     	,di888eT%%g...; 	)K&&(((((	) 	)r   c                     dS )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                                                                        z   | j        j                            t          j        j                  z   }|                                | j        j                            t          j        j                  z   }|                     t+          t-          ||z             t-          ||z             t-          |          t-          |                               dS )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   se    !%Bv=KKMME>\\^^F **,,K--dk.K.K.M.MNNZ

FHHJJ//k""$$33556 k ,,U^-@AAB IIKK$+,889KLLLtAbDzz4"::#E{{DLL: : 	; 	; 	; 	; 	;r   )F)r   r   r    r!   objectr%   propertyr+   setterr0   r7   rO   rR   rV   rZ   rn   __classcell__)rX   s   @r   r   r   "   s        > > > > >6 > > >$ 	  	  X	  ! ! !   "? ? ?0I I I(B B 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      s            1 0 0 0 0 0 0 0 5 5 5 5 5 5 5 5 5 5 5 5 ! ! ! ! ! ! ! ! 7 6 6 6 6 6		8	$	$h; h; h; h; h;G_ h; h; h; h; h;r   