
    Je"                         d Z ddlZddlZddlmZmZm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 ddlmZmZ  G d d      Z G d de      Zy)z
Shortcuts Plugin.
    N)QtSignalSlot)QKeySequence)QAction	QShortcut)PluginsSpyderPluginV2)on_plugin_availableon_plugin_teardown_)ApplicationMenusHelpMenuSections)ShortcutsConfigPage)ShortcutsSummaryDialog)add_shortcut_to_tooltipSpyderActionc                       e Zd ZdZy)ShortcutActionsshow_shortcut_summary_actionN)__name__
__module____qualname__ShortcutSummaryAction     A/usr/lib/python3/dist-packages/spyder/plugins/shortcuts/plugin.pyr   r   !   s    :r   r   c                      e Zd ZdZdZej                  gZej                  gZ	e
ZeZdZdZ e       Z	 ed        Zd Zd Zd Z eej                        d	        Z eej                        d
        Z eej                        d        Z eej                        d        Zd Zd Zd Z e       d        Z 	 ddZ!	 ddZ"d Z#ddZ$ddZ%y)	Shortcutsz
    Shortcuts Plugin.
    	shortcutsFc                      t        d      S )NzKeyboard shortcutsr   r   r   r   get_namezShortcuts.get_name>   s    %&&r   c                     t        d      S )Nz1Manage application, widget and actions shortcuts.r   selfs    r   get_descriptionzShortcuts.get_descriptionB   s    DEEr   c                 $    | j                  d      S )Nkeyboard)create_iconr%   s    r   get_iconzShortcuts.get_iconE   s    
