
    G@dOI                         d 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
 ddlmZ  G d de	          Z G d	 d
e          Z G d dee
          Z G d dee          ZdS )z
Old API for plugins.

These plugins were supported until Spyder 4, but they will be deprecated in
the future. Please don't rely on them for new plugins and use instead the
classes present in new_api.py
    )SignalSlot)QWidget)	NoDefault)BasePluginMixinBasePluginWidgetMixin)imac                       e Zd ZdZ eee          Z eee          Z	d fd	Z
 ee           eee          d fd	                        Z eee          	 	 d fd	            Zedf fd	Zd fd		Z fd
Zd fd	Z xZS )
BasePluginzv
    Basic functionality for Spyder plugins.

    WARNING: Don't override any methods or attributes present here!
    Nc                    t          t          |                               |           || _        |                                 | _        | j                            | j                   | j	                            | j
                   d S N)superr   __init__main_get_plugin_pathPLUGIN_PATHsig_show_status_messageconnectshow_status_messagesig_option_changed
set_option)selfparent	__class__s     :lib/python3.11/site-packages/spyder/api/plugins/old_api.pyr   zBasePlugin.__init__+   s{    j$((000 	  0022 	$,,T-EFFF''88888    r   c                 Z    t          t          |                               ||           dS )z
        Show message in main window's status bar.

        Parameters
        ----------
        message: str
            Message to display in the status bar.
        timeout: int
            Amount of time to display the message.
        N)r   r   _show_status_message)r   messagetimeoutr   s      r   r   zBasePlugin.show_status_message:   s+     	j$44WgFFFFFr   Tc                 `    t          t          |                               ||||           dS )a  
        Set an option in Spyder configuration file.

        Parameters
        ----------
        option: str
            Name of the option (e.g. 'case_sensitive')
        value: bool, int, str, tuple, list, dict
            Value to save in configuration file, passed as a Python
            object.

        Notes
        -----
        * Use sig_option_changed to call this method from widgets of the
          same or another plugin.
        * CONF_SECTION needs to be defined for this to work.
        )sectionrecursive_notificationN)r   r   _set_option)r   optionvaluer"   r#   r   s        r   r   zBasePlugin.set_optionI   s@    ( 	j$++E7#9 	, 	; 	; 	; 	; 	;r   c                 Z    t          t          |                               |||          S )a'  
        Get an option from Spyder configuration file.

        Parameters
        ----------
        option: str
            Name of the option to get its value from.

        Returns
        -------
        bool, int, str, tuple, list, dict
            Value associated with `option`.
        r"   )r   r   _get_option)r   r%   defaultr"   r   s       r   
get_optionzBasePlugin.get_optiona   s6     Z&&2267;B 3 D D 	Dr   c                 X    t          t          |                               ||          S )aE  
        Remove an option from the Spyder configuration file.

        Parameters
        ----------
        option: Union[str, Tuple[str, ...]]
            A string or a Tuple of strings containing an option name to remove.
        section: Optional[str]
            Name of the section where the option belongs to.
        r(   )r   r   _remove_option)r   r%   r"   r   s      r   remove_optionzBasePlugin.remove_optionr   s(     Z&&55fg5NNNr   c                 X    t          t          |                               |           dS )a  
        Show a message in main window's status bar and changes the
        mouse to Qt.WaitCursor when starting a long process.

        Parameters
        ----------
        message: str
            Message to show in the status bar when the long
            process starts.
        N)r   r   _starting_long_processr   r   r   s     r   starting_long_processz BasePlugin.starting_long_process   s)     	j$66w?????r    c                 X    t          t          |                               |           dS )a  
        Clear main window's status bar after a long process and restore
        mouse to the OS deault.

        Parameters
        ----------
        message: str
            Message to show in the status bar when the long process
            finishes.
        N)r   r   _ending_long_processr1   s     r   ending_long_processzBasePlugin.ending_long_process   s)     	j$44W=====r   r   )r   )NT)r3   )__name__
__module____qualname____doc__r   strintr   objectr   r   r   r   r   r   r+   r.   r2   r6   __classcell__r   s   @r   r   r      s         %fS#..  V,,9 9 9 9 9 9 
T#YY	T#s^^G G G G G ^ YG 
T#v04*.; ; ; ; ; ;. *3D D D D D D D"O O O O O O@ @ @ @ @> > > > > > > > > >r   r   c                   0    e Zd ZdZdZdZdZdZdZdZ	d Z
dS )SpyderPluginzh
    Spyder plugin class.

    All plugins *must* inherit this class and reimplement its interface.
    NTc                     d}d}||fS )a	  
        This method can be reimplemented to check compatibility of a
        plugin for a given condition.

        Returns
        -------
        (bool, str)
            The first value tells Spyder if the plugin has passed the
            compatibility test defined in this method. The second value
            is a message that must explain users why the plugin was
            found to be incompatible (e.g. 'This plugin does not work
            with PyQt4'). It will be shown at startup in a QMessageBox.
        r3   T )r   r   valids      r   check_compatibilityz SpyderPlugin.check_compatibility   s     g~r   )r7   r8   r9   r:   CONF_SECTIONDESCRIPTIONCONFIGWIDGET_CLASS	CONF_FILECONF_DEFAULTSCONF_VERSIONrE   rC   r   r   rA   rA      sX          L K  I M L    r   rA   c                        e Zd ZdZ e            ZddZ fdZ fdZd fd	Z		 ddZ
	 dd	Zd
 Zd Z fdZ fdZ xZS )BasePluginWidgetz}
    Basic functionality for Spyder plugin widgets.

    WARNING: Don't override any methods or attributes present here!
    Nc                 f    t          j        |            t          j        | |           d | _        d S r   )r   r   r   
dockwidget)r   r   s     r   r   zBasePluginWidget.__init__   s3    &tT222 r   c                 V    t          t          |                                            dS )z0Add the plugin's QDockWidget to the main window.N)r   rM   _add_dockwidgetr   r   s    r   add_dockwidgetzBasePluginWidget.add_dockwidget   s&    %%5577777r   c                 X    t          t          |                               |           dS )a&  
        Tabify plugin next to one of the core plugins.

        Parameters
        ----------
        core_plugin: SpyderPluginWidget
            Core Spyder plugin this one will be tabified next to.

        Examples
        --------
        >>> self.tabify(self.main.variableexplorer)
        >>> self.tabify(self.main.ipyconsole)

        Notes
        -----
        The names of variables associated with each of the core plugins
        can be found in the `setup` method of `MainWindow`, present in
        `spyder/app/mainwindow.py`.
        N)r   rM   _tabify)r   core_pluginr   s     r   tabifyzBasePluginWidget.tabify   s*    ( 	%%--k:::::r   Fc                 T    t          t          |                               |          S )a  
        Return plain or rich text font used in Spyder.

        Parameters
        ----------
        rich_text: bool
            Return rich text font (i.e. the one used in the Help pane)
            or plain text one (i.e. the one used in the Editor).

        Returns
        -------
        QFont:
            QFont object to be passed to other Qt widgets.

        Notes
        -----
        All plugins in Spyder use the same, global font. This is a
        convenience method in case some plugins want to use a delta
        size based on the default one. That can be controlled by using
        FONT_SIZE_DELTA or RICH_FONT_SIZE_DELTA (declared below in
        `SpyderPluginWidget`).
        )r   rM   	_get_font)r   	rich_textr   s     r   get_fontzBasePluginWidget.get_font  s$    . %t,,66yAAAr   c                 L    | j                             ||||| j                   dS )a  
        Register a shortcut associated to a QAction or a QShortcut to
        Spyder main application.

        Parameters
        ----------
        qaction_or_qshortcut: QAction or QShortcut
            QAction to register the shortcut for or QShortcut.
        context: str
            Name of the plugin this shortcut applies to. For instance,
            if you pass 'Editor' as context, the shortcut will only
            work when the editor is focused.
            Note: You can use '_' if you want the shortcut to be work
            for the entire application.
        name: str
            Name of the action the shortcut refers to (e.g. 'Debug
            exit').
        add_shortcut_to_tip: bool
            If True, the shortcut is added to the action's tooltip.
            This is useful if the action is added to a toolbar and
            users hover it to see what it does.
        N)r   register_shortcutrF   r   qaction_or_qshortcutcontextnameadd_shortcut_to_tips        r   r]   z"BasePluginWidget.register_shortcut,  s:    0 		## 	 	 	 	 	r   c                 L    | j                             ||||| j                   dS )a  
        Unregister a shortcut associated to a QAction or a QShortcut to
        Spyder main application.

        Parameters
        ----------
        qaction_or_qshortcut: QAction or QShortcut
            QAction to register the shortcut for or QShortcut.
        context: str
            Name of the plugin this shortcut applies to. For instance,
            if you pass 'Editor' as context, the shortcut will only
            work when the editor is focused.
            Note: You can use '_' if you want the shortcut to be work
            for the entire application.
        name: str
            Name of the action the shortcut refers to (e.g. 'Debug
            exit').
        add_shortcut_to_tip: bool
            If True, the shortcut is added to the action's tooltip.
            This is useful if the action is added to a toolbar and
            users hover it to see what it does.
        N)r   unregister_shortcutrF   r^   s        r   rd   z$BasePluginWidget.unregister_shortcutK  s:    0 		%% 	 	 	 	 	r   c                 j    |                                 D ]\  }}}|                     |||           dS )a  
        Register shortcuts defined by a plugin's widget so they take
        effect when the plugin is focused.

        Parameters
        ----------
        widget: QWidget
            Widget to register shortcuts for.

        Notes
        -----
        The widget interface must have a method called
        `get_shortcut_data` for this to work. Please see
        `spyder/widgets/findreplace.py` for an example.
        N)get_shortcut_datar]   r   widget	qshortcutr`   ra   s        r   register_widget_shortcutsz*BasePluginWidget.register_widget_shortcutsj  sK      )/(@(@(B(B 	= 	=$Iw""9gt<<<<	= 	=r   c                 j    |                                 D ]\  }}}|                     |||           dS )av  
        Unregister shortcuts defined by a plugin's widget.

        Parameters
        ----------
        widget: QWidget
            Widget to register shortcuts for.

        Notes
        -----
        The widget interface must have a method called
        `get_shortcut_data` for this to work. Please see
        `spyder/widgets/findreplace.py` for an example.
        N)rf   rd   rg   s        r   unregister_widget_shortcutsz,BasePluginWidget.unregister_widget_shortcuts}  sK     )/(@(@(B(B 	? 	?$Iw$$Y>>>>	? 	?r   c                 R    t          t          |                                           S )aJ  
        Get the current color scheme.

        Returns
        -------
        dict
            Dictionary with properties and colors of the color scheme
            used in the Editor.

        Notes
        -----
        This is useful to set the color scheme of all instances of
        CodeEditor used by the plugin.
        )r   rM   _get_color_schemerR   s    r   get_color_schemez!BasePluginWidget.get_color_scheme  s"     %t,,>>@@@r   c                 V    t          t          |                                            dS )z
        Switch to this plugin.

        Notes
        -----
        This operation unmaximizes the current plugin (if any), raises
        this plugin to view (if it's hidden) and gives it focus (if
        possible).
        N)r   rM   _switch_to_pluginrR   s    r   switch_to_pluginz!BasePluginWidget.switch_to_plugin  s(     	%%7799999r   r   F)r7   r8   r9   r:   r   sig_update_plugin_titler   rS   rW   r[   r]   rd   rj   rl   ro   rr   r>   r?   s   @r   rM   rM      s)         %fhh   8 8 8 8 8; ; ; ; ;,B B B B B B4 /4   @ 16   >= = =&? ? ?$A A A A A"
