B
    nôb\òÔ  ã               @   s<  d Z ddlmZ ddlZddlmZ ddlZddlZddl	Z	ddl
Z
ddlZddlmZmZ ddlmZ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mZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) ddl*m+Z+m,Z, dd	l-m.Z.m/Z/m0Z0 dd
l1m2Z3 ddl1m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z< ddl=m>Z> yddl?m@ZA W n   dZAY nX dd„ ZBd3dd„ZCdd„ ZDdd„ ZEd4dd„ZFdd„ ZGG dd„ de ƒZHG d d!„ d!e'ƒZIG d"d#„ d#eƒZJG d$d%„ d%eIƒZKG d&d'„ d'eIƒZLG d(d)„ d)e)ƒZMG d*d+„ d+e)ƒZNG d,d-„ d-e)ƒZOd.d/„ ZPeQd0kr8ePd1d2 ePdd2 dS )5zFiles and Directories Exploreré    )Úwith_statementN)ÚgetsavefilenameÚgetexistingdirectory)
ÚQDirÚ	QFileInfoÚ	QMimeDataÚQSizeÚQSortFilterProxyModelÚQtÚQTimerÚQUrlÚSignalÚSlot)ÚQDrag)ÚQFileSystemModelÚQHBoxLayoutÚQFileIconProviderÚQInputDialogÚQLabelÚ	QLineEditÚQMenuÚQMessageBoxÚQToolButtonÚ	QTreeViewÚQVBoxLayoutÚQWidget)Ú_Úget_home_dir)Ú	str_lowerÚto_binary_stringÚto_text_string)Úicon_manager)ÚencodingÚmiscÚprogramsÚvcs)Úadd_actionsÚcreate_actionÚfile_uriÚcreate_plugin_layout)Úgetcwd_or_home)ÚPythonExporterc             C   sP   t jdkrt dd| g¡ n0tj | ¡} tjdkr>t | ¡ nt d| g¡ d S )NÚdarwinÚopenz-RÚntzxdg-open)	ÚsysÚplatformÚ
subprocessZcallÚosÚpathÚdirnameÚnameZ	startfile)Úfilename© r7   ú6lib/python3.7/site-packages/spyder/widgets/explorer.pyÚopen_file_in_external_explorer1   s    

r9   c             C   s.   t | ttfƒs| g} x| D ]}t|ƒ qW dS )zcShow files in external file explorer

    Args:
        fnames (list): Names of files to show.
    N)Ú
isinstanceÚtupleÚlistr9   )ÚfnamesÚfnamer7   r7   r8   Úshow_in_external_file_explorer;   s    
r?   c             C   s*   t jdkrtjntj}|t t | ¡¡ƒS )zANormalize path fixing case, making absolute and removing symlinksr.   )r2   r5   ÚospÚnormcaseÚnormpathÚabspathÚrealpath)r3   Znormr7   r7   r8   ÚfixpathF   s    rE   c          
   C   sv   t j dddg¡}yt t|ƒ| d¡ W nH tk
rp } z*t t	dƒt	dƒt
 | ¡t|ƒf ¡ W dd}~X Y nX dS )zCreate a new Python scriptz# -*- coding: utf-8 -*-Ú zutf-8z
Save Errorz;<b>Unable to save file '%s'</b><br><br>Error message:<br>%sN)r2   ÚlinesepÚjoinr"   Úwriter    ÚEnvironmentErrorr   Úcriticalr   r@   ÚbasenameÚstr)r>   ÚtextÚerrorr7   r7   r8   Úcreate_scriptL   s    
rP   Ú.ú
\.pyc$|^\.Fc             C   s’   g }t tjƒg}xht t | ƒ¡D ]V}t ||¡r6|s6q t t | |¡¡rT| 	|¡ q |r\q q t ||¡sl|r | 	|¡ q W t
|tdt
|td S )zList files and directories)Úkey)r    r@   Úpardirr2   ÚlistdirÚreÚsearchÚisdirrH   ÚappendÚsortedr   )r3   ÚincludeÚexcludeÚshow_allÚfolders_onlyZnamelistÚdirlistÚitemr7   r7   r8   rU   W   s    
rU   c          	   C   s8   yt t| |||ddƒdkS  ttfk
r2   dS X dS )z&Return True if path has subdirectoriesT)r^   é   FN)ÚlenrU   ÚIOErrorÚOSError)r3   r[   r\   r]   r7   r7   r8   Úhas_subdirectoriesi   s
    
re   c                   sf   e Zd Zdd„ dD ƒZddddddddœZdddd	œZ‡ fd
d„Zeeƒee	ƒ‡ fdd„ƒƒZ
‡  ZS )ÚIconProviderc             C   s   i | ]
}d |“qS )ZArchiveFileIconr7   )Ú.0Úxr7   r7   r8   ú
<dictcomp>t   s    zIconProvider.<dictcomp>)Úzipzx-tarzx-7z-compressedZrarZPowerpointFileIconZWordFileIconZExcelFileIconZPDFIcon)zvnd.ms-powerpointz=vnd.openxmlformats-officedocument.presentationml.presentationZmswordz;vnd.openxmlformats-officedocument.wordprocessingml.documentzvnd.ms-excelz5vnd.openxmlformats-officedocument.spreadsheetml.sheetZpdf)z.xlsxz.docxz.pptxc                s:   t t| ƒ ¡  || _i | _| j | j¡ | j | j¡ d S )N)Úsuperrf   Ú__init__ÚtreeviewÚapplication_iconsÚupdateÚ	BIN_FILESÚDOCUMENT_FILES)Úselfrm   )Ú	__class__r7   r8   rl   „   s
    zIconProvider.__init__c                sH  t |tjƒrtt| ƒ |¡S |}t t| 	¡ ƒ¡}t 
|¡rFt d¡S t |¡}t |¡\}}t |¡\}}t d¡}|| jkrt | j| ¡}|dk	r@y| d¡\}	}
W n tk
rÄ   d}	Y nX |	dkrÚt d¡}nf|	dkrît d¡}nR|	d	krt d
¡}n<|	dkrt d¡}n&|	dkr@|
| jkr@t | j|
 ¡}|S dS )zReimplement Qt methodZDirOpenIconZFileIconNú/rN   ZTextFileIconZaudioZAudioFileIconZvideoZVideoFileIconZimageZImageFileIconZapplication)r:   r   ZIconTyperk   rf   Úiconr@   rB   r    ZabsoluteFilePathrX   ÚimarL   ÚsplitextÚmimeZ
guess_typeÚOFFICE_FILESÚsplitÚ
ValueErrorrn   )rr   Zicontype_or_qfileinfoZ	qfileinfor>   rL   r   Ú	extensionZ	mime_typeru   Z	file_typeZbin_name)rs   r7   r8   ru   ‹   s:    









