B
    nôb\ç  ã               @   sâ   d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ dd	lmZ G d
d„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdd„ Ze dkrÞeƒ  dS )z+Module checking Spyder runtime dependenciesé    N)Úto_qvariant)ÚQtÚQModelIndexÚQAbstractTableModel)ÚQColor)	ÚQApplicationÚQDialogÚQDialogButtonBoxÚQHBoxLayoutÚQItemDelegateÚQLabelÚQPushButtonÚ
QTableViewÚQVBoxLayout)Ú__version__)Ú_)Úicon_managerc               @   sr   e Zd Zdd„ Zdd„ Zeƒ fdd„Zeƒ fdd„Zej	fd	d
„Z
ejfdd„Zdd„ Zejfdd„Zdd„ ZdS )ÚDependenciesTableModelc             C   s    t  | |¡ d | _|  |¡ d S )N)r   Ú__init__ÚdependenciesÚset_data)ÚselfÚparentr   © r   ú:lib/python3.7/site-packages/spyder/widgets/dependencies.pyr      s    zDependenciesTableModel.__init__c             C   s   || _ |  ¡  dS )zSet model dataN)r   Úreset)r   r   r   r   r   r       s    zDependenciesTableModel.set_datac             C   s
   t | jƒS )zArray row number)Úlenr   )r   Úqindexr   r   r   ÚrowCount%   s    zDependenciesTableModel.rowCountc             C   s   dS )zArray column counté   r   )r   r   r   r   r   ÚcolumnCount)   s    z"DependenciesTableModel.columnCountc             C   sD   |dkr| j jdd„ d n|dkr&n|dkr0n|dkr8|  ¡  dS )	zOverriding sort methodr   c             S   s
   t | dƒS )NÚmodname)Úgetattr)Údepr   r   r   Ú<lambda>0   s    z-DependenciesTableModel.sort.<locals>.<lambda>)Úkeyé   é   é   N)r   Úsortr   )r   ÚcolumnÚorderr   r   r   r)   -   s    zDependenciesTableModel.sortc             C   sT   |t jkrtƒ S t|ƒ}|t jkrJtdƒtdƒtdƒtdƒf}t|| ƒS tƒ S dS )zOverriding method headerDataZModulez
 Required z Installed zProvided featuresN)r   ÚDisplayRoler   ÚintZ
Horizontalr   )r   ZsectionZorientationÚroleZi_columnZheadersr   r   r   Ú
headerData9   s    

z!DependenciesTableModel.headerDatac             C   s,   | j | ¡  }|j|j| ¡ |jf| ¡  S )zReturn current value)r   Úrowr!   Zrequired_versionZget_installed_versionZfeaturesr*   )r   Úindexr#   r   r   r   Ú	get_valueE   s    z DependenciesTableModel.get_valuec             C   s¾   |  ¡ stƒ S | j| ¡  }|tjkrX| ¡ dkrD|  |¡}t|ƒS |  |¡}t|ƒS nb|tjkrvtt	tj
tjB ƒƒS |tjkrºddlm} | ¡ }||jkrºttjƒ}| d¡ t|ƒS dS )zReturn data at table indexr   )Ú
Dependencyg      Ð?N)ZisValidr   r   r0   r   r,   r*   r2   ZTextAlignmentRoler-   Z	AlignLeftZAlignVCenterZBackgroundColorRoleÚspyder.dependenciesr3   Z
get_statusZNOKr   ZredZ	setAlphaF)r   r1   r.   r#   Úvaluer3   ÚstatusZcolorr   r   r   ÚdataK   s$    








zDependenciesTableModel.datac             C   s   |   ¡  |  ¡  d S )N)ZbeginResetModelZendResetModel)r   r   r   r   r   a   s    zDependenciesTableModel.resetN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r    r   ÚDescendingOrderr)   r,   r/   r2   r7   r   r   r   r   r   r      s   r   c               @   s   e Zd Zddd„ZdS )ÚDependenciesDelegateNc             C   s   t  | |¡ d S )N)r   r   )r   r   r   r   r   r   g   s    zDependenciesDelegate.__init__)N)r8   r9   r:   r   r   r   r   r   r<   f   s   r<   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚDependenciesTableViewc             C   sF   t  | |¡ t| |ƒ| _|  | j¡ t| ƒ| _|  | j¡ |  ¡  d S )N)	r   r   r   ÚmodelZsetModelr<   ZdelegateZsetItemDelegateÚsetup_table)r   r   r7   r   r   r   r   l   s    
zDependenciesTableView.__init__c             C   s<   |   ¡  d¡ |  ¡  |  d¡ |  d¡ |  dtj¡ dS )zSetup tableTr   FN)ZhorizontalHeaderZsetStretchLastSectionÚadjust_columnsZcolumnAtZsetSortingEnabledÚsortByColumnr   r;   )r   r   r   r   r?   t   s
    

