
    Je.                         d 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m	Z	m
Z
 ddlmZmZ ddlmZ ddlmZ ddlmZ d Zdd	Zd
 Zd ZddZd Z G d de      Zy)zExplorer widget utilities.    N)	QFileInfoSlot)QFileIconProviderQMessageBox)_)encoding)imac                    t         j                  dk(  rt        j                  dd| g       y t        j
                  dk(  rmt        j                  j                  |       rt        j                  dd| g       y t        j                  dt        j                  j                  |       g       y t        j                  j                  |       } t        j                  d| g       y )Ndarwinopenz-Rntexplorerz/select,zxdg-open)	sysplatform
subprocesscallosnamepathexistsdirname)filenames    G/usr/lib/python3/dist-packages/spyder/plugins/explorer/widgets/utils.pyopen_file_in_external_explorerr      s    
||xx01	D77>>(#OOZX>?OOZ)BCD77??8,X./    c                 Z    t        | t        t        f      s| g} | D ]  }t        |        y)zcShow files in external file explorer

    Args:
        fnames (list): Names of files to show.
    N)
isinstancetuplelistr   )fnamesfnames     r   show_in_external_file_explorerr"   '   s0     fudm, .&u-.r   c                     t         j                  dk(  rt        j                  nt        j                  } |t        j
                  t        j                  |                   S )zANormalize path fixing case, making absolute and removing symlinksr   )r   r   ospnormcasenormpathabspathrealpath)r   norms     r   fixpathr*   3   s8    77d?3<<DCLL./00r   c           	      F   t         j                  j                  g d      }	 t        j                  t        |      | d       y# t        $ rS}t        j                  t        d      t        d      t        j                  |       t        |      fz         Y d}~yd}~ww xY w)zCreate a new Python script)z# -*- coding: utf-8 -*- r,   zutf-8z
Save Errorz;<b>Unable to save file '%s'</b><br><br>Error message:<br>%sN)r   linesepjoinr   writestrEnvironmentErrorr   criticalr   r$   basename)r!   texterrors      r   create_scriptr6   9   s    ::??>?DFs4y%1 FQ|_  > !$'LL$7U#DE	F 	FFs    A 	B A	BB c                    g }t        t        j                        g}t        j                  t        |             D ]  }t        j                  ||      rt        j                  t        j                  | |            r|j                  |       U|rXt        j                  ||      so|j                  |        t        |t         j                        t        |t         j                        z   S )zList files and directories)key)r0   r$   pardirr   listdirresearchisdirr.   appendsortedlower)r   includeexcludefolders_onlynamelistdirlistitems          r   r:   r:   E   s    H3::G

3t9% "99Wd#99SXXdD)*NN4 YYw%OOD!" 'syy)F8,KKKr   c                 d    	 t        t        | ||d            dkD  S # t        t        f$ r Y yw xY w)z&Return True if path has subdirectoriesT)rC      F)lenr:   IOErrorOSError)r   rA   rB   s      r   has_subdirectoriesrL   U   s9    74'EFJJW s    //c                   X     e Zd ZdZ fdZ ee       ee       fd              Z xZ	S )IconProviderz!Project tree widget icon providerc                 8    t         t        |           || _        y N)superrN   __init__treeview)selfrS   	__class__s     r   rR   zIconProvider.__init__a   s    lD*, r   c                 n   t        |t        j                        rt        t        |   |      S |}t        j                  t        |j                                     }t        j                  |      st        j                  |      rt        j                  |d      }|S t        j
                  d      }|S )zReimplement Qt methodg      ?)scale_factorbinary)r   r   IconTyperQ   rN   iconr$   r&   r0   absoluteFilePathisfiler=   r	   get_icon_by_extension_or_type)rT   icontype_or_qfileinfo	qfileinfor!   rZ   rU   s        r   rZ   zIconProvider.icone   s     +->-G-GHt12GHH-ILLY%?%?%A!BCEzz% CIIe$488FIK K xx)Kr   )
__name__
__module____qualname____doc__rR   r   intr   rZ   __classcell__)rU   s   @r   rN   rN   ^   s/    +! 
#Y	)_  r   rN   rP   ).z
\.pyc$|^\.F)rc   r   os.pathr   r$   r;   r   r   qtpy.QtCorer   r   qtpy.QtWidgetsr   r   spyder.api.translationsr   spyder.utilsr   spyder.utils.icon_managerr	   r   r"   r*   r6   r:   rL   rN    r   r   <module>rn      s[    ! 
  	  
 ( 9 & ! )
0	.1	FL $ r   