zIconProvider.icon)Ú__name__Ú
__module__Ú__qualname__rp   rq   ry   rl   r   Úintr   ru   Ú__classcell__r7   r7   )rs   r8   rf   s   s   rf   c                   sV  e Zd ZdZd€‡ f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gdfdd„Zdd„ Zdd„ Zeƒ d d!„ ƒZeeƒd"d#„ ƒZd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zeƒ d8d9„ ƒZd:d;„ Z d<d=„ Z!d>d?„ Z"d@dA„ Z#eƒ ddBdC„ƒZ$dDdE„ Z%dFdG„ Z&eƒ d‚dHdI„ƒZ'dJdK„ Z(dLdM„ Z)eƒ dƒdNdO„ƒZ*dPdQ„ Z+eƒ dRdS„ ƒZ,dTdU„ Z-eƒ d„dVdW„ƒZ.eƒ d…dXdY„ƒZ/eƒ d†dZd[„ƒZ0d\d]„ Z1d^d_„ Z2d`da„ Z3dbdc„ Z4ddde„ Z5dfdg„ Z6dhdi„ Z7djdk„ Z8dldm„ Z9dndo„ Z:dpdq„ Z;drds„ Z<dtdu„ Z=dvdw„ Z>dxdy„ Z?dzd{„ Z@d|d}„ ZAd~d„ ZB‡  ZCS )‡ÚDirViewzBase file/directory tree viewNc                sT   t t| ƒ |¡ dg| _|| _d | _d | _d | _d | _d | _	d | _
|  ¡  d | _d S )Nz*.py)rk   r‚   rl   Úname_filtersÚparent_widgetr]   ÚmenuÚcommon_actionsÚ_DirView__expanded_stateÚ_to_be_loadedÚfsmodelÚsetup_fs_modelÚ_scrollbar_positions)rr   Úparent)rs   r7   r8   rl   º   s    zDirView.__init__c             C   s>   t jt jB t jB t jB }t| ƒ| _| j |¡ | j d¡ dS )zSetup filesystem modelFN)	r   ZAllDirsZFilesZDrivesZNoDotAndDotDotr   r‰   Z	setFilterZsetNameFilterDisables)rr   Úfiltersr7   r7   r8   rŠ   È   s    
zDirView.setup_fs_modelc             C   s   |   | j¡ dS )zInstall filesystem modelN)ÚsetModelr‰   )rr   r7   r7   r8   Úinstall_modelÏ   s    zDirView.install_modelc                sd   ˆ   ¡  ˆ jj ‡ fdd„¡ ˆ  d¡ ˆ  d¡ ˆ  dtj¡ ˆ jj	 ˆ j
¡ ˆ  
¡  ˆ  ¡  dS )z
Setup viewc                  s
   ˆ   d¡S )Nr   )ZresizeColumnToContentsr7   )rr   r7   r8   Ú<lambda>×   s    z$DirView.setup_view.<locals>.<lambda>FTr   N)r   r‰   ÚdirectoryLoadedÚconnectZsetAnimatedZsetSortingEnabledZsortByColumnr
   ÚAscendingOrderZ
modelResetÚreset_icon_providerÚfilter_directories)rr   r7   )rr   r8   Ú
setup_viewÓ   s    

zDirView.setup_viewc             C   s   || _ | j |¡ dS )zSet name filtersN)rƒ   r‰   ÚsetNameFilters)rr   rƒ   r7   r7   r8   Úset_name_filtersà   s    zDirView.set_name_filtersc             C   s$   |r| j  g ¡ n| j  | j¡ dS )zToggle 'show all files' stateN)r‰   r—   rƒ   )rr   Ústater7   r7   r8   Úset_show_allå   s    zDirView.set_show_allc             C   s   |rt  t| j |¡ƒ¡S dS )z'Return filename associated with *index*N)r@   rB   r    r‰   ÚfilePath)rr   Úindexr7   r7   r8   Úget_filenameì   s    zDirView.get_filenamec             C   s   | j  |¡S )z%Return index associated with filename)r‰   rœ   )rr   r6   r7   r7   r8   Ú	get_indexñ   s    zDirView.get_indexc                s8   ˆ   ¡ ˆ jkr$‡ fdd„ˆ  ¡ D ƒS ˆ  ˆ  ¡ ¡gS dS )zReturn selected filenamesc                s   g | ]}ˆ   |¡‘qS r7   )r   )rg   Úidx)rr   r7   r8   ú
<listcomp>ø   s    z2DirView.get_selected_filenames.<locals>.<listcomp>N)ZselectionModeZExtendedSelectionZselectedIndexesr   ZcurrentIndex)rr   r7   )rr   r8   Úget_selected_filenamesõ   s    zDirView.get_selected_filenamesc             C   s*   |   |¡}|r&t |¡r|S t |¡S dS )z&Return dirname associated with *index*N)r   r@   rX   r4   )rr   rœ   r>   r7   r7   r8   Úget_dirnameü   s
    

zDirView.get_dirnamez*.pyz*.pywFc             C   s0   |   ¡  |  |¡ || _t| ƒ| _|  ¡ | _dS )zSetup tree widgetN)r–   r˜   r]   r   r…   Úsetup_common_actionsr†   )rr   rƒ   r]   r7   r7   r8   Úsetup  s
    

zDirView.setupc             C   s   | j  t| ƒ¡ dS )zgReset file system model icon provider
        The purpose of this is to refresh files/directories iconsN)r‰   ZsetIconProviderrf   )rr   r7   r7   r8   r”     s    zDirView.reset_icon_providerc             C   sR   t | tdƒdt d¡| jd}t | tdƒ| jd}| | j¡ |  | j¡ ||gS )z!Setup context menu common actionszEdit filename filters...NÚfilter)Ú	triggeredzShow all files)Útoggled)r'   r   rv   ru   Úedit_filterÚ
toggle_allÚ
setCheckedr]   )rr   Zfilters_actionZ
all_actionr7   r7   r8   r£     s    




zDirView.setup_common_actionsc          	   C   sb   t  | tdƒtdƒtjd | j¡¡\}}|r^dd„ t|ƒ d¡D ƒ}| j	j
 d|¡ |  |¡ dS )	zEdit name filterszEdit filename filterszName filters:z, c             S   s   g | ]}|  ¡ ‘qS r7   )Ústrip)rg   Úfr7   r7   r8   r    -  s    z'DirView.edit_filter.<locals>.<listcomp>ú,rƒ   N)r   ÚgetTextr   r   ÚNormalrH   rƒ   r    rz   r„   Úsig_option_changedÚemitr˜   )rr   r   Úvalidr7   r7   r8   r¨   %  s    zDirView.edit_filterc             C   s$   | j j d|¡ || _|  |¡ dS )zToggle all files moder]   N)r„   r°   r±   r]   rš   )rr   Úcheckedr7   r7   r8   r©   1  s    zDirView.toggle_allc                s¦   ˆ sg S t ˆtdƒt d¡‡ ‡fdd„d}t ˆtdƒt d¡‡ ‡fdd„d}t ˆtd	ƒt d
