
    Jem                     ~    d Z ddlmZ ddlmZmZmZ ddlmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ  G d	 d
e      Zy)z1
A Class and Function Dropdown Panel for Spyder.
    )IntervalTree)QSizeQtSlot)	QComboBoxQHBoxLayout)Panel)_)
SymbolKind)imac                        e Zd ZdZ fdZ fdZd Z eee      d        Z	d Z
 fdZd Zd	 Zdd
Zd ZddZ xZS )ClassFunctionDropdownz
    Class and Function/Method Dropdowns Widget.

    Parameters
    ----------
    editor : :class:`spyder.plugins.editor.widgets.codeeditor.CodeEditor`
        The editor to act on.
    c                    t         |           t               | _        d | _        g | _        g | _        t               | _        t               | _	        | j                  j                  t        d      d       | j                  j                  t        d      d       t               }|j                  | j                         |j                  | j                         |j                  d       |j                  dddd       | j!                  |       | j                  j"                  j%                  | j&                         | j                  j"                  j%                  | j&                         y )N<None>r   )super__init__r   _tree_dataclassesfuncsr   class_cb	method_cbaddItemr
   r   	addWidget
setSpacingsetContentsMargins	setLayout	activatedconnectcombobox_activated)selfhbox	__class__s     T/usr/lib/python3/dist-packages/spyder/plugins/editor/panels/classfunctiondropdown.pyr   zClassFunctionDropdown.__init__    s    "^


 "" 	ak1-q{A. }t}}%t~~&1a+t 	''(?(?@  (()@)@A    c                     t         |   |       || _        | j                  j                  j	                  | j
                         y)z"Manages install setup of the pane.N)r   
on_install_editorsig_cursor_position_changedr   $_handle_cursor_position_change_event)r!   editorr#   s     r$   r'   z ClassFunctionDropdown.on_install=   s:    6" 	008855	
r%   c                 6    | j                   j                         S )z&Get the default height of a QComboBox.)r   heightr!   s    r$   _getVerticalSizez&ClassFunctionDropdown._getVerticalSizeH   s    }}##%%r%   c                 &    | j                  |       y )N)update_selected)r!   linenumcolumns      r$   r*   z:ClassFunctionDropdown._handle_cursor_position_change_eventL   s    W%r%   c                 6    t        d| j                               S )zOverride Qt method.r   )r   r/   r.   s    r$   sizeHintzClassFunctionDropdown.sizeHintP   s    Q--/00r%   c                     | j                   ;| j                  g k(  r,| j                  g k(  r| j                  | j                   d       t        |   |       y)zm
        Update contents in case there is available data and the widget hasn't
        been updated.
        NT)force)r   r   r   update_datar   	showEvent)r!   eventr#   s     r$   r9   zClassFunctionDropdown.showEventT   sI    
 ::!dllb&8TZZ2=MTZZt4% r%   c                    | j                         }|j                  |j                               }|r,|d   d   d   d   dz   }| j                  j	                  |       || j
                  k(  r| j                  j                  d       yy)z+Move the cursor to the selected definition.locationrangestartline   r   N)senderitemDatacurrentIndexr+   
go_to_liner   r   setCurrentIndex)r!   rA   itemr?   s       r$   r    z(ClassFunctionDropdown.combobox_activated]   sz    v2245
#G,W5f=ADKK""4(T]]"NN**1- #r%   c                    t        t        | j                  |               }|D ]U  }|j                  }|j	                  d      }|t
        j                  fv rt        | j                  j                               D ]=  }| j                  j                  |      |k(  s"| j                  j                  |         | j                  j                  d       |t
        j                  t
        j                  fv rt        | j                  j                               D ]>  }| j                  j                  |      |k(  s"| j                  j                  |        8 | j                  j                  d       VX t        |      dk(  r7| j                  j                  d       | j                  j                  d       yy)z@Updates the dropdowns to reflect the current class and function.kindr   N)listsortedr   datagetr   CLASSr=   r   countrB   rE   FUNCTIONMETHODr   len)r!   r2   possible_parentsivrF   rH   idxs          r$   r1   z%ClassFunctionDropdown.update_selectedi   si   tzz'': ;<" 	B77D88F#D
(()) !4!4!67 5C}}--c2d:55c:5
 MM11!4*--z/@/@AA !5!5!78 6C~~..s3t;66s;6
 NN2215+	.  A%MM))!,NN**1- &r%   c                 \   |j                          |j                  t        d      d       |j                         }|j	                  d      }|j                  t        j                         g }|D ]  }|d   }|r|d   d   d   d   }|d   d   d   d   }	t        | j                  j                  ||	      d	
      }
