B
    nôb\ú   ã               @   sÞ   d Z ddlmZmZmZ ddlmZmZmZm	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 dd	lmZ dd
lmZ dZejdedƒedd dZejdedƒedd G dd„ deƒZG dd„ de	eƒZdS )zVariable Explorer Pluginé    )ÚQTimerÚSignalÚSlot)Ú	QGroupBoxÚQStackedWidgetÚQVBoxLayoutÚQWidget)ÚREMOTE_SETTINGS)Údependencies)Ú_)ÚSpyderPluginMixin)ÚPluginConfigPage)Úicon_manager)ÚNamespaceBrowserz>=0.13.1Zpandasz<View and edit DataFrames and Series in the Variable ExplorerT)Zrequired_versionZoptionalz>=1.7ZnumpyzGView and edit two and three dimensional arrays in the Variable Explorerc               @   s   e Zd Zdd„ ZdS )ÚVariableExplorerConfigPagec                sú   t tdƒƒ}dtdƒfdtdƒfdtdƒfdtd	ƒfg}‡ fd
d„|D ƒ}t tdƒƒ}dtdƒdfg}‡ fdd„|D ƒ}tƒ }x|D ]}| |¡ q„W | |¡ tƒ }	x|D ]}|	 |¡ q¬W | |	¡ tƒ }
|
 |¡ |
 |¡ |
 d¡ ˆ  |
¡ d S )NZFilterZexclude_privatezExclude private referencesZexclude_capitalizedzExclude capitalized referencesZexclude_uppercasez Exclude all-uppercase referencesZexclude_unsupportedzExclude unsupported data typesc                s   g | ]\}}ˆ   ||¡‘qS © )Úcreate_checkbox)Ú.0ÚoptionÚtext)Úselfr   ú>lib/python3.7/site-packages/spyder/plugins/variableexplorer.pyú
<listcomp>,   s   z9VariableExplorerConfigPage.setup_page.<locals>.<listcomp>ZDisplayZminmaxzShow arrays min/maxÚ c                s"   g | ]\}}}ˆ j |||d ‘qS ))Útip)r   )r   r   r   r   )r   r   r   r   1   s   é   )r   r   r   Ú	addWidgetÚ	setLayoutZ
addStretch)r   Zfilter_groupZfilter_dataZfilter_boxesZdisplay_groupZdisplay_dataZdisplay_boxesZfilter_layoutZboxZdisplay_layoutZvlayoutr   )r   r   Ú
setup_page$   s0    