¡‡ ‡fdd„d}t ˆtdƒt d¡‡ ‡fdd„d}||d||gS )z#Return actions for submenu 'New...'zFile...Zfilenewc                  s   ˆ  ˆ d ¡S )Néÿÿÿÿ)Únew_filer7   )r=   rr   r7   r8   r   >  s    z1DirView.create_file_new_actions.<locals>.<lambda>)ru   r¦   z	Module...Zspyderc                  s   ˆ  ˆ d ¡S )Nr´   )Ú
new_moduler7   )r=   rr   r7   r8   r   B  s    z	Folder...Z
folder_newc                  s   ˆ  ˆ d ¡S )Nr´   )Ú
new_folderr7   )r=   rr   r7   r8   r   F  s    z
Package...Zpackage_newc                  s   ˆ  ˆ d ¡S )Nr´   )Únew_packager7   )r=   rr   r7   r8   r   J  s    N)r'   r   rv   ru   )rr   r=   Znew_file_actZnew_module_actZnew_folder_actZnew_package_actr7   )r=   rr   r8   Úcreate_file_new_actions8  s     



zDirView.create_file_new_actionsc             C   s   g S )z&Return actions for submenu 'Import...'r7   )rr   r=   r7   r7   r8   Úcreate_file_import_actionsO  s    z"DirView.create_file_import_actionsc                sr  t dd„ |D ƒƒ}t dd„ |D ƒƒ}t dd„ |D ƒƒ}t dd„ |D ƒƒ}tˆtdƒt d¡ˆjd}tˆtd	ƒt d
¡ˆjd}tˆtdƒdˆjd}tˆtdƒt d¡ˆjd}	tˆtdƒt d¡ˆj	d}
tˆtdƒˆj
d}tˆtdƒt d¡ˆjd}g }|r| |¡ |r*|r*| |¡ n
| |¡ tjdkrJtdƒ}ntdƒ}tˆ|ˆjd}| |¡ ||	|
g7 }tt |d ¡ƒ‰ t ‡ fdd„|D ƒƒr¬| |¡ |dg7 }|rÐtdk	rÐ| |¡ t |d ¡rè|d nt |d ¡‰t|ƒdkrnt ˆ¡rn‡‡fdd„}‡‡fdd„}tˆtdƒt d ¡|d}tˆtd!ƒt d"¡|d}|d||g7 }|S )#zReturn file management actionsc             S   s   g | ]}t  |¡‘qS r7   )r@   Úisfile)rg   Ú_fnr7   r7   r8   r    U  s    z6DirView.create_file_manage_actions.<locals>.<listcomp>c             S   s   g | ]}t  |¡d  dk‘qS )ra   )z.pyz.pywz.ipy)r@   rw   )rg   r¼   r7   r7   r8   r    V  s   c             S   s   g | ]}t  |¡d  dk‘qS )ra   z.ipynb)r@   rw   )rg   r¼   r7   r7   r8   r    X  s   c             S   s   g | ]}t  |¡‘qS r7   )r"   Úis_text_file)rg   r¼   r7   r7   r8   r    Z  s    ZRunÚrun)ru   r¦   ZEditÚeditzMove...zmove.pngz	Delete...Z
editdeletez	Rename...ÚrenameZOpen)r¦   zConvert to Python scriptZpythonr,   zShow in FinderzShow in external file explorerr   c                s   g | ]}t t |¡ƒˆ k‘qS r7   )rE   r@   r4   )rg   r¼   )Úbasedirr7   r8   r    }  s    Nra   c                  s   ˆ  ˆ gd¡S )NZcommit)Úvcs_commandr7   )r4   rr   r7   r8   r   ‡  s    z4DirView.create_file_manage_actions.<locals>.<lambda>c                  s   ˆ  ˆ gd¡S )NZbrowse)rÂ   r7   )r4   rr   r7   r8   r   ˆ  s    ZCommitZ
vcs_commitzBrowse repositoryZ
vcs_browse)Úallr'   r   rv   ru   r¾   ÚclickedÚmoveÚdeleterÀ   r-   Úconvert_notebooksrY   r/   r0   r?   rE   r@   r4   Ú
nbexporterrX   rb   r%   Zis_vcs_repository)rr   r=   Z
only_filesZonly_modulesZonly_notebooksZ
only_validZ
run_actionZedit_actionZmove_actionZdelete_actionZrename_actionZopen_actionZipynb_convert_actionÚactionsrN   Zexternal_fileexp_actionZcommit_slotZbrowse_slotZvcs_ciZvcs_logr7   )rÁ   r4   rr   r8   Úcreate_file_manage_actionsS  sl    



















&

z"DirView.create_file_manage_actionsc                sN   g }t jdkrtdƒ}ntdƒ}tdƒ}tˆ|‡ ‡fdd„d}| |¡ |S )z Return folder management actionsr.   zOpen command prompt herezOpen terminal herezOpen IPython console herec                  s
   ˆ  ˆ ¡S )N)Úopen_interpreterr7   )r=   rr   r7   r8   r   œ  s    z6DirView.create_folder_manage_actions.<locals>.<lambda>)r¦   )r2   r5   r   r'   rY   )rr   r=   rÉ   Z_titleÚactionr7   )r=   rr   r8   Úcreate_folder_manage_actions“  s    


z$DirView.create_folder_manage_actionsc             C   sþ   g }|   ¡ }|  |¡}t|ƒdkrFttdƒ| ƒ}t||ƒ | |¡ n||7 }|  |¡}t|ƒdkrˆttdƒ| ƒ}t||ƒ | |¡ n||7 }|rž| d¡ |r°||  |¡7 }|r¾| d¡ |rât	dd„ |D ƒƒrâ||  
|¡7 }|rð| d¡ || j7 }|S )zCreate context menu actionsra   ZNewZImportNc             S   s   g | ]}t  |¡‘qS r7   )r@   rX   )rg   r¼   r7   r7   r8   r    »  s    z7DirView.create_context_menu_actions.<locals>.<listcomp>)r¡   r¹   rb   r   r   r&   rY   rº   rÊ   rÃ   rÍ   r†   )rr   rÉ   r=   Znew_actionsZnew_act_menuZimport_actionsZimport_act_menur7   r7   r8   Úcreate_context_menu_actions¡  s4    







