B
    nôb\3  ã               @   sÄ   d Z ddlm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mZ ddlmZ eddƒZG dd„ deƒZG dd„ deeƒZdS )zPylint Code Analysis Plugin.é    N)ÚQtÚSignalÚSlot)Ú	QGroupBoxÚQInputDialogÚQLabelÚQVBoxLayout)Úget_translation)ÚSpyderPluginMixin)ÚPluginConfigPage)Úicon_manager)Úis_module_installed)Úcreate_actionÚMENU_SEPARATORé   )ÚPylintWidgetÚpylintZspyder_pylintc               @   s   e Zd Zdd„ ZdS )ÚPylintConfigPagec          	   C   sB  t tdƒƒ}| jtdƒddd}t tdƒƒ}ttdƒƒ}| d¡ | jtdƒtd	ƒd
ddddd}t tdƒƒ}ttdƒƒ}| d¡ ttjƒ}| t	j
¡ | d¡ tƒ }	|	 |¡ | |	¡ tƒ }
|
 |¡ |
 |¡ | |
¡ tƒ }| |¡ | |¡ | |¡ tƒ }| |¡ | |¡ | |¡ | d¡ |  |¡ d S )NZSettingszSave file before analyzing itÚsave_beforeT)ÚdefaultÚHistoryz5The following option will be applied at next startup.z	History: z resultsÚmax_entriesé2   é
   i@B )r   Zmin_Zmax_ÚstepZResultszResults are stored here:r   )r   Ú_Zcreate_checkboxr   ZsetWordWrapZcreate_spinboxr   ZDATAPATHZsetTextInteractionFlagsr   ZTextSelectableByMouser   Z	addWidgetZ	setLayoutZ
addStretch)ÚselfZsettings_groupZsave_boxZ
hist_groupZhist_label1Z	hist_spinZresults_groupZresults_label1Zresults_label2Zsettings_layoutZhist_layoutZresults_layoutZvlayout© r   ú3lib/python3.7/site-packages/spyder_pylint/pylint.pyÚ
setup_page#   s@    



















zPylintConfigPage.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eƒ dd„ ƒZeƒ dd„ ƒZdd„ ZdS )!ÚPylintz+Python source code analysis based on pylintr   Nc             C   s0   t j| ||  dd¡d t | |¡ |  ¡  d S )Nr   r   )Úparentr   )r   Ú__init__Ú
get_optionr
   Zinitialize_plugin)r   r$   r   r   r   r%   X   s    zPylint.__init__c             C   s   t dƒS )zReturn widget titlezStatic code analysis)r   )r   r   r   r   Úget_plugin_titlea   s    zPylint.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_icone   s    zPylint.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
        )Ú
treewidget)r   r   r   r   Úget_focus_widgetj   s    zPylint.get_focus_widgetc             C   s<   t | tdƒdt d¡tdƒ| jd}| j jd|f7  _g S )z*Return a list of actions related to pluginz
History...NÚhistoryzSet history maximum entries)Ú	triggered)r   r   r*   r+   Úchange_history_depthr.   Zcommon_actions)r   Zhistory_actionr   r   r   Úget_plugin_actionsq   s    


zPylint.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Pylint.on_first_registrationc             C   sŒ   | j  | jjj¡ | j | jj¡ | j | ¡ t| t	dƒ| j
d}| tdƒ¡ | j|ddd | j jt|g7  _| jj j|g7  _dS )z'Register plugin in Spyder's main windowzRun static code analysis)r1   r   r#   zRun analysis)ÚcontextÚnameN)Ú	edit_gotoZconnectr4   ÚeditorÚloadZredirect_stdioZredirect_internalshell_stdioZadd_dockwidgetr   r   Ú
run_pylintZ
setEnabledr   Zregister_shortcutZsource_menu_actionsr   Zpythonfile_dependent_actions)r   Z
pylint_actr   r   r   Úregister_plugin€   s    

zPylint.register_pluginc             C   s   |   ¡  dS )zRefresh pylint widgetN)Zremove_obsolete_items)r   r   r   r   Úrefresh_plugin   s    zPylint.refresh_pluginFc             C   s   dS )z3Perform actions before parent main window is closedTr   )r   Z
cancelabler   r   r   Úclosing_plugin“   s    zPylint.closing_pluginc             C   s   dS )z*Apply configuration file's plugin settingsNr   )r   Zoptionsr   r   r   Úapply_plugin_settings—   s    zPylint.apply_plugin_settingsc             C   s:   t  | tdƒtdƒ|  d¡dd¡\}}|r6|  d|¡ dS )zChange history max entriesr   zMaximum entriesr   r   i'  N)r   ZgetIntr   r&   Z
set_option)r   ZdepthZvalidr   r   r   r2   ž   s    zPylint.change_history_depthc             C   s:   |   dd¡r| jj ¡ sdS |  ¡  |  | jj ¡ ¡ dS )zRun pylint code analysisr   TN)r&   r4   r;   ZsaveZswitch_to_pluginÚanalyzeZget_current_filename)r   r   r   r   r=   ¨   s
    zPylint.run_pylintc             C   s<   | j r,| js,| j  d¡ | j  ¡  | j  ¡  t | |¡ dS )zReimplement analyze methodTN)r6   ZismaximizedZ
setVisibleZsetFocusZraise_r   rB   )r   Úfilenamer   r   r   rB   ±   s
    

zPylint.analyze)N)F)r    r!   r"   Ú__doc__ZCONF_SECTIONr   ZCONFIGWIDGET_CLASSr   ÚstrÚintr:   r%   r'   r-   r/   r3   r7   r>   r?   r@   rA   r   r2   r=   rB   r   r   r   r   r#   R   s"   
	


	r#   ) rD   Úos.pathr,   r(   Zqtpy.QtCorer   r   r   Zqtpy.QtWidgetsr   r   r   r   Zspyder.config.baser	   Zspyder.pluginsr
   Zspyder.plugins.configdialogr   Zspyder.utilsr   r*   Zspyder.utils.programsr   Zspyder.utils.qthelpersr   r   Zwidgets.pylintguir   r   r   r#   r   r   r   r   Ú<module>   s   
0