z%VariableExplorerConfigPage.setup_pageN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   "   s   r   c               @   sä   e Zd ZdZdZeZdZdZe	e
eƒZdd„ Zdd„ Zee
eƒd	d
„ ƒZeƒ dd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd1d&d'„Zd(d)„ Zd*d+„ Z d,d-„ Z!d.d/„ Z"d0S )2ÚVariableExplorerz"
    Variable Explorer Plugin
    Zvariable_exploreri`ê  i ¿ c             C   sP   t  | |¡ t | |¡ t| ƒ| _i | _tƒ }| | j¡ |  |¡ |  	¡  d S )N)
r   Ú__init__r   r   ÚstackÚshellwidgetsr   r   r   Zinitialize_plugin)r   ÚparentZlayoutr   r   r   r#   O   s    

zVariableExplorer.__init__c             C   s<   i }xt D ]}|  |¡||< q
W d}d |  |¡¡||< |S )a  
        Retrieve all Variable Explorer configuration settings.
        
        Specifically, return the settings in CONF_SECTION with keys in 
        REMOTE_SETTINGS, and the setting 'dataframe_format'.
        
        Returns:
            dict: settings
        Údataframe_formatz%{0})r	   Z
get_optionÚformat)r   ZsettingsÚnamer   r   r   Úget_settings_   s    

zVariableExplorer.get_settingsc             C   s4   |dkr"|  d¡st‚|dd… }| j ||¡ dS )an  
        Change a config option.

        This function is called if sig_option_changed is received. If the
        option changed is the dataframe format, then the leading '%' character
        is stripped (because it can't be stored in the user config). Then,
        the signal is emitted again, so that the new value is saved in the
        user config.
        r'   ú%r   N)Ú
startswithÚAssertionErrorÚsig_option_changedÚemit)r   Zoption_nameZ	new_valuer   r   r   Úchange_options   s    zVariableExplorer.change_optionc                s:   ˆ j  ¡  t ˆ j‡ fdd„¡ t ˆ j‡ fdd„¡ dS )zFree memory signal.c                  s
   ˆ j  ¡ S )N)ÚmainÚfree_memoryr   )r   r   r   Ú<lambda>ˆ   s    z.VariableExplorer.free_memory.<locals>.<lambda>c                  s
   ˆ j  ¡ S )N)r1   r2   r   )r   r   r   r3   Š   s    N)r1   r2   r   Z
singleShotÚ INITIAL_FREE_MEMORY_TIME_TRIGGERÚ"SECONDARY_FREE_MEMORY_TIME_TRIGGER)r   r   )r   r   r2   ƒ   s
    
zVariableExplorer.free_memoryc             C   s   | j  |¡ d S )N)r$   ZsetCurrentWidget)r   Únsbr   r   r   Úset_current_widget   s    z#VariableExplorer.set_current_widgetc             C   s
   | j  ¡ S )N)r$   ZcurrentWidget)r   r   r   r   Úcurrent_widget   s    zVariableExplorer.current_widgetc             C   s
   | j  ¡ S )N)r$   Úcount)r   r   r   r   r9   “   s    zVariableExplorer.countc             C   s   | j  |¡ d S )N)r$   ZremoveWidget)r   r6   r   r   r   Úremove_widget–   s    zVariableExplorer.remove_widgetc             C   s   | j  |¡ d S )N)r$   r   )r   r6   r   r   r   Ú
add_widget™   s    zVariableExplorer.add_widgetc             C   sv   t |ƒ}|| jkrrt| ƒ}| |¡ |jf |  ¡ Ž |j | j¡ |j	 | j
¡ |  |¡ || j|< |  |¡ |S dS )z
        Register shell with variable explorer.

        This function opens a new NamespaceBrowser for browsing the variables
        in the shell.
        N)Úidr%   r   Zset_shellwidgetÚsetupr*   r.   Zconnectr0   Zsig_free_memoryr2   r;   Úset_shellwidget_from_id)r   ZshellwidgetÚshellwidget_idr6   r   r   r   Úadd_shellwidget   s    




z VariableExplorer.add_shellwidgetc             C   s,   || j kr(| j  |¡}|  |¡ | ¡  d S )N)r%   Úpopr:   Úclose)r   r?   r6   r   r   r   Úremove_shellwidget°   s    

z#VariableExplorer.remove_shellwidgetc             C   s"   || j kr| j | }|  |¡ d S )N)r%   r7   )r   r?   r6   r   r   r   r>   ¸   s    

z(VariableExplorer.set_shellwidget_from_idc             C   sJ   |   ¡ rF|  ¡ }| ¡  |j|d | jrF| jsF| j d¡ | j ¡  dS )z Import data in current namespace)Ú	filenamesTN)r9   r8   Zrefresh_tableÚimport_dataZ
dockwidgetZismaximizedZ
setVisibleZraise_)r   Úfnamer6   r   r   r   rE   ½   s    zVariableExplorer.import_datac             C   s   t dƒS )zReturn widget titlezVariable explorer)r   )r   r   r   r   Úget_plugin_titleÈ   s    z!VariableExplorer.get_plugin_titlec             C   s
   t  d¡S )zReturn plugin iconZdictedit)ÚimaZicon)r   r   r   r   Úget_plugin_iconÌ   s    z VariableExplorer.get_plugin_iconc             C   s   |   ¡ S )zq
        Return the widget to give focus to when
        this plugin's dockwidget is raised on top-level
        )r8   )r   r   r   r   Úget_focus_widgetÐ   s    z!VariableExplorer.get_focus_widgetFc             C   s   dS )z3Perform actions before parent main window is closedTr   )r   Z
cancelabler   r   r   Úclosing_plugin×   s    zVariableExplorer.closing_pluginc             C   s   dS )zRefresh widgetNr   )r   r   r   r   Úrefresh_pluginÛ   s    zVariableExplorer.refresh_pluginc             C   s   g S )z*Return a list of actions related to pluginr   )r   r   r   r   Úget_plugin_actionsß   s    z#VariableExplorer.get_plugin_actionsc             C   s   | j  | ¡ dS )z'Register plugin in Spyder's main windowN)r1   Zadd_dockwidget)r   r   r   r   Úregister_pluginã   s    z VariableExplorer.register_pluginc             C   s,   x&t | j ¡ ƒD ]}|jf |  ¡ Ž qW dS )z*Apply configuration file's plugin settingsN)Úlistr%   Úvaluesr=   r*   )r   Zoptionsr6   r   r   r   Úapply_plugin_settingsç   s    z&VariableExplorer.apply_plugin_settingsN)F)#r   r    r!   Ú__doc__ZCONF_SECTIONr   ZCONFIGWIDGET_CLASSr4   r5   r   ÚstrÚobjectr.   r#   r*   r   r0   r2   r7   r8   r9   r:   r;   r@   rC   r>   rE   rG   rI   rJ   rK   rL   rM   rN   rQ   r   r   r   r   r"   E   s6   


r"   N)rR   Zqtpy.QtCorer   r   r   Zqtpy.QtWidgetsr   r   r   r   Zspyder_kernels.utils.nsviewr	   Zspyderr
   Zspyder.config.baser   Zspyder.pluginsr   Zspyder.plugins.configdialogr   Zspyder.utilsr   rH   Z0spyder.widgets.variableexplorer.namespacebrowserr   ZPANDAS_REQVERÚaddZNUMPY_REQVERr   r"   r   r   r   r   Ú<module>   s"   

#