
    Je                     F    d Z ddlmZ ddlmZmZ ddlmZ  G d de      Zy)z3
This module contains the indentation guide panel.
    )Qt)QPainterQColor)Panelc                   R     e Zd ZdZd Z fdZd Zd Zd Zd Z	d Z
d	 Zd
 Z xZS )IndentationGuidez2Indentation guides to easy identify nested blocks.c                 t    t        j                  |        t        j                  | _        d| _        d| _        y)zaInitialize IndentationGuide panel.
        i_width(int): identation width in characters.
           r   N)r   __init__r   darkGraycolori_width
bar_offsetselfs    P/usr/lib/python3/dist-packages/spyder/plugins/editor/panels/indentationguides.pyr   zIndentationGuide.__init__   s)     	t[[
    c                     t         |   |       |j                         }|j                  j	                  | j
                         |j                  j	                  | j                         y)z"Manages install setup of the pane.N)super
on_installhorizontalScrollBarvalueChangedconnectupdate_bar_positionsliderReleasedupdate)r   editorhorizontal_scrollbar	__class__s      r   r   zIndentationGuide.on_install!   sQ    6"%99;))11$2J2JK++33DKK@r   c                     || _         y )N)r   )r   values     r   r   z$IndentationGuide.update_bar_position(   s	    r   c                 "    | j                         S )zOverride Qt method.)sizer   s    r   sizeHintzIndentationGuide.sizeHint+   s    yy{r   c                 H   t        |       }t        | j                        }|j                  d       |j	                  |       | j
                  j                         j                         | j
                  j                         j                         z   }| j
                  j                  j                  d      }|j                  }| j
                  j                  }| j
                  j                         }|D ]  }	||	   }
|	|
f}| j                  ||      s | j
                  j                         j!                  |	      }| j
                  j                         j!                  |
dz
        }| j
                  j                         }t#        | j
                  j%                  |      j'                  |      j)                               }t#        | j
                  j%                  |      j'                  |      j+                               }|j                  t-        |	dz
  d            }|j                  |
dz
        }|sG||k7  sN| j
                  j/                         }t#        |j1                  |dz        | j2                  z   |z         }|j5                  ||||        y)zD
        Overriden Qt method.

        Paint indent guides.
        g      ?FoldingPanel   r   9N)r   r   r   	setAlphaFsetPenr   documentdocumentMargincontentOffsetxpanelsgetfolding_regionsleading_whitespacesget_visible_block_numbersdo_paintfindBlockByNumberintblockBoundingGeometry
translatedtopbottommaxfontMetricswidthr   drawLine)r   eventpainterr   offsetfolding_panelr1   r2   visible_blocks
start_lineend_lineline_numbersstart_block	end_blockcontent_offsetr9   r:   total_whitespaceend_whitespacefont_metricsr.   s                        r   
paintEventzIndentationGuide.paintEvent/   s9    4.tzz"u ++&&(779++++-//12 **..~>'77"kk== >>@ * 	8J&z2H&1L}}^\:"kk224FF  KK002DDqL"	 "&!:!:!<$++;;!!+N!;CCECT[[>>)z.9&&(D $7#:#:
Q*$, !4!8!8A!F!n8H&H#';;#:#:#<LL../?#/EF OO,.45 6A$$QQ71	8r   c                 h    || _         | j                  |       | j                  j                          y)zToggle edge line visibility.N)_enabled
setVisibler   request_folding)r   states     r   set_enabledzIndentationGuide.set_enabledd   s'     	##%r   c                 X    | j                   j                  j                  d      | _        y)z6Set color using syntax highlighter color for comments.commentN)r   highlighterget_color_namer   r   s    r   update_colorzIndentationGuide.update_colorm   s    [[,,;;IF
r   c                     || _         y)z7Set indentation width to be used to draw indent guides.N)r   )r   indentation_widths     r   set_indentation_widthz&IndentationGuide.set_indentation_widthq   s	    (r   c                     |d   dz   }|d   dz   }|d   }|d   }||k  r||cxk  r|k  ry ||k  r||k\  ry||cxk  r|k  r	n n||kD  ry||cxk  r|k  rn y||cxk  r|k  ry yy)ze
        Decide if we need to paint an indent guide according to the
        visible region.
        r   r'   TF )r   rC   rF   first_visible_linelast_visible_linerD   rE   s          r   r4   zIndentationGuide.do_paintu   s     ,A.2*1-1 "!_
? ++#xD3DD E ++<M0M  :B1BB,,  :B1BB
 	 $xD3DD E r   )__name__
__module____qualname____doc__r   r   r   r$   rM   rS   rX   r[   r4   __classcell__)r   s   @r   r   r      s6    <A 18j&G)!r   r   N)	rc   qtpy.QtCorer   
qtpy.QtGuir   r   spyder.api.panelr   r   r]   r   r   <module>rh      s%   
  ' #Cu Cr   