
    G@d'                         d Z ddlZddlmZmZmZ ddlmZmZ ddl	m
Z
mZ dZ edd          Z G d	 d
          Z G d d          Z G d de          Z G d de          ZdS )z
Spyder API menu widgets.
    N)OptionalUnionTypeVar)QActionQMenu)add_actionsSpyderActionT
SpyderMenu)boundc                       e Zd ZdZdZdS )OptionsMenuSectionstop_sectionbottom_sectionN)__name__
__module____qualname__TopBottom     8lib/python3.11/site-packages/spyder/api/widgets/menus.pyr   r      s        
CFFFr   r   c                       e Zd ZdZdZdS )PluginMainWidgetMenuscontext_menuoptions_menuN)r   r   r   ContextOptionsr   r   r   r   r   $   s        GGGGr   r   c                        e Zd ZdZg Z	 	 d fd	Zd Z	 	 	 	 	 ddedee	ef         d	e
e         d
e
e         de
e         dedefdZdefdZd Zd Zd Zd ZddZ xZS )r   zL
    A QMenu subclass to implement additional functionality for Spyder.
    NTc                    || _         || _        g | _        g | _        i | _        i | _        i | _        d| _        || _        |"t                      
                    |           n"t                      
                    ||           | j                            ||| f           t          j        dk    r$|r"|                     t!          |                      | j                            | j                   d S )NFdarwin)_parent_title	_sections_actions_actions_mapunintroduced_actions_after_sections_dirtymenu_idsuper__init__MENUSappendsysplatform	addActionr   aboutToShowconnect_render)selfparenttitledynamicr*   	__class__s        r   r,   zSpyderMenu.__init__1   s    $&!!=GGV$$$$GGUF+++
65$/000<8### NN74==)))  .....r   c                 t    |                                   g | _        g | _        i | _        i | _        i | _        dS )z{
        Remove actions from the menu (including custom references)

        Returns
        -------
        None.
        N)clearr$   r%   r&   r'   r(   r5   s    r   clear_actionszSpyderMenu.clear_actionsJ   s=     	

$&!!r   Fr5   actionsectionbeforebefore_sectioncheck_beforeomit_idc                    d}t          |t                    st          |d          r|j        }n,t          |t                    st          |d          r|j        }|s||t          d| d          || j                            ||f           ng }d}	| j	        
                    |d          }
| j        D ]=\  }}|
||
k    rd}	|                    ||f           |                    ||f           >|	s>|r<| j        
                    |g           }|                    ||f           || j        |<   || _        || j        vr|                     ||           d| _        || j	        |<   dS )a  
        Add action to a given menu section.

        Parameters
        ----------
        action: SpyderAction
            The action to add.
        section: str or None
            The section id in which to insert the `action`.
        before: str
            Make the action appear before the given action identifier.
        before_section: str or None
            Make the item section (if provided) appear before another
            given section.
        check_before: bool
            Check if the `before` action is part of the menu. This is
            necessary to avoid an infinite recursion when adding
            unintroduced actions with this method again.
        omit_id: bool
            If True, then the menu will check if the item to add declares an
            id, False otherwise. This flag exists only for items added on
            Spyder 4 plugins. Default: False
        N	action_idr*   zItem z must declare an id.FT)