z#DirView.create_context_menu_actionsc             C   s   | j  ¡  t| j |  ¡ ƒ dS )zUpdate context menuN)r…   Úclearr&   rÎ   )rr   r7   r7   r8   Úupdate_menuÂ  s    
zDirView.update_menuc             C   s   |   ¡  t | |¡S )zReimplement Qt method)ZexecuteDelayedItemsLayoutr   ÚviewportEvent)rr   Úeventr7   r7   r8   rÑ   È  s    zDirView.viewportEventc             C   s6   y|   ¡  | j | ¡ ¡ W n tk
r0   Y nX dS )zOverride Qt methodN)rÐ   r…   ZpopupZ	globalPosÚAttributeError)rr   rÒ   r7   r7   r8   ÚcontextMenuEventØ  s
    zDirView.contextMenuEventc             C   sv   |  ¡ tjtjfkr|  ¡  nT|  ¡ tjkr6|  ¡  n<|  ¡ tjkrN|  ¡  n$|  ¡ tj	krf|  
¡  nt | |¡ dS )zReimplement Qt methodN)rS   r
   Z	Key_EnterZ
Key_ReturnrÄ   ZKey_F2rÀ   Z
Key_DeleterÆ   ZKey_BackspaceÚgo_to_parent_directoryr   ÚkeyPressEvent)rr   rÒ   r7   r7   r8   rÖ   â  s    



zDirView.keyPressEventc             C   s   t  | |¡ |  ¡  dS )zReimplement Qt methodN)r   ÚmouseDoubleClickEventrÄ   )rr   rÒ   r7   r7   r8   r×   ï  s    zDirView.mouseDoubleClickEventc             C   s<   |   ¡ }x.|D ]&}t |¡r(|  |¡ q|  |g¡ qW dS )z<Selected item was double-clicked or enter/return was pressedN)r¡   r@   rX   Údirectory_clickedr-   )rr   r=   r>   r7   r7   r8   rÄ   ô  s
    

zDirView.clickedc             C   s   dS )zDirectory was just clickedNr7   )rr   r4   r7   r7   r8   rØ   þ  s    zDirView.directory_clickedc             C   s   |  | ¡  d¡¡ dS )zDrag and Drop - Enter eventz
text/plainN)ZsetAcceptedÚmimeDataÚ	hasFormat)rr   rÒ   r7   r7   r8   ÚdragEnterEvent  s    zDirView.dragEnterEventc             C   s0   |  ¡  d¡r$| tj¡ | ¡  n| ¡  dS )zDrag and Drop - Move eventz
text/plainN)rÙ   rÚ   ZsetDropActionr
   Z
MoveActionZacceptÚignore)rr   rÒ   r7   r7   r8   ÚdragMoveEvent  s    
zDirView.dragMoveEventc             C   s<   t ƒ }| dd„ |  ¡ D ƒ¡ t| ƒ}| |¡ | ¡  dS )z)Reimplement Qt Method - handle drag eventc             S   s   g | ]}t |ƒ‘qS r7   )r   )rg   r>   r7   r7   r8   r      s    z%DirView.startDrag.<locals>.<listcomp>N)r   ZsetUrlsr¡   r   ZsetMimeDataÚexec_)rr   ZdropActionsÚdataZdragr7   r7   r8   Ú	startDrag  s
    
zDirView.startDragc             C   sR   |dkr|   ¡ }x<|D ]4}t |¡r>t |¡r>| jj |¡ q|  |g¡ qW dS )z+Open files with the appropriate applicationN)	r¡   r@   r»   r"   r½   r„   Úsig_open_filer±   Úopen_outside_spyder)rr   r=   r>   r7   r7   r8   r-     s    
zDirView.openc             C   s:   x4t |ƒD ](}t|ƒ}t |¡}|s
| jj |¡ q
W dS )z…Open file outside Spyder with the appropriate application
        If this does not work, opening unknown file in Spyder, as text fileN)rZ   r(   r$   Z
start_filer„   r¿   r±   )rr   r=   r3   Úokr7   r7   r8   râ   #  s
    
zDirView.open_outside_spyderc             C   s$   xt |ƒD ]}| jj |¡ q
W dS )zOpen interpreterN)rZ   r„   rË   r±   )rr   r=   r3   r7   r7   r8   rË   ,  s    zDirView.open_interpreterc             C   s0   |dkr|   ¡ }x|D ]}| jj |¡ qW dS )zRun Python scriptsN)r¡   r„   r¾   r±   )rr   r=   r>   r7   r7   r8   r¾   1  s    
zDirView.runc             C   s   t j|tjd dS )zLRemove whole directory tree
        Reimplemented in project explorer widget)ÚonerrorN)ÚshutilZrmtreer#   rä   )rr   r4   r7   r7   r8   Úremove_tree9  s    zDirView.remove_treec             C   s  |rt jt jB t jB t jB }nt jt jB }|dkr~t  | tdƒtdƒt |¡ |¡}|t jkrb|S |t jkrpdS |t jkr~d}y@t 	|¡r¤t
 |¡ | jj |¡ n|  |¡ | jj |¡ |S  tk
r } z0tdƒ}t  | tdƒtdƒ||t|ƒf ¡ W dd}~X Y nX dS )	zDelete fileNZDeletez'Do you really want to delete <b>%s</b>?FTrÆ   zProject Explorerz9<b>Unable to %s <i>%s</i></b><br><br>Error message:<br>%s)r   ÚYesZYesAllÚNoZCancelÚwarningr   r@   rL   r»   r#   Zremove_filer„   Zremovedr±   ræ   Zremoved_treerJ   rK   r    )rr   r>   ÚmultipleÚ
yes_to_allZbuttonsZanswerrO   Z
action_strr7   r7   r8   Údelete_file>  s4    





$zDirView.delete_filec             C   s†   |dkr|   ¡ }t|ƒdk}d}x`|D ]X}t |d¡}t |¡rbt |¡rbt | tdƒtdƒ¡ q&|  	|||¡}|dk	r&|s&P q&W dS )zDelete filesNra   z.spyprojectzFile ExplorerzŽThe current directory contains a project.<br><br>If you want to delete the project, please go to <b>Projects</b> &raquo; <b>Delete Project</b>)
r¡   rb   r@   rH   rX   Úexistsr   Zinformationr   rì   )rr   r=   rê   rë   r>   Zspyproject_pathr7   r7   r8   rÆ   `  s    
zDirView.deletec          
   C   sh   yt ƒ  |¡d }W n@ tk
rT } z"t | tdƒtdƒt|ƒ ¡ dS d}~X Y nX | jj 	|¡ dS )z8Convert an IPython notebook to a Python script in editorr   zConversion errorz=It was not possible to convert this notebook. The error is:

N)
rÈ   Zfrom_filenameÚ	Exceptionr   rK   r   r    r„   Úsig_new_filer±   )rr   r>   ZscriptÚer7   r7   r8   Úconvert_notebookw  s    zDirView.convert_notebookc             C   s8   |   ¡ }t|ttfƒs|g}x|D ]}|  |¡ q"W dS )z5Convert IPython notebooks to Python scripts in editorN)r¡   r:   r;   r<   rñ   )rr   r=   r>   r7   r7   r8   rÇ   ƒ  s
    