++r   c                     g | _         | j                  t        j                  t	        d      | j
                  dt        j                         y )NzShortcuts SummaryT)text	triggeredregister_shortcutcontext)_shortcut_datacreate_actionr   r   r   show_summaryr   ApplicationShortcutr%   s    r   on_initializezShortcuts.on_initializeH   sD     11&'''"** 	 	
r   )pluginc                 d    | j                  t        j                        }|j                  |        y N)
get_pluginr	   Preferencesregister_plugin_preferencesr&   preferencess     r   on_preferences_availablez"Shortcuts.on_preferences_availableR   s$    oog&9&9://5r   c                     | j                  t        j                        }| j                  t        j
                        }|j                  |t        j                  t        j                  t        j                         y )N)menu_idsectionbefore_section)r9   r	   MainMenu
get_actionr   r   add_item_to_application_menur   Helpr   DocumentationSupport)r&   mainmenushortcuts_actions      r   on_main_menu_availablez Shortcuts.on_main_menu_availableW   sa    ??7#3#34??113 	--$))$22+33	 	. 	
r   c                 d    | j                  t        j                        }|j                  |        y r8   )r9   r	   r:   deregister_plugin_preferencesr<   s     r   on_preferences_teardownz!Shortcuts.on_preferences_teardowne   s$    oog&9&9:11$7r   c                     | j                  t        j                        }|j                  t        j
                  t        j                         y )N)r@   )r9   r	   rC   !remove_item_from_application_menur   r   r   rF   )r&   rI   s     r   on_main_menu_teardownzShortcuts.on_main_menu_teardownj   s;    ??7#3#342211$)) 	3 	
r   c                 $    | j                          y r8   )apply_shortcutsr%   s    r   on_mainwindow_visiblezShortcuts.on_mainwindow_visibler   s    r   c                     | j                   S )zW
        Return the registered shortcut data from the main application window.
        )r1   r%   s    r   get_shortcut_datazShortcuts.get_shortcut_dataw   s     """r   c                 R    | j                   r| j                   j                          yy)zReset shrotcuts.N)_confreset_shortcutsr%   s    r   rY   zShortcuts.reset_shortcuts}   s    ::JJ&&( r   c                 :    t        d      }|j                          y)zReset shortcuts.N)r   exec_)r&   dlgs     r   r3   zShortcuts.show_summary   s     %T*		r   Nc                 D    | j                   j                  |||||f       y)zz
        Register QAction or QShortcut to Spyder main application,
        with shortcut (context, name, default)
        N)r1   append)r&   qaction_or_qshortcutr0   nameadd_shortcut_to_tipplugin_names         r   r/   zShortcuts.register_shortcut   s,     	""$8'#')<k$K 	Lr   c                 f    |||||f}|| j                   v r| j                   j                  |       yy)zO
        Unregister QAction or QShortcut from Spyder main application.
        N)r1   remove)r&   r_   r0   r`   ra   rb   datas          r   unregister_shortcutzShortcuts.unregister_shortcut   sA    
 %gt5H 4&&&&&t, 'r   c                 F   g }t        | j                        D ]  \  }\  }}}}}	 | j                  |||      }|rt        |      }	n
t               }	|j                  d      rt        |t              r
t               }		 t        |t              rKt        j                  dk(  r|j                  dk(  r|	|_        n|j                  |	       |r/t!        |||       n!t        |t"              r|j%                  |	        t+        |d      D ]  }| j                  j-                  |        | j.                  j1                          y# t        j                  t        j
                  f$ r | j                  ||d|       d}Y Fw xY w# t&        $ r |j)                  |       Y w xY w)zB
        Apply shortcuts settings to all widgets/plugins.
         z	switch todarwinmissingT)reverseN)	enumerater1   get_shortcutconfigparserNoSectionErrorNoOptionErrorset_shortcutr   
startswith
isinstancer   r   sysplatform_shown_shortcutsetShortcutr   r   setKeyRuntimeErrorr^   sortedpopsig_shortcuts_updatedemit)
r&   toberemovedindexqobjectr0   r`   ra   rb   shortcut_sequencekeyseqs
             r   rS   zShortcuts.apply_shortcuts   s     %.d.A.A$B(	* !E !GWd,?'$($5$5gt6A%C! !%&78 &
 ,"7L9%*gw/0 ' 7 79 D28/++F3*/$G3NN6*K(	*T K6 	+E##E*	+ 	""'')Q !//1K1KL ' !!'4[A$&!'B   *""5)*s$   E<A<F9E?>E?F F c                 >    | j                   j                  |||      S )a  
        Get keyboard shortcut (key sequence string).

        Parameters
        ----------
        context:
            Context must be either '_' for global or the name of a plugin.
        name: str
            Name of the shortcut.
        plugin_id: spyder.api.plugins.SpyderpluginV2 or None
            The plugin for which the shortcut is registered. Default is None.

        Returns
        -------
        Shortcut
            A shortcut object.
        rb   )rX   rm   )r&   r0   r`   rb   s       r   rm   zShortcuts.get_shortcut   s     $ zz&&w+&NNr   c                 B    | j                   j                  ||||       y)a  
        Set keyboard shortcut (key sequence string).

        Parameters
        ----------
        context:
            Context must be either '_' for global or the name of a plugin.
        name: str
            Name of the shortcut.
        keystr: str
            Shortcut keys in string form.
        plugin_id: spyder.api.plugins.SpyderpluginV2 or None
            The plugin for which the shortcut is registered. Default is None.
        r   N)rX   rq   )r&   r0   r`   keystr	plugin_ids        r   rq   zShortcuts.set_shortcut   s     	

v9Mr   )TNr8   )&r   r   r   __doc__NAMEr	   r:   REQUIRESrC   OPTIONALr   CONF_WIDGET_CLASSCONF_SECTION	CONF_FILECAN_BE_DISABLEDr   r|   staticmethodr#   r'   r+   r5   r   r>   rK   r   rN   rQ   rT   rV   rY   r   r3   r/   rf   rS   rm   rq   r   r   r   r    r    '   s>    D##$H  !H+LIO #H ' 'F,
  3 346 56  0 01
 2
 w2238 48 w//0
 1

#)
 
V  AEL CG	-6*pO(Nr   r    ) r   rn   rt   qtpy.QtCorer   r   r   
qtpy.QtGuir   qtpy.QtWidgetsr   r   spyder.api.pluginsr	   r
   )spyder.api.plugin_registration.decoratorsr   r   spyder.api.translationsr   spyder.plugins.mainmenu.apir   r   !spyder.plugins.shortcuts.confpager   (spyder.plugins.shortcuts.widgets.summaryr   spyder.utils.qthelpersr   r   r   r    r   r   r   <module>r      sS   
  
 ) ( # - 7- % J A K H; ;PN PNr   