isinstancer	   hasattrrE   r   r*   AttributeErrorr%   r.   r&   getr'   r$   _add_sectionr)   )r5   r>   r?   r@   rA   rB   rC   item_idnew_actionsaddedbefore_itemsecactbefore_actionss                 r   
add_actionzSpyderMenu.add_actionY   s   < fl++ 	%wv{/K/K 	%&GG
++ 	%wvy/I/I 	%nG 	G7?v/A !E!E!E!EFFF>M  '6!23333KE+//==K M / /S*sk/A/A E&&'8999""C:....  C\ C!%!:!>!>vr!J!J%%w&78884B)&1'DM$.((g~666 %+'"""r   rK   c                     || j         v rh| j                             |          }d }t          | j                  D ]\  }\  }}||k    r|} n|%| j                            |           d| _        d S d S d S )NT)r&   pop	enumerater%   r)   )r5   rK   r>   positioni_rP   s          r   remove_actionzSpyderMenu.remove_action   s    d'''&**733FH(77  8As&== HE ! #!!(+++" (' $#r   c                     | j         S )z,
        Return the title for menu.
        )r#   r<   s    r   	get_titlezSpyderMenu.get_title   s     {r   c                     g }| j         D ]D}| j        D ] \  }}||k    r|                    |           !|                    t                     E|S )z
        Return a parsed list of menu actions.

        Includes MENU_SEPARATOR taking into account the sections defined.
        )r$   r%   r.   MENU_SEPARATOR)r5   actionsr?   rO   r>   s        r   get_actionszSpyderMenu.get_actions   se     ~ 	+ 	+G!% + +f'>>NN6***NN>****r   c                 *    t          | j                  S )z2
        Return a tuple of menu sections.
        )tupler$   r<   s    r   get_sectionszSpyderMenu.get_sections   s     T^$$$r   c                    | j         r|                                  | j                                        D ]&\  }}|D ]\  }}|                     |||d           '|                                 }t          | |           d| _         dS dS )zv
        Create the menu prior to showing it. This takes into account sections
        and location of menus.
        F)r?   r@   rB   N)r)   r;   r'   itemsrR   r_   r   )r5   r@   r^   r?   r>   s        r   r4   zSpyderMenu._render   s    
 ; 	 JJLLL $(#<#B#B#D#D G G'. G GOGVOOFG+1 $ G G G GG &&((Gg&&&DKKK	  	 r   c                    d}|f|| j         v r8| j                             |          }| j                             ||           d}n?|| j        |<   | j                             |           n| j                             |           | j                            |d          }||s]|| j         v r| j                             |           | j                             |          }| j                             |dz   |           dS || j         v r| j                             |           | j                             |          }|dk    r|n|dz
  }| j                             ||           dS dS )z
        Add a new section to the list of sections in this menu.

        Parameters
        ----------
        before_section: str or None
            Make `section` appear before another one.
        FNT   r   )r$   indexinsertr(   r.   rT   remove)r5   r?   rA   inserted_before_otheridxafter_sectionrg   s          r   rJ   zSpyderMenu._add_section   s    !&%// n**>::%%c7333(,%%
 8?$^4
 %%g....N!!'*** ,00$??$( : dn,,N))'222,,];;%%eai99999 !DN22N))-888n**733!QhhcccAg%%c=99999# %$r   )NNTN)NNNTF)N)r   r   r   __doc__r-   r,   r=   r
   r   r	   r   strboolrR   rY   r[   r_   rb   r4   rJ   __classcell__)r9   s   @r   r   r   +   sY         E8</ / / / / /2" " "" -1+/37(,#(E, E, E, q1E,$SME, $C=E, $,C=	E,
 "&E, !E, E, E, E,N#S # # # #    % % %     &5: 5: 5: 5: 5: 5: 5: 5:r   c                       e Zd ZdZd ZdS )MainWidgetMenuzA
    This menu fixes the bottom section of the options menu.
    c                 ~   | j         r|                                  t          j        }g }| j        D ]J}| j        D ]&\  }}||k    r||k    r|                    |           '|                    t                     K| j        D ] \  }}||k    r|                    |           !t          | |           d| _         dS dS )z
        Create the menu prior to showing it. This takes into account sections
        and location of menus. It also hides consecutive separators if found.
        FN)	r)   r;   r   r   r$   r%   r.   r]   r   )r5   bottomr^   r?   rO   r>   s         r   r4   zMainWidgetMenu._render  s    
 ; 	 JJLLL(/FG> / /%)] / /MS&g~~#--v...~.... "& + +f&==NN6***g&&&DKKK#	  	 r   N)r   r   r   rm   r4   r   r   r   rr   rr     s-                  r   rr   )rm   r/   typingr   r   r   qtpy.QtWidgetsr   r   spyder.utils.qthelpersr   r	   r]   r
   r   r   r   rr   r   r   r   <module>rx      s@   
 


 + + + + + + + + + + * ) ) ) ) ) ) ) = < < < < < < <
  GC|$$$       
       f: f: f: f: f: f: f: f:R         Z          r   