zDirView.convert_notebooksc             C   s$  t  | tdƒtdƒtjt |¡¡\}}|r t t |¡t	|ƒ¡}||krNdS t 
|¡r–t | tdƒtdƒt |¡t |¡f tjtjB ¡tjkr–dS y<t ||¡ t |¡rÀ| jj ||¡ n| jj ||¡ |S  tk
r } z,t | tdƒtdƒt |¡t	|ƒf ¡ W dd}~X Y nX dS )zRename fileZRenamez	New name:NzQDo you really want to rename <b>%s</b> and overwrite the existing file <b>%s</b>?zB<b>Unable to rename file <i>%s</i></b><br><br>Error message:<br>%s)r   r®   r   r   r¯   r@   rL   rH   r4   r    rí   r   ré   rç   rè   r#   Úrename_filer»   r„   Zrenamedr±   Zrenamed_treerJ   rK   )rr   r>   r3   r²   rO   r7   r7   r8   rò   Œ  s.    


zDirView.rename_filec             C   s   |dkr|   ¡ }t|ƒ dS )z#Show file in external file explorerN)r¡   r?   )rr   r=   r7   r7   r8   r?   ©  s    z&DirView.show_in_external_file_explorerc             C   s@   |dkr|   ¡ }t|ttfƒs$|g}x|D ]}|  |¡ q*W dS )zRename filesN)r¡   r:   r;   r<   rò   )rr   r=   r>   r7   r7   r8   rÀ   °  s    
zDirView.renamec             C   sø   |dkr|   ¡ }tt |d ¡ƒ}xZ| jj d¡ |dkrLt| tdƒ|ƒ}n|}| jj d¡ |rvt|ƒ}||krzP q$dS q$W xt|D ]l}t 	|¡}yt
 |t ||¡¡ W q„ tk
rî } z&t | tdƒtdƒ|t|ƒf ¡ W dd}~X Y q„X q„W dS )zMove files/directoriesNr   FzSelect directoryTÚErrorz;<b>Unable to move <i>%s</i></b><br><br>Error message:<br>%s)r¡   rE   r@   r4   r„   Úredirect_stdior±   r   r   rL   r#   Z	move_filerH   rJ   r   rK   r    )rr   r=   Ú	directoryZorigÚfolderr>   rL   rO   r7   r7   r8   rÅ   º  s.    


zDirView.movec             C   s(  |dkrd}t  |¡r t  |¡}t | ||tjd¡\}}|r$t  |t|ƒ¡}zTyt	 
|¡ W n@ tk
rž } z"t | |tdƒ|t|ƒf ¡ W dd}~X Y nX W d|r"t  |d¡}	y(t|	dƒ}
|
 tdƒ¡ W dQ R X |S  tk
r  } z"t | |tdƒ|	t|ƒf ¡ W dd}~X Y nX X dS )zCreate new folderNrF   zD<b>Unable to create folder <i>%s</i></b><br><br>Error message:<br>%sz__init__.pyÚwbú#zB<b>Unable to create file <i>%s</i></b><br><br>Error message:<br>%s)r@   r»   r4   r   r®   r   r¯   rH   r    r2   ÚmkdirrJ   r   rK   r   r-   rI   r   )rr   Úcurrent_pathÚtitleÚsubtitleÚ
is_packager5   r²   r4   rO   r>   r¬   r7   r7   r8   Úcreate_new_folderØ  s2    


&zDirView.create_new_folderc             C   s&   t d ƒ}t dƒ}| j|||dd dS )z
New folderzFolder name:F)rý   N)r   rþ   )rr   rÁ   rû   rü   r7   r7   r8   r·   ù  s    zDirView.new_folderc             C   s&   t d ƒ}t dƒ}| j|||dd dS )zNew packagezPackage name:T)rý   N)r   rþ   )rr   rÁ   rû   rü   r7   r7   r8   r¸   ÿ  s    zDirView.new_packagec             C   s¨   |dkrd}t  |¡r t  |¡}| jj d¡ t| |||ƒ\}}| jj d¡ |r¤y||ƒ |S  tk
r¢ } z&t 	| t
dƒt
dƒ|t|ƒf ¡ W dd}~X Y nX dS )z2Create new file
        Returns True if successfulNrF   FTzNew filezB<b>Unable to create file <i>%s</i></b><br><br>Error message:<br>%s)r@   r»   r4   r„   rô   r±   r   rJ   r   rK   r   r    )rr   rú   rû   r   Úcreate_funcr>   Z
_selfilterrO   r7   r7   r8   Úcreate_new_file  s    

zDirView.create_new_filec             C   sD   t d ƒ}t dƒd }dd„ }|  ||||¡}|dk	r@|  |g¡ dS )zNew filez	All filesz (*)c          	   S   sD   t  | ¡d dkrt| ƒ n$t| dƒ}| tdƒ¡ W dQ R X dS )zFile creation callbackra   )z.pyz.pywz.ipyr÷   rF   N)r@   rw   rP   r-   rI   r   )r>   r¬   r7   r7   r8   rÿ     s    
z%DirView.new_file.<locals>.create_funcN)r   r   r-   )rr   rÁ   rû   r   rÿ   r>   r7   r7   r8   rµ     s    zDirView.new_filec                s4   t d ƒ}t dƒd }‡ fdd„}ˆ  ||||¡ dS )z
New modulezPython scriptsz (*.py *.pyw *.ipy)c                s   ˆ j j | ¡S )N)r„   Úcreate_moduler±   )r>   )rr   r7   r8   r   ,  s    z$DirView.new_module.<locals>.<lambda>N)r   r   )rr   rÁ   rû   r   rÿ   r7   )rr   r8   r¶   (  s    zDirView.new_modulec             C   s   d S )Nr7   )rr   r7   r7   r8   rÕ   /  s    zDirView.go_to_parent_directoryc          
   C   s„   y"xt |ƒD ]}t ||¡ qW W n\ tjk