: 
: 
: 
: 
: 
: 
: 
: 
:r   rM   c                   p    e Zd ZdZdZdZdZdZdZd Z	d Z
d Zdd
Zd Zd Zd Zd Zd Zd Zd Zd ZdS )SpyderPluginWidgetzv
    Spyder plugin widget class.

    All plugin widgets *must* inherit this class and reimplement its interface.
    imagesr   TNc                     t           )zr
        Get plugin's title.

        Returns
        -------
        str
            Name of the plugin.
        NotImplementedErrorr   s    r   get_plugin_titlez#SpyderPluginWidget.get_plugin_title  s
     "!r   c                 *    t          j        d          S )zy
        Get plugin's associated icon.

        Returns
        -------
        QIcon
            QIcon instance
        outline_explorer)r	   iconr{   s    r   get_plugin_iconz"SpyderPluginWidget.get_plugin_icon  s     x*+++r   c                     dS )z
        Get the plugin widget to give focus to.

        Returns
        -------
        QWidget
            QWidget to give focus to.

        Notes
        -----
        This is applied when plugin's dockwidget is raised on top-level.
        NrC   r{   s    r   get_focus_widgetz#SpyderPluginWidget.get_focus_widget  s	     	r   Fc                     dS )a  
        Perform actions before the main window is closed.

        Returns
        -------
        bool
            Whether the plugin may be closed immediately or not.

        Notes
        -----
        The returned value is ignored if *cancelable* is False.
        TrC   )r   
cancelables     r   closing_pluginz!SpyderPluginWidget.closing_plugin  s	     tr   c                     dS )z
        Refresh plugin after it receives focus.

        Notes
        -----
        For instance, this is used to maintain in sync the Variable
        Explorer with the currently focused IPython console.
        NrC   r{   s    r   refresh_pluginz!SpyderPluginWidget.refresh_plugin  s	     	r   c                     g S )z
        Return a list of QAction's related to plugin.

        Notes
        -----
        These actions will be shown in the plugins Options menu (i.e.
        the hambuger menu on the right of each plugin).
        rC   r{   s    r   get_plugin_actionsz%SpyderPluginWidget.get_plugin_actions  s	     	r   c                 .    |                                   dS )a   
        Register plugin in Spyder's main window and connect it to other
        plugins.

        Notes
        -----
        Below is the minimal call necessary to register the plugin. If
        you override this method, please don't forget to make that call
        here too.
        N)rS   r{   s    r   register_pluginz"SpyderPluginWidget.register_plugin  s     	r   c                     t           )z
        Action to be performed on first plugin registration.

        Notes
        -----
        This is mostly used to tabify the plugin next to one of the
        core plugins, like this:

        self.tabify(self.main.variableexplorer)
        ry   r{   s    r   on_first_registrationz(SpyderPluginWidget.on_first_registration$  s
     "!r   c                     dS )zN
        Determine what to do to apply configuration plugin settings.
        NrC   )r   optionss     r   apply_plugin_settingsz(SpyderPluginWidget.apply_plugin_settings1  	     	r   c                     dS )z`
        This must be reimplemented by plugins that need to adjust
        their fonts.
        NrC   r{   s    r   update_fontzSpyderPluginWidget.update_font7  s	    
 	r   c                     | j         sdS |r4| j                                          | j                                          dS | j                                          dS )a  
        Toggle dockwidget's visibility when its entry is selected in
        the menu `View > Panes`.

        Parameters
        ----------
        checked: bool
            Is the entry in `View > Panes` checked or not?

        Notes
        -----
        Redefining this method can be useful to execute certain actions
        when the plugin is made visible. For an example, please see
        `spyder/plugins/ipythonconsole/plugin.py`
        N)rO   showraise_hide)r   checkeds     r   toggle_viewzSpyderPluginWidget.toggle_view>  sc       	F 	#O  """O""$$$$$O  """""r   c                     dS )zW
        Needed to update the ancestor/parent of child widgets when undocking.
        NrC   )r   ancestors     r   set_ancestorzSpyderPluginWidget.set_ancestorV  r   r   rs   )r7   r8   r9   r:   IMG_PATHFONT_SIZE_DELTARICH_FONT_SIZE_DELTADISABLE_ACTIONS_WHEN_HIDDENshortcutr|   r   r   r   r   r   r   r   r   r   r   r   rC   r   r   rv   rv     s          H
 O
 #' H	" 	" 	"	, 	, 	,     	 	 		 	 	  " " "    # # #0    r   rv   N)r:   qtpy.QtCorer   r   qtpy.QtWidgetsr   spyder.config.userr   spyder.plugins.baser   r   spyder.utils.icon_managerr	   r   rA   rM   rv   rC   r   r   <module>r      sV    % $ $ $ $ $ $ $ " " " " " " ) ( ( ( ( ( F F F F F F F F ) ) ) ) ) ){> {> {> {> {> {> {> {>|E E E E E: E E EVE: E: E: E: E:w 5 E: E: E:Pm m m m m'7 m m m m mr   