
    G@d                         d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZ ee         Z G d d	e          Z G d
 de          ZdS )zL
API to create an entry in Spyder Preferences associated to a given plugin.
    N)Set)CONF)ConfigurationKey)PrefixedTuple)SpyderConfigPageBaseConfigTabc                   N     e Zd ZdZdZdef fdZdefdZde	fdZ
 fdZ xZS )	SpyderPreferencesTabz
    Widget that represents a tab on a preference page.

    All calls to :class:`SpyderConfigPage` attributes are resolved
    via delegation.
    Nparentc                     t                                          |           || _        | j        t	          | j        t
                    st          d          d S )NzTITLE must be a str)super__init__r   TITLE
isinstancestr
ValueError)selfr   	__class__s     6lib/python3.11/site-packages/spyder/api/preferences.pyr   zSpyderPreferencesTab.__init__$   sR       :Z
C%@%@2333     returnc                      t          i           S )z
        Hook called to manually apply settings that cannot be automatically
        applied.

        Reimplement this if the configuration tab has complex widgets that
        cannot be created with any of the `self.create_*` calls.
        setr   s    r   apply_settingsz#SpyderPreferencesTab.apply_settings+   s     2wwr   c                     dS )z}
        Return True if the tab contents are valid.

        This method can be overriden to perform complex checks.
        T r   s    r   is_validzSpyderPreferencesTab.is_valid5   s	     tr   c                     t          |           }||vrt          | j        |          S t                                          |          S N)dirgetattrr   r   __getattr__)r   attrthis_class_dirr   s      r   r$   z SpyderPreferencesTab.__getattr__=   sC    T~%%4;---77&&t,,,r   )__name__
__module____qualname____doc__r   r   r   	OptionSetr   boolr   r$   __classcell__)r   s   @r   r
   r
      s          E4/ 4 4 4 4 4 4	    $    - - - - - - - - -r   r
   c                   L    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
efdZdS )PluginConfigPagezx
    Widget to expose the options a plugin offers for configuration as
    an entry in Spyder's Preferences dialog.
    Fc                     || _         |j        | _        t          |d          r|j        | _        t          |d          r|j        | _        | j        s|                     |           t          j        | |           d S )NCONF_SECTIONget_font)	pluginmainhasattrr1   r2   APPLY_CONF_PAGE_SETTINGS_patch_apply_settingsr   r   )r   r3   r   s      r   r   zPluginConfigPage.__init__P   s    K	6>** 	4 & 3D6:&& 	,"ODM, 	/&&v...!$/////r   c                 8    fd}t          j        ||           S )z
        Wrap apply_settings call to ensure that a user-defined custom call
        is called alongside the Spyder Plugin API configuration propagation
        call.
        c                     |                                  pt          i           }||z  }|                     |            |           d S r!   )previous_apply_settingsr   aggregate_sections_partials)r   optionsoptsfuncs      r   wrapperz6PluginConfigPage._wrap_apply_settings.<locals>.wrappere   sM    //11<SWWDGOD,,T222DJJJJJr   )types
MethodType)r   r>   r?   s    ` r   _wrap_apply_settingsz%PluginConfigPage._wrap_apply_settings_   s1    	 	 	 	 	
 ...r   c                 N   | j         | _        	 |                     |j                  | _         |j        | _        |j        | _        |j        | _	        d S # t          $ rG |                     |j                  | _         |j        | _        |j        | _        |j	        | _	        Y d S w xY wr!   )r   r:   rB   
apply_confget_conf
get_optionset_conf
set_optionremove_confremove_optionAttributeErrorapply_plugin_settings)r   r3   s     r   r7   z&PluginConfigPage._patch_apply_settingsl   s    '+':$	6"&";";F<M"N"ND$oDO$oDO!'!3D 	6 	6 	6"&";";,#. #.D$/DO$/DO!'!5D	6s   AA AB$#B$c                 J   i }|D ]}t          |t                    r#t          |          dk    r|d         |d         }| j        }|| j        v r| j        |         }|                    |g           }|                    |           |||<   |D ]}t                      }t          j	        |dd           ||         D ]6}t          |t                    r|dd         }|
                    |           7|D ]*}	 t          j	        ||d           # t          $ r Y 'w xY wdS )	z;Aggregate options by sections in order to notify observers.   r   N   	__sectionF)recursive_notification)r   tuplelenr1   cross_section_optionsgetappendr   r   notify_observersadd_path	Exception)r   r=   	to_updateoptsectionsection_optionssection_prefixprefixs           r   r;   z,PluginConfigPage.aggregate_sections_partials|   s   	 	1 	1C#u%% ! s88q==SV^a&C'Gd0004S9'mmGR88O""3'''!0Ig  	 	G*__N!';9>@ @ @ @ ) 1 1c5)) 1crc(C"++C000(  )'6AFH H H H H    D		 	s   :D
DDc                     	 | j                                         }n)# t          $ r | j                                         }Y nw xY w|S )z
        Return plugin name to use in preferences page title, and
        message boxes.

        Normally you do not have to reimplement it, as soon as the
        plugin name in preferences page will be the same as the plugin
        title.
        )r3   get_namerK   get_plugin_title)r   names     r   rb   zPluginConfigPage.get_name   sU    	2;''))DD 	2 	2 	2;//11DDD	2     #AAc                     	 | j                                         }n)# t          $ r | j                                         }Y nw xY w|S )z
        Return plugin icon to use in preferences page.

        Normally you do not have to reimplement it, as soon as the
        plugin icon in preferences page will be the same as the plugin
        icon.
        )r3   get_iconrK   get_plugin_icon)r   icons     r   rg   zPluginConfigPage.get_icon   sU    	1;''))DD 	1 	1 	1;..00DDD	1 re   c                     t           )z
        Setup configuration page widget

        You should implement this method and set the layout of the
        preferences page.

        layout = QVBoxLayout()
        layout.addWidget(...)
        ...
        self.setLayout(layout)
        )NotImplementedErrorr   s    r   
setup_pagezPluginConfigPage.setup_page   s
     "!r   r   c                      t          i           S )aV  
        Hook called to manually apply settings that cannot be automatically
        applied.

        Reimplement this if the configuration page has complex widgets that
        cannot be created with any of the `self.create_*` calls.

        This call should return a set containing the configuration options that
        changed.
        r   r   s    r   r   zPluginConfigPage.apply_settings   s     2wwr   N)r'   r(   r)   r*   r6   r   rB   r7   r;   rb   rg   rl   r+   r   r   r   r   r/   r/   E   s           %0 0 0/ / /6 6 6 ! ! !F  $  "" " "	      r   r/   )r*   r@   typingr   spyder.config.managerr   spyder.config.typesr   spyder.api.utilsr   spyder.plugins.preferences.apir   r   r+   r
   r/   r   r   r   <module>rs      s    
        ' & & & & & 0 0 0 0 0 0 * * * * * * J J J J J J J J  !	)- )- )- )- )-= )- )- )-XV V V V V' V V V V Vr   