r~ } z<tdƒ|jd |j¡f }t 	| tdƒtdƒt
|ƒ ¡ W dd}~X Y nX dS )zVCS action (commit, browse)zMFor %s support, please install one of the<br/> following tools:<br/><br/>  %sz, ró   z1<b>Unable to find external program.</b><br><br>%sN)rZ   r%   Zrun_vcs_toolZActionToolNotFoundr   ZvcsnamerH   Ztoolsr   rK   r    )rr   r=   rÌ   r3   rO   Úmsgr7   r7   r8   rÂ   3  s    zDirView.vcs_commandc             C   s   |   ¡  ¡ |  ¡  ¡ fS )zReturn scrollbar positions)ÚhorizontalScrollBarÚvalueÚverticalScrollBar)rr   r7   r7   r8   Úget_scrollbar_positionA  s    
zDirView.get_scrollbar_positionc             C   s*   || _ | jdk	r&t| jƒdkr&|  ¡  dS )zSet scrollbar positionsNr   )r‹   rˆ   rb   Úrestore_scrollbar_positions)rr   Zpositionr7   r7   r8   Úset_scrollbar_positionF  s    zDirView.set_scrollbar_positionc             C   s*   | j \}}|  ¡  |¡ |  ¡  |¡ dS )z/Restore scrollbar positions once tree is loadedN)r‹   r  ZsetValuer  )rr   ZhorZverr7   r7   r8   r  M  s    
z#DirView.restore_scrollbar_positionsc             C   s   |   ¡  | jS )zReturn expanded state)Úsave_expanded_stater‡   )rr   r7   r7   r8   Úget_expanded_stateS  s    zDirView.get_expanded_statec             C   s   || _ |  ¡  dS )zSet expanded stateN)r‡   Úrestore_expanded_state)rr   r™   r7   r7   r8   Úset_expanded_stateX  s    zDirView.set_expanded_statec             C   sH   |   ¡ }|dk	rDg | _x,| ¡ D ] }|  |¡r | j |  |¡¡ q W dS )zSave all items expanded stateN)Úmodelr‡   ZpersistentIndexListZ
isExpandedrY   r   )rr   r  rŸ   r7   r7   r8   r	  ]  s    
zDirView.save_expanded_statec             C   s²   t  t|ƒ¡}t  |¡sdS xzt |¡D ]l}t  t  ||¡¡}t  |¡r(|| jkr(| j 	| j 
|¡¡ | jdkrvg | _| j |¡ |  |  |¡d¡ q(W | js®| jj | j¡ dS )z Restore directory expanded stateNT)r@   rB   r    rí   r2   rU   rH   rX   r‡   Úpoprœ   rˆ   rY   ZsetExpandedrž   r‰   r‘   Ú
disconnectÚrestore_directory_state)rr   r>   ÚrootrL   r3   r7   r7   r8   r  h  s    

zDirView.restore_directory_statec             C   sv   | j dkrdS t t|ƒ¡}|| j kr2| j  |¡ | j dk	rrt| j ƒdkrr| jj | j	¡ | j
dk	rrt d| j¡ dS )z(Follow directories loaded during startupNr   é2   )rˆ   r@   rB   r    Úremoverb   r‰   r‘   r  Úfollow_directories_loadedr‹   r   Z
singleShotr  )rr   r>   r3   r7   r7   r8   r  y  s    


z!DirView.follow_directories_loadedc             C   s:   | j dk	r6t| j tƒr6| jj | j¡ | jj | j¡ dS )z Restore all items expanded stateN)r‡   r:   r<   r‰   r‘   r’   r  r  )rr   r7   r7   r8   r  ‡  s    
zDirView.restore_expanded_statec             C   s,   |   d¡}|dk	r(|  | ¡ | ¡ d¡ dS )zFilter the directories to showz.spyprojectNT)rž   ZsetRowHiddenÚrowrŒ   )rr   rœ   r7   r7   r8   r•   ‘  s    
zDirView.filter_directories)N)N)N)N)N)N)NN)Dr}   r~   r   Ú__doc__rl   rŠ   r   r–   r˜   rš   r   rž   r¡   r¢   r¤   r”   r£   r   r¨   Úboolr©   r¹   rº   rÊ   rÍ   rÎ   rÐ   rÑ   rÔ   rÖ   r×   rÄ   rØ   rÛ   rÝ   rà   r-   râ   rË   r¾   ræ   rì   rÆ   rñ   rÇ   rò   r?   rÀ   rÅ   rþ   r·   r¸   r   rµ   r¶   rÕ   rÂ   r  r  r  r
  r  r	  r  r  r  r•   r   r7   r7   )rs   r8   r‚   ¸   sˆ   
@!

	
	"		!
r‚   c                   sF   e Zd ZdZ‡ fdd„Zdd„ Zejfdd„Zdd	„ Z	d
d„ Z
‡  ZS )Ú
ProxyModelzProxy model: filters tree viewc                s*   t t| ƒ |¡ d | _g | _|  d¡ d S )NT)rk   r  rl   Ú	root_pathÚ	path_listZsetDynamicSortFilter)rr   rŒ   )rs   r7   r8   rl   ™  s    zProxyModel.__init__c             C   s,   t  t|ƒ¡| _dd„ |D ƒ| _|  ¡  dS )z#Setup proxy model filter parametersc             S   s   g | ]}t  t|ƒ¡‘qS r7   )r@   rB   r    )rg   Úpr7   r7   r8   r    ¢  s    z+ProxyModel.setup_filter.<locals>.<listcomp>N)r@   rB   r    r  r  ZinvalidateFilter)rr   r  r  r7   r7   r8   Úsetup_filterŸ  s    zProxyModel.setup_filterc             C   s   |   ¡  ||¡ dS )zReimplement Qt methodN)ÚsourceModelÚsort)rr   ÚcolumnÚorderr7   r7   r8   r  ¥  s    zProxyModel.sortc             C   s|   | j dkrdS |  ¡  |d|¡}t t|  ¡  |¡ƒ¡}| j  |¡rHdS x.| jD ] }||ksl| |t	j
 ¡rPdS qPW dS dS )zReimplement Qt methodNTr   F)r  r  rœ   r@   rB   r    r›   Ú
startswithr  r2   Úsep)rr   r  Zparent_indexrœ   r3   r  r7   r7   r8   ÚfilterAcceptsRow©  s    
zProxyModel.filterAcceptsRowc             C   sH   |t jkr:| jd  tj¡d }| ¡ |kr:t | j|¡S t	 | ||¡S )z7Show tooltip with full path only for the root directoryr   r´   )
r
   ZToolTipRoler  rz   r@   r"  rß   rH   r  r	   )rr   rœ   ZroleZroot_dirr7   r7   r8   rß   ¹  s
    
zProxyModel.data)r}   r~   r   r  rl   r  r
   r“   r  r#  rß   r   r7   r7   )rs   r8   r  —  s   r  c                   sZ   e Zd ZdZd‡ fdd„	Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Z‡  ZS )ÚFilteredDirViewz!Filtered file/directory tree viewNc                s(   t t| ƒ |¡ d | _|  ¡  d | _d S )N)rk   r$  rl   Ú
