
    G@dm                         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dS )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        
                    t          d          d           | j	        
                    t          d          d           t                      }|                    | j                   |                    | j	                   |                    d           |                    dddd           |                     |           | j        j                            | j                   | j	        j                            | j                   d S )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     Rlib/python3.11/site-packages/spyder/plugins/editor/panels/classfunctiondropdown.pyr   zClassFunctionDropdown.__init__    sB    "^^


 "" 	akk1---q{{A... }}t}%%%t~&&&1a+++t 	''(?@@@ (()@AAAAA    c                     t                                          |           || _        | j        j                            | j                   dS )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=   sQ    6""" 	0885	
 	
 	
 	
 	
r%   c                 4    | j                                         S )z&Get the default height of a QComboBox.)r   heightr!   s    r$   _getVerticalSizez&ClassFunctionDropdown._getVerticalSizeH   s    }##%%%r%   c                 0    |                      |           d S )N)update_selected)r!   linenumcolumns      r$   r*   z:ClassFunctionDropdown._handle_cursor_position_change_eventL   s    W%%%%%r%   c                 F    t          d|                                           S )zOverride Qt method.r   )r   r/   r.   s    r$   sizeHintzClassFunctionDropdown.sizeHintP   s    Q--//000r%   c                     | j         2| j        g k    r'| j        g k    r|                     | j         d           t	                                          |           dS )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   s^    
 :!dlb&8&8TZ2=M=MTZt444%     r%   c                 <   |                                  }|                    |                                          }|r7|d         d         d         d         dz   }| j                            |           || j        k    r| j                            d           dS dS )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]   s    v224455 	)
#G,W5f=ADK""4(((T]""N**1----- #"r%   c                 x   t          t          | j        |                             }|D ]E}|j        }|                    d          }|t
          j        fv r~t          | j        	                                          D ]<}| j        
                    |          |k    r| j                            |            n=| j                            d           |t
          j        t
          j        fv rt          | j        	                                          D ]<}| j        
                    |          |k    r| j                            |            n=| j                            d           EGt          |          dk    r6| j                            d           | j                            d           dS dS )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   s   tz'': ; ;<<" 	 	B7D88F##D
())) !4!4!6!677 5 5C}--c22d::55c::: ; M11!444*-z/@AAA !5!5!7!788 6 6C~..s33t;;66s;;; < N221555  A%%M))!,,,N**1----- &%r%   Fc                    |                                  |                    t          d          d           |                                }|                    d          }|                    t          j                   g }|D ]}|d         }|r|d         d         d         d         }|d         d         d         d         }	t          | j	        
                    ||	          d	
          }
|
D ]n}|j        |k    r|j        |	k    r|j        }|d         d         d         d         }|d         d         d         d         }||k    r||	k    r|d         dz   |z   }o|                    ||f           |D ]\  }}d}|d         }|d         t          j        fv rt#          j        d          }nh|                    d          rt#          j        d          }n>|                    d          rt#          j        d          }nt#          j        d          }||                    |||           |                    ||           | j                                        \  }}|                     |           dS )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   s   $ 	8a(((  zz!}}bn%%% 	( 	(Dv,C  9Z(1':6B:&w/6v>#)$**<*<UC*H*H26$8 $8 $8 * 	9 	9Bx5((RVs]]   WF$Z09'B6JG":.w7>vFE%''ESLL$Vns2S8NNC;''''  	, 	,ICD<DF|
 0111x((??4(( .8J//DD__S)) .8J//DD8H--D   sD1111  d++++<6688bT"""""r%   c                     || _         dS )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dS || _         | j                                         g | _        g | _        |D ]}|d         d         d         d         }|d         d         d         d         }|                    d          }| j                                                            |          }|r|	                                ndx}}||k    rnd	|vrj|| j        ||<   |t          j        fv r| j                            |           |t          j        t          j        fv r| j                            |           | j                                         | j                                         |                     | j        | j        d
           |                     | j        | j        d           dS )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    	++F


 	, 	,Dj)'27;FCJJ'07?H88F##DL))++AA*MME49$AEJJLLLrAI	 X%%*I*E*E26
:h./J,---L''----j1:3DEEEJ%%d+++dmT\uEEEdndjdCCCCCr%   )F)__name__
__module____qualname____doc__r   r'   r/   r   intr*   r5   r9   r    r1   rp   rr   r8   __classcell__)r#   s   @r$   r   r      s        B B B B B:	
 	
 	
 	
 	
& & & 
T#s^^& & ^&1 1 1! ! ! ! !
. 
. 
.. . .<D# D# D# D#L  D D D D D D D 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      s    
 & % % % % % ' ' ' ' ' ' ' ' ' ' 1 1 1 1 1 1 1 1 # " " " " "             4 4 4 4 4 4 ) ) ) ) ) )ZD ZD ZD ZD ZDE ZD ZD ZD ZD ZDr%   