z!DependenciesTableView.setup_tablec             C   s    xt dƒD ]}|  |¡ q
W dS )z&Resize three first columns to contentsr(   N)ÚrangeZresizeColumnToContents)r   Úcolr   r   r   r@   }   s    z$DependenciesTableView.adjust_columnsN)r8   r9   r:   r   r?   r@   r   r   r   r   r=   k   s   	r=   c                   s4   e Zd Zdd„ Z‡ fdd„Zdd„ Zdd„ Z‡  ZS )	ÚDependenciesDialogc             C   s@  t  | |¡ |  dttdƒf ¡ |  t d¡¡ |  d¡ t	| g ƒ| _
ddddd	g}ttd
ƒd |d d… ¡|d f ƒ| _| j d¡ | j tj¡ | j dddd¡ ttdƒƒ}|j | j¡ ttjƒ}|j | j¡ tƒ }| |¡ | ¡  | |¡ tƒ }| | j¡ | | j
¡ | |¡ |   |¡ |  !dd¡ d S )NzSpyder %s: %sZDependenciesZtooloptionsTZNumPyZ
MatplotlibZPandasZSymPyZCythonaš  Spyder depends on several Python modules to provide the right functionality for all its panes. The table below shows the required and installed versions (if any) of all of them.<br><br><b>Note</b>: You can safely use Spyder without the following modules installed: <b>%s</b> and <b>%s</b>.<br><br>Please also note that new dependencies or changed ones will be correctly detected only after Spyder is restarted.z, éÿÿÿÿé   é   é   é
   zCopy to clipboardiv  i¤  )"r   r   ZsetWindowTitler   r   ZsetWindowIconÚimaZiconZsetModalr=   Úviewr   ÚjoinZlabelZsetWordWrapZsetAlignmentr   ZAlignJustifyZsetContentsMarginsr   ZclickedZconnectÚcopy_to_clipboardr	   ZOkZacceptedZacceptr
   Z	addWidgetZ
addStretchr   Z	addLayoutZ	setLayoutZresize)r   r   Zopt_modsZbtnZbboxZhlayoutZvlayoutr   r   r   r   ƒ   s4    
 




zDependenciesDialog.__init__c                s$   |   ¡  | j ¡  tt| ƒ ¡  d S )N)ÚshowrK   ZresizeRowsToContentsÚsuperrD   Úexec_)r   )Ú	__class__r   r   rP   ®   s    
zDependenciesDialog.exec_c             C   s,   | j j |¡ | j  ¡  | j  dtj¡ d S )Nr   )rK   r>   r   r@   rA   r   r;   )r   r   r   r   r   r   ¶   s    
zDependenciesDialog.set_datac             C   s    ddl m} t ¡  |ƒ ¡ d S )Nr   )r6   )r4   r6   r   Z	clipboardZsetText)r   r6   r   r   r   rM   »   s    z$DependenciesDialog.copy_to_clipboard)r8   r9   r:   r   rP   r   rM   Ú__classcell__r   r   )rQ   r   rD   ‚   s   +rD   c              C   s„   ddl m}  |  ddd¡ |  ddd¡ |  d	d
d¡ |  ddd¡ ddlm} |ƒ }tdƒ}| | j¡ | ¡  t	 
| ¡ ¡ dS )zRun dependency widget testr   )r   ZIPythonzEnhanced Python interpreterz>=0.13Z
matplotlibzInteractive data plottingz>=1.0ZsympyzSymbolic Mathematicsz>=10.0ZfoozNon-existent module)ÚqapplicationN)Úspyderr   ÚaddZspyder.utils.qthelpersrS   rD   r   ZDEPENDENCIESrN   ÚsysÚexitrP   )r   rS   ZappZdlgr   r   r   ÚtestÀ   s    rX   Ú__main__)!Ú__doc__rV   Zqtpy.compatr   Zqtpy.QtCorer   r   r   Z
qtpy.QtGuir   Zqtpy.QtWidgetsr   r   r	   r
   r   r   r   r   r   rT   r   Zspyder.config.baser   Zspyder.utilsr   rJ   r   r<   r=   rD   rX   r8   r   r   r   r   Ú<module>   s   ,L>