proxymodelÚsetup_proxy_modelr  )rr   rŒ   )rs   r7   r8   rl   Ã  s    zFilteredDirView.__init__c             C   s   t | ƒ| _| j | j¡ dS )zSetup proxy modelN)r  r%  ZsetSourceModelr‰   )rr   r7   r7   r8   r&  Ê  s    
z!FilteredDirView.setup_proxy_modelc             C   s   | j dk	r|  | j¡ dS )zInstall proxy modelN)r  rŽ   r%  )rr   r7   r7   r8   r   Ï  s    
zFilteredDirView.install_modelc             C   s0   || _ |  ¡  | j |¡}|  | j |¡¡ dS )zSet root pathN)r  r   r‰   ÚsetRootPathÚsetRootIndexr%  ÚmapFromSource)rr   r  rœ   r7   r7   r8   Úset_root_pathÔ  s    zFilteredDirView.set_root_pathc             C   s2   | j  |¡}| ¡ r.| ¡ | j kr.| j |¡S dS )z%Return index associated with filenameN)r‰   rœ   ZisValidr  r%  r)  )rr   r6   rœ   r7   r7   r8   rž   Û  s    zFilteredDirView.get_indexc                s4   ˆ j dk	st‚‡ fdd„|D ƒ}ˆ j ˆ j |¡ dS )zSet folder namesNc                s   g | ]}t  ˆ j|¡‘qS r7   )r@   rH   r  )rg   r4   )rr   r7   r8   r    ä  s   z4FilteredDirView.set_folder_names.<locals>.<listcomp>)r  ÚAssertionErrorr%  r  )rr   Zfolder_namesr  r7   )rr   r8   Úset_folder_namesá  s    
z FilteredDirView.set_folder_namesc             C   s*   |r&| j  | j |¡¡}t t|ƒ¡S dS )zReturn filename from indexN)r‰   r›   r%  ZmapToSourcer@   rB   r    )rr   rœ   r3   r7   r7   r8   r   è  s    zFilteredDirView.get_filenamec             C   s.   xdD ]}|   |¡ qW |  d¡ |  ¡  dS )zSetup view for projects)ra   é   é   TN)Z
hideColumnZsetHeaderHiddenr•   )rr   Úir7   r7   r8   Úsetup_project_viewî  s    

z"FilteredDirView.setup_project_view)N)r}   r~   r   r  rl   r&  r   r*  rž   r,  r   r0  r   r7   r7   )rs   r8   r$  Á  s   r$  c                   s¨   e Zd ZdZeeƒZeeƒZddd„Z‡ fdd„Z	e
eƒdd„ ƒZd	d
„ Zdd„ Zddd„Zdd„ Ze
ƒ dd„ ƒZe
ƒ dd„ ƒZe
ƒ dd„ ƒZdd„ Zddd„Z‡  ZS )ÚExplorerTreeWidgetzÂFile/directory explorer tree widget
    show_cd_only: Show current directory only
    (True/False: enable/disable the option
     None: enable the option and do not allow the user to disable it)Nc             C   sD   t  | |¡ g | _d | _|| _d | _d | _d | _d | _|  	d¡ d S )NT)
r‚   rl   ÚhistoryÚ	histindexÚshow_cd_onlyÚ(_ExplorerTreeWidget__original_root_indexÚ _ExplorerTreeWidget__last_folderr…   r†   ZsetDragEnabled)rr   rŒ   r4  r7   r7   r8   rl   þ  s    zExplorerTreeWidget.__init__c                sZ   t t| ƒ ¡ }| jdkr d| _n6t| tdƒ| jd}| | j¡ |  | j¡ | |¡ |S )z!Setup context menu common actionsNTzShow current directory only)r§   )	rk   r1  r£   r4  r'   r   Útoggle_show_cd_onlyrª   rY   )rr   rÉ   Zcd_only_action)rs   r7   r8   r£     s    


z'ExplorerTreeWidget.setup_common_actionsc             C   sL   | j j d|¡ || _|r2| jdk	rH|  | j¡ n| jdk	rH|  | j¡ dS )z'Toggle show current directory only moder4  N)r„   r°   r±   r4  r6  Úset_current_folderr5  r(  )rr   r³   r7   r7   r8   r7     s    

z&ExplorerTreeWidget.toggle_show_cd_onlyc             C   s:   | j  |¡}|| _| jr6| jdkr,|  ¡ | _|  |¡ |S )z4Set current folder and return associated model indexN)r‰   r'  r6  r4  r5  Z	rootIndexr(  )rr   rö   rœ   r7   r7   r8   r8  ,  s    


z%ExplorerTreeWidget.set_current_folderc             C   s   | j S )N)r6  )rr   r7   r7   r8   Úget_current_folder6  s    z%ExplorerTreeWidget.get_current_folderFc             C   s~   |dkrt ƒ }|r0|  |¡}|  |¡ |  |¡ | j | jdk	oH| jdk¡ | j | jdk	on| jt| j	ƒd k ¡ |  
¡  dS )zPRefresh widget
        force=False: won't refresh widget if path has not changedNr   ra   )r*   r8  ÚexpandZsetCurrentIndexÚset_previous_enabledr±   r3  Úset_next_enabledrb   r2  r•   )rr   Únew_pathÚforce_currentrœ   r7   r7   r8   Úrefresh9  s    


zExplorerTreeWidget.refreshc             C   s   | j |d dS )zDirectory was just clicked)rõ   N)Úchdir)rr   r4   r7   r7   r8   rØ   J  s    z$ExplorerTreeWidget.directory_clickedc             C   s    |   t t tƒ tj¡¡¡ dS )zGo to parent directoryN)r@  r@   rC   rH   r*   r2   rT   )rr   r7   r7   r8   rÕ   O  s    z)ExplorerTreeWidget.go_to_parent_directoryc             C   s   |  j d8  _ | jdd dS )zBack to previous directoryra   T)Úbrowsing_historyN)r3  r@  )rr   r7   r7   r8   Úgo_to_previous_directoryT  s    z+ExplorerTreeWidget.go_to_previous_directoryc             C   s   |  j d7  _ | jdd dS )zReturn to next directoryra   T)rA  N)r3  r@  )rr   r7   r7   r8   Úgo_to_next_directoryZ  s    z'ExplorerTreeWidget.go_to_next_directoryc             C   sX   y*t  t|ƒ¡}|| jkr(| j |¡| _W n( tk
rR   tƒ }| j|dd Y nX dS )zUpdate browse historyT)rõ   rA  N)	r@   rC   r    r2  rœ   r3  rî   r   r@  )rr   rõ   Zuser_directoryr7   r7   r8   Úupdate_history`  s    
z!ExplorerTreeWidget.update_historyc          	   C   sf  |dk	rt  t|ƒ¡}|r(| j| j }n€|| jkrB| j |¡| _nf| jdkrTg | _n| jd| jd … | _t| jƒdksŒ| jr˜| jd |kr˜| j |¡ t| jƒd | _t|ƒ}y| | W n, tk
rè   t	}t
jdkràt}nt}Y nX y*t
 |¡ | jj |¡ | j|dd W nL |k
r>   t | jdtd	ƒ¡ Y n$ |k
r`   | j | j¡ Y nX dS )
z"Set directory as working directoryNra   r   r´   r.   T)r=  r>  ró   z;You don't have the right permissions to open this directory)r@   rC   r    r2  r3  rœ   rb   rY   Ú	NameErrorrd   r2   r5   ZWindowsErrorrc   r@  r„   Úopen_dirr±   r?  r   rK   r   r  )rr   rõ   rA  ÚPermissionErrorÚFileNotFoundErrorr7   r7   r8   r@  j  s>    





