
    G@d#                         d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
mZ ddlmZ ddlmZmZ ddlmZ dd	lmZmZmZ dd
lmZ  G d de          ZdS )z
Toolbar Plugin.
    )SpyderAction)UnionOptional)SpyderPluginV2Plugins)on_plugin_availableon_plugin_teardown_)ApplicationMenusViewMenuSections)ApplicationToolbars)ToolbarContainerToolbarMenusToolbarActions)QWidgetc                      e Zd ZdZdZej        gZeZdZ	e
ZdZed             Zd Zd Zd Z eej                  d	             Z eej                  d
             Zd Zd Zd Zd ZdefdZ	 	 	 	 	 ddeeef         dee         dee         dee         dee         de fdZ!	 d dedee         fdZ"d Z#d dZ$e%d             Z&e%d             Z'e%d             Z(dS )!Toolbarz#
    Docstrings viewer widget.
    toolbarFc                       t          d          S )Nr   r
        =lib/python3.11/site-packages/spyder/plugins/toolbar/plugin.pyget_namezToolbar.get_name*   s    ||r   c                      t          d          S )Nz Application toolbars management.r
   selfs    r   get_descriptionzToolbar.get_description.   s    3444r   c                 ,    |                      d          S )Nhelp)create_iconr   s    r   get_iconzToolbar.get_icon1   s    '''r   c                 ,   | j         } |t          j        t          d                      |t          j        t          d                      |t          j        t          d                      |t          j        t          d                     d S )NzFile toolbarzRun toolbarzDebug toolbarzMain toolbar)create_application_toolbarr   Filer   RunDebugMain)r   create_app_toolbars     r   on_initializezToolbar.on_initialize4   s    !<.3Q~5F5FGGG.2Am4D4DEEE.4a6H6HIII.3Q~5F5FGGGGGr   )pluginc                 4   |                      t          j                  }|                    | j        t
          j        t          j        t          j	                   |                    | j
        t
          j        t          j        t          j	                   d S )N)menu_idsectionbefore_section)
get_pluginr   MainMenuadd_item_to_application_menutoolbars_menur   Viewr   r   Layoutshow_toolbars_actionr   mainmenus     r   on_main_menu_availablezToolbar.on_main_menu_available;   s    ??7#344--$)$,+2	 	. 	4 	4 	4
 	--%$)$,+2	 	. 	4 	4 	4 	4 	4r   c                     |                      t          j                  }|                    t          j        t          j                   |                    t          j	        t          j                   d S )N)r-   )
r0   r   r1   !remove_item_from_application_menur   ToolbarsMenur   r4   r   ShowToolbarsr7   s     r   on_main_menu_teardownzToolbar.on_main_menu_teardownJ   st    ??7#34422%$) 	3 	+ 	+ 	+ 	22'$) 	3 	+ 	+ 	+ 	+ 	+r   c           	         |                                  }t          j        | j        j        t          j        | j        j        t          j        | j        j        i}|	                                D ]\}|j
        }||v r;d}||         D ]0}||dz  }
|                     ||t          |          d           1|                                 ]|                                 |                                 d S )Nr      T)
toolbar_idr.   omit_id)get_containerr   r%   _mainfile_toolbar_actionsr'   debug_toolbar_actionsr&   run_toolbar_actionsget_application_toolbarsIDadd_item_to_application_toolbarstr_rendercreate_toolbars_menuload_last_visible_toolbars)r   	container
ACTION_MAPr   rA   r.   items          r   on_mainwindow_visiblezToolbar.on_mainwindow_visibleU   s   &&((	  $dj&E%tz'G#TZ%C


 !99;; 	 	G JZ''&z2 
 
D|1 88#- #G $	 9     OO&&(((,,.....r   c                     |                                  }|                                 |j        D ]}|                    d           d S )NF)rC   save_last_visible_toolbars_visible_toolbars
setVisible)r   _unusedrO   r   s       r   on_closezToolbar.on_closes   sX    &&((	,,... 2 	& 	&Gu%%%%	& 	&r   c                     |                                                      ||          }|                     |           |S )aw  
        Create a Spyder application toolbar.

        Parameters
        ----------
        toolbar_id: str
            The toolbar unique identifier string.
        title: str
            The localized toolbar title to be displayed.

        Returns
        -------
        spyder.api.widgets.toolbar.ApplicationToolbar
            The created application toolbar.
        )rC   r$   add_application_toolbar)r   rA   titler   s       r   r$   z"Toolbar.create_application_toolbar{   sC      $$&&AA $$W---r   c                 `    |                                                      || j                   dS )aL  
        Add toolbar to application toolbars.

        This can be used to add a custom toolbar. The `WorkingDirectory`
        plugin is an example of this.

        Parameters
        ----------
        toolbar: spyder.api.widgets.toolbars.ApplicationToolbar
            The application toolbar to add to the main window.
        N)rC   rZ   rD   )r   r   s     r   rZ   zToolbar.add_application_toolbar   s.     	44WdjIIIIIr   rA   c                 `    |                                                      || j                   dS )a2  
        Remove toolbar from the application toolbars.

        This can be used to remove a custom toolbar. The `WorkingDirectory`
        plugin is an example of this.

        Parameters
        ----------
        toolbar: str
            The application toolbar to remove from the main window.
        N)rC   remove_application_toolbarrD   r   rA   s     r   r^   z"Toolbar.remove_application_toolbar   s.     	77
DJOOOOOr   NrQ   r.   beforer/   rB   c                     |$t          |t                    st          d          |                                                     ||||||          S )aa  
        Add action or widget `item` to given application menu `section`.

        Parameters
        ----------
        item: SpyderAction or QWidget
            The item to add to the `toolbar`.
        toolbar_id: str or None
            The application toolbar unique string identifier.
        section: str or None
            The section id in which to insert the `item` on the `toolbar`.
        before: str or None
            Make the item appear before another given item.
        before_section: str or None
            Make the item defined section appear before another given section
            (must be already defined).
        omit_id: bool
            If True, then the toolbar 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
        Nzbefore argument must be a str)rA   r.   r`   r/   rB   )
isinstancerK   
ValueErrorrC   rJ   )r   rQ   rA   r.   r`   r/   rB   s          r   rJ   z'Toolbar.add_item_to_application_toolbar   sh    8 fc** B !@AAA!!##CC%- D   	r   item_idc                 X    |                                                      ||           dS )a  
        Remove action or widget `item` from given application menu by id.

        Parameters
        ----------
        item_id: str
            The item to remove from the toolbar.
        toolbar_id: str or None
            The application toolbar unique string identifier.
        )rA   N)rC   $remove_item_from_application_toolbar)r   rd   rA   s      r   rf   z,Toolbar.remove_item_from_application_toolbar   s>     	AA! 	B 	
 	
 	
 	
 	
r   c                 P    |                                                      |          S )a,  
        Return an application toolbar by toolbar_id.

        Parameters
        ----------
        toolbar_id: str
            The toolbar unique string identifier.

        Returns
        -------
        spyder.api.widgets.toolbars.ApplicationToolbar
            The application toolbar.
        )rC   get_application_toolbarr_   s     r   rh   zToolbar.get_application_toolbar   s$     !!##;;JGGGr   c                 F    | j         D ]}|                    |            dS )zLock/Unlock toolbars.N)toolbarslist
setMovable)r   valuer   s      r   toggle_lockzToolbar.toggle_lock   s7    ( 	* 	*G5y))))	* 	*r   c                 P    |                                                      d          S )Nr3   )rC   get_menur   s    r   r3   zToolbar.toolbars_menu   s"    !!##,,_===r   c                 ,    |                      d          S )Nzshow toolbars)
get_actionr   s    r   r6   zToolbar.show_toolbars_action   s    ///r   c                 4    |                                  j        S N)rC   _toolbarslistr   s    r   rj   zToolbar.toolbarslist  s    !!##11r   )NNNNFrs   ))__name__
__module____qualname____doc__NAMEr   r1   OPTIONALCONF_SECTION	CONF_FILEr   CONTAINER_CLASSCAN_BE_DISABLEDstaticmethodr   r   r"   r*   r   r9   r	   r>   rR   rX   r$   rZ   rK   r^   r   r   r   r   boolrJ   rf   rh   rm   propertyr3   r6   rj   r   r   r   r   r      sr         D !HLI&OO   \5 5 5( ( (H H H  01114 4 214 w/000+ + 10+/ / /<& & &  *J J JPS P P P P  EIAE@DHL8=' '.3L'4I.J'4<SM' 2:#' 19	'
 9A' 26' ' ' 'T JN
 
C 
9A#
 
 
 
"H H H * * * * > > X> 0 0 X0 2 2 X2 2 2r   r   N)rx   spyder.utils.qthelpersr   typingr   r   spyder.api.pluginsr   r   )spyder.api.plugin_registration.decoratorsr   r	   spyder.api.translationsr   spyder.plugins.mainmenu.apir   r   spyder.plugins.toolbar.apir    spyder.plugins.toolbar.containerr   r   r   qtpy.QtWidgetsr   r   r   r   r   <module>r      s=   
 0 / / / / / " " " " " " " " 7 6 6 6 6 6 6 6- - - - - - - - % % % % % % J J J J J J J J : : : : : :4 4 4 4 4 4 4 4 4 4 # " " " " "i2 i2 i2 i2 i2n i2 i2 i2 i2 i2r   