
    Je#                         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y)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(y)!Toolbarz#
    Docstrings viewer widget.
    toolbarFc                      t        d      S )Nr   r
        ?/usr/lib/python3/dist-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4r   c                 $    | j                  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             y )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   sf    !<<.33Q~5FG.22Am4DE.44a6HI.33Q~5FGr   )pluginc                 f   | j                  t        j                        }|j                  | j                  t
        j                  t        j                  t        j                         |j                  | j                  t
        j                  t        j                  t        j                         y )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#34--$))$,,+22	 	. 	4
 	--%%$))$,,+22	 	. 	4r   c                     | j                  t        j                        }|j                  t        j
                  t        j                         |j                  t        j                  t        j                         y )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   sb    ??7#3#3422%%$)) 	3 	+ 	22''$)) 	3 	+r   c           	         | j                         }t        j                  | j                  j                  t        j
                  | j                  j                  t        j                  | j                  j                  i}|j                         D ]T  }|j                  }||v r2d}||   D ](  }||dz  }| j                  ||t        |      d       * |j                          V |j                          |j                          y )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    &&(	  $$djj&E&E%%tzz'G'G##TZZ%C%C


 !99; 	G JZ'&z2 
D|1 88#- #G $	 9 
 OO!	$ 	&&(,,.r   c                     | j                         }|j                          |j                  D ]  }|j                  d        y )NF)rC   save_last_visible_toolbars_visible_toolbars
setVisible)r   _unusedrO   r   s       r   on_closezToolbar.on_closes   s?    &&(	,,. 22 	&Gu%	&r   c                 h    | j                         j                  ||      }| j                  |       |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{   s5      $$&AA$$W-r   c                 X    | j                         j                  || j                         y)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4WdjjIr   rA   c                 X    | j                         j                  || j                         y)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
DJJOr   NrQ   r.   beforer/   rB   c                     |t        |t              st        d      | j                         j	                  ||||||      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
        z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   sT    8 fc* !@AA!!#CC%- D  	r   item_idc                 F    | j                         j                  ||       y)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                 @    | j                         j                  |      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Gr   c                 J    | j                   D ]  }|j                  |         y)zLock/Unlock toolbars.N)toolbarslist
setMovable)r   valuer   s      r   toggle_lockzToolbar.toggle_lock   s'    (( 	*G5y)	*r   c                 @    | j                         j                  d      S )Nr3   )rC   get_menur   s    r   r3   zToolbar.toolbars_menu   s    !!#,,_==r   c                 $    | j                  d      S )Nzshow toolbars)
get_actionr   s    r   r6   zToolbar.show_toolbars_action   s    //r   c                 6    | j                         j                  S N)rC   _toolbarslistr   s    r   rj   zToolbar.toolbarslist  s    !!#1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      s    D  !HLI&OO  5(H  0 014 24 w//0+ 1+/<&*JPS P  EIAE@DHL8='.3L'4I.J'4<SM' 2:#' 19	'
 9A' 26'T JN
C 
9A#
"H * > > 0 0 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      sB   
 0 " 7- % J :4 4 #i2n i2r   