zExplorerTreeWidget.chdir)NN)NF)NF)r}   r~   r   r  r   r  r;  r<  rl   r£   r   r7  r8  r9  r?  rØ   rÕ   rB  rC  rD  r@  r   r7   r7   )rs   r8   r1  ö  s   



r1  c               @   sb   e Zd ZdZeeeƒZeeƒZeeƒZ	ee
ƒZeeƒZdddgdddfdd„Zee
ƒd	d
„ ƒZdS )ÚExplorerWidgetzExplorer widgetNz*.pyz*.pywFTc             C   s.  t  | |¡ t| |d| _t| ƒ}t| ƒ}t| ƒ}t| ƒ| _t| ƒ}	|||| jg| _t| t	dƒ| j
d}
t| t	dƒt d¡| jjd}t| t	dƒt d¡| jjd}t| t	d	ƒt d
¡| jjd}t| dt	dƒd}| jj||d | j tƒ ¡ | j jd |
g7  _| |¡ | d¡ | |¡ | d¡ | |¡ | j t d¡¡ | j tj¡ | j |	¡ t|	| jjƒ | |	¡ |  
|¡ |
 |¡ x*| jD ] }| d¡ | tddƒ¡ q˜W tƒ }|  |¡ |  |¡ |  |¡ | !¡  |  | j¡ t"|| jƒ}|  #|¡ | jj$ %|j¡ | jj& %|j¡ d S )N)r4  zShow icons and text)r§   ZPreviousZ	ArrowBack)rN   ru   r¦   ZNextZArrowForwardZParentZArrowUprF   ZOptions)rN   Ztip)rƒ   r]   FZtooloptionsTé   )'r   rl   r1  Ú
treewidgetr   Úbutton_menur   Úaction_widgetsr'   r   Útoggle_icontextrv   ru   rB  rC  rÕ   r¤   r@  r*   r†   ZsetDefaultActionZ
setEnabledZsetIconZsetPopupModeZInstantPopupZsetMenur&   rª   ZsetAutoRaiseZsetIconSizer   r   Ú	addWidgetZ
addStretchr)   Ú	setLayoutr;  r’   r<  )rr   rŒ   rƒ   r]   r4  Úshow_icontextZbutton_previousZbutton_nextZbutton_parentr…   Zicontext_actionZprevious_actionZnext_actionZparent_actionZoptions_actionÚwidgetZblayoutZlayoutr7   r7   r8   rl   š  sd    



















zExplorerWidget.__init__c             C   sJ   | j  d|¡ x6| jD ],}|| jk	r|r6| tj¡ q| tj¡ qW dS )zToggle icon textrQ  N)r°   r±   rM  rL  ZsetToolButtonStyler
   ZToolButtonTextBesideIconZToolButtonIconOnly)rr   r™   rR  r7   r7   r8   rN  á  s    
zExplorerWidget.toggle_icontext)r}   r~   r   r  r   rM   Úobjectr°   rá   rï   r  rô   rF  rl   r   rN  r7   r7   r7   r8   rI  ’  s   
FrI  c               @   s   e Zd Zdd„ ZdS )ÚFileExplorerTestc                sN  t  ˆ ¡ tƒ }ˆ  |¡ tˆ d dˆ _| ˆ j¡ tƒ }| |¡ t	dƒ}| 
tj¡ | |¡ t	ƒ ˆ _| ˆ j¡ ˆ jj ˆ jj¡ tƒ }| |¡ t	dƒ}| 
tj¡ | |¡ t	ƒ ˆ _| ˆ j¡ ˆ jj ˆ jj¡ tƒ }| |¡ t	dƒ}| 
tj¡ | |¡ t	ƒ ˆ _| ˆ j¡ ˆ jj ‡ fdd„¡ ˆ jj ‡ fdd„¡ d S )N)r4  z<b>Open file:</b>z<b>Open dir:</b>z<b>Option changed:</b>c                s   ˆ j  d| |f ¡S )Nzoption_changed: %r, %r)Úlabel3ÚsetText)rh   Úy)rr   r7   r8   r     s    z+FileExplorerTest.__init__.<locals>.<lambda>c                  s   ˆ j j d¡S )Nz..)ÚexplorerrK  r?  r7   )rr   r7   r8   r     s    )r   rl   r   rP  rI  rX  rO  r   Z	addLayoutr   ZsetAlignmentr
   Z
AlignRightZlabel1rá   r’   rV  Zlabel2rF  rU  r°   )rr   ÚvlayoutZhlayout1ZlabelZhlayout2Zhlayout3r7   )rr   r8   rl   ñ  s@    







zFileExplorerTest.__init__N)r}   r~   r   rl   r7   r7   r7   r8   rT  ð  s   rT  c               @   s   e Zd Zddd„ZdS )ÚProjectExplorerTestNc             C   sp   t  | |¡ tƒ }|  |¡ t| ƒ| _| j ¡  | j t 	t 
t¡¡¡ | j dg¡ | j ¡  | | j¡ d S )NZvariableexplorer)r   rl   r   rP  r$  rK  r–   r*  r@   r4   rC   Ú__file__r,  r0  rO  )rr   rŒ   rY  r7   r7   r8   rl     s    



zProjectExplorerTest.__init__)N)r}   r~   r   rl   r7   r7   r7   r8   rZ    s   rZ  c             C   sD   ddl m} |ƒ }| rtƒ }ntƒ }| dd¡ | ¡  | ¡  d S )Nr   )Úqapplicationi€  ià  )Úspyder.utils.qthelpersr\  rT  rZ  ZresizeZshowrÞ   )Úfile_explorerr\  ZappÚtestr7   r7   r8   r_  $  s    r_  Ú__main__T)r^  )N)rQ   rR   FF)Rr  Z
__future__r   r2   Úos.pathr3   r@   rV   rå   r1   r/   Z	mimetypesrx   Zqtpy.compatr   r   Zqtpy.QtCorer   r   r   r   r	   r
   r   r   r   r   Z
qtpy.QtGuir   Zqtpy.QtWidgetsr   r   r   r   r   r   r   r   r   r   r   r   Zspyder.config.baser   r   Zspyder.py3compatr   r   r    Zspyder.utilsr!   rv   r"   r#   r$   r%   r]  r&   r'   r(   r)   Zspyder.utils.miscr*   Z	nbconvertr+   rÈ   r9   r?   rE   rP   rU   re   rf   r‚   r  r$  r1  rI  rT  rZ  r_  r}   r7   r7   r7   r8   Ú<module>   s^   08


 

E     d*5 ^'

