B
    nôb\p  ã               @   s¼   d Z ddlmZ ddlmZmZ ddl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mZ eddƒZG dd„ deƒZG dd„ deeƒZdS )zProfiler Plugin.é    N)ÚQtÚSignal)Ú	QGroupBoxÚQLabelÚQVBoxLayout)Úget_translation)ÚSpyderPluginMixin)ÚPluginConfigPage)Úget_run_configuration)Úicon_manager)Úcreate_actioné   )ÚProfilerWidgetÚis_profiler_installedÚprofilerZspyder_profilerc               @   s   e Zd Zdd„ ZdS )ÚProfilerConfigPagec             C   sŽ   t tdƒƒ}ttdƒƒ}| d¡ ttjƒ}| tj¡ | d¡ t	ƒ }| 
|¡ | 
|¡ | |¡ t	ƒ }| 
|¡ | d¡ |  |¡ d S )NZResultszRProfiler plugin results (the output of python's profile/cProfile)
are stored here:Tr   )r   Ú_r   ZsetWordWrapr   ZDATAPATHZsetTextInteractionFlagsr   ZTextSelectableByMouser   Z	addWidgetZ	setLayoutZ
addStretch)ÚselfZresults_groupZresults_label1Zresults_label2Zresults_layoutZvlayout© r   ú7lib/python3.7/site-packages/spyder_profiler/profiler.pyÚ
setup_page    s    







zProfilerConfigPage.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eee	eƒZ
d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d„Zdd„ Zdd„ Zdd„ ZdS )ÚProfilerz,Profiler (after python's profile and pstats)r   Nc             C   s0   t j| ||  dd¡d t | |¡ |  ¡  d S )NÚmax_entriesé2   )Úparentr   )r   Ú__init__Z
get_optionr   Zinitialize_plugin)r   r   r   r   r   r   @   s    zProfiler.__init__c             C   s   t dƒS )zReturn widget titler   )r   )r   r   r   r   Úget_plugin_titleI   s    zProfiler.get_plugin_titlec             C   s   t  | j| j¡}tjd|dS )zReturn widget iconr   )Z	icon_path)ÚospÚjoinZPLUGIN_PATHZIMG_PATHÚimaÚicon)r   Úpathr   r   r   Úget_plugin_iconM   s    zProfiler.get_plugin_iconc             C   s   | j S )zq
        Return the widget to give focus to when
        this plugin's dockwidget is raised on top-level
        )Zdatatree)r   r   r   r   Úget_focus_widgetR   s    zProfiler.get_focus_widgetc             C   s   g S )z*Return a list of actions related to pluginr   )r   r   r   r   Úget_plugin_actionsY   s    zProfiler.get_plugin_actionsc             C   s    | j  | j j| ¡ | j ¡  dS )z3Action to be performed on first plugin registrationN)ÚmainZtabify_pluginsÚhelpÚ
dockwidgetZhide)r   r   r   r   Úon_first_registration]   s    zProfiler.on_first_registrationc             C   sŽ   | j  | jjj¡ | j | jj¡ | j | ¡ t| t	dƒ|  
¡ | jd}| tƒ ¡ | j|ddd | j j|g7  _| jj j|g7  _dS )z'Register plugin in Spyder's main windowZProfile)r#   Z	triggeredr   zRun profiler)ÚcontextÚnameN)Ú	edit_gotoZconnectr(   ÚeditorÚloadZredirect_stdioZredirect_internalshell_stdioZadd_dockwidgetr   r   r%   Úrun_profilerZ
setEnabledr   Zregister_shortcutZrun_menu_actionsZpythonfile_dependent_actions)r   Zprofiler_actr   r   r   Úregister_pluginb   s    

zProfiler.register_pluginc             C   s   dS )zRefresh profiler widgetNr   )r   r   r   r   Úrefresh_pluginr   s    zProfiler.refresh_pluginFc             C   s   dS )z3Perform actions before parent main window is closedTr   )r   Z
cancelabler   r   r   Úclosing_pluginv   s    zProfiler.closing_pluginc             C   s   dS )z*Apply configuration file's plugin settingsNr   )r   Zoptionsr   r   r   Úapply_plugin_settingsz   s    zProfiler.apply_plugin_settingsc             C   s*   | j j ¡ r&|  ¡  |  | j j ¡ ¡ dS )zRun profilerN)r(   r/   ZsaveZswitch_to_pluginÚanalyzeZget_current_filename)r   r   r   r   r1      s    zProfiler.run_profilerc             C   s€   | j r,| js,| j  d¡ | j  ¡  | j  ¡  | j ¡ }t|ƒ}dg  }}|dk	rh|jr\|j	}|j
rh|j}tj| ||||d dS )zReimplement analyze methodTN)ÚwdirÚargsÚ
pythonpath)r*   ZismaximizedZ
setVisibleZsetFocusZraise_r(   Zget_spyder_pythonpathr
   Zwdir_enabledr7   Zargs_enabledr8   r   r6   )r   Úfilenamer9   Zrunconfr7   r8   r   r   r   r6   ‡   s    



zProfiler.analyze)N)F)r   r   r   Ú__doc__ZCONF_SECTIONr   ZCONFIGWIDGET_CLASSr   ÚstrÚintr.   r   r   r%   r&   r'   r+   r2   r3   r4   r5   r1   r6   r   r   r   r   r   :   s    
	
r   )r;   Úos.pathr$   r    Zqtpy.QtCorer   r   Zqtpy.QtWidgetsr   r   r   Zspyder.config.baser   Zspyder.pluginsr   Zspyder.plugins.configdialogr	   Zspyder.plugins.runconfigr
   Zspyder.utilsr   r"   Zspyder.utils.qthelpersr   Zwidgets.profilerguir   r   r   r   r   r   r   r   r   Ú<module>	   s   