|
D ]`  }|j                  |k(  r|j                  |	k(  r"|j                  }|d   d   d   d   }|d   d   d   d   }||k  sP||	k\  sV|d   dz   |z   }b |j                  ||f        |D ]  \  }}d}|d   }|d   t        j                   fv rt#        j$                  d      }nc|j'                  d      rt#        j$                  d      }n<|j'                  d      rt#        j$                  d      }nt#        j$                  d      }||j                  |||       |j                  ||        | j(                  j+                         \  }}| j-                  |       y)a  
        Populate the given ``combobox`` with the class or function names.

        Parameters
        ----------
        combobox : :class:`qtpy.QtWidgets.QComboBox`
            The combobox to populate
        data : list of :class:`dict`
            The data to populate with. There should be one list element per
            class or function definition in the file.
        add_parents : bool
            Add parents to name to create a fully qualified name.

        Returns
        -------
        None
        r   r   namer<   r=   r>   r?   endT)reverse.NrH   class__private2r
   private1method)clearr   r
   modelrF   setFlagsr   NoItemFlagsrJ   r   overlapbeginrW   rK   appendr   rM   r   icon
startswithr(   get_cursor_line_columnr1   )r!   comboboxrK   add_parentsr`   rF   cb_datafqnrd   rW   rR   rS   p_itemp_beginp_endrf   rV   r?   r[   s                      r$   populatezClassFunctionDropdown.populate   s0   $ 	8a( zz!}bnn% 	(Dv,C Z(1':6B:&w/6v>#)$***<*<UC*H26$8 * 	9Bxx5(RVVs]   WWF$Z09'B6JG":.w7>vFE%'ESL$Vns2S8	9 NNC;')	(, ! 	,ICD<DF|
 0 011xx(??4(88J/D__S)88J/D88H-D   sD1  d+%	,( <<668bT"r%   c                     || _         y)z8Set data in internal attribute to use it when necessary.N)r   )r!   rK   s     r$   set_datazClassFunctionDropdown.set_data   s	    
r%   c                    |s|| j                   k(  ry|| _         | j                  j                          g | _        g | _        |D ]  }|d   d   d   d   }|d   d   d   d   }|j                  d      }| j                  j                         j                  |      }|r|j                         ndx}}||k7  sud	|vsz|| j                  || |t        j                  fv r| j                  j                  |       |t        j                  t        j                  fv s| j                  j                  |        | j                  j                          | j                   j                          | j#                  | j                  | j                  d
       | j#                  | j                   | j                  d       y)zUpdate and process symbol data.Nr<   r=   r>   r?   rW   rH    z import F)rj   T)r   r   r_   r   r   rL   r(   documentfindBlockByLineNumbertextr   rM   re   rO   rP   r   r   rp   )	r!   rK   r7   rF   
line_startline_endrH   block	line_texts	            r$   r8   z!ClassFunctionDropdown.update_data   s}   +



 	,Dj)'27;FCJJ'07?H88F#DLL))+AA*ME49EJJLrAI	 X%*I*E26

:h/J,,--LL''-j11:3D3DEEJJ%%d+!	,$ 	dmmT\\uEdnndjjdCr%   )F)__name__
__module____qualname____doc__r   r'   r/   r   intr*   r5   r9   r    r1   rp   rr   r8   __classcell__)r#   s   @r$   r   r      sX    B:	
& 
#s^& &1!
..<D#LDr%   r   N)r   intervaltreer   qtpy.QtCorer   r   r   qtpy.QtWidgetsr   r   spyder.api.panelr	   spyder.config.baser
   spyder.plugins.completion.apir   spyder.utils.icon_managerr   r    r%   r$   <module>r      s6   
 & ' ' 1 #   4 )ZDE ZDr%   