diff --git a/spyder/utils/icon_manager.py b/spyder/utils/icon_manager.py index b7550e794ac..de41d40d308 100644 --- a/spyder/utils/icon_manager.py +++ b/spyder/utils/icon_manager.py @@ -173,6 +173,15 @@ 'MessageBoxInformation': [('fa.info',), {'color': '3775a9'}], 'DirOpenIcon': [('fa.folder-open',), {}], 'FileIcon': [('fa.file-o',), {}], + 'ExcelFileIcon': [('fa.file-excel-o',), {}], + 'WordFileIcon': [('fa.file-word-o',), {}], + 'PowerpointFileIcon': [('fa.file-powerpoint-o',), {}], + 'PDFIcon': [('fa.file-pdf-o',), {}], + 'AudioFileIcon': [('fa.file-audio-o',), {}], + 'ImageFileIcon': [('fa.file-image-o',), {}], + 'ArchiveFileIcon': [('fa.file-archive-o',), {}], + 'VideoFileIcon': [('fa.file-video-o',), {}], + 'TextFileIcon': [('fa.file-text-o',), {}], 'project': [('fa.folder-open-o',), {}], 'DriveHDIcon': [('fa.hdd-o',), {}], 'arrow': [('fa.arrow-right',), {}], diff --git a/spyder/widgets/explorer.py b/spyder/widgets/explorer.py index a72be2c379e..965f52d9c15 100644 --- a/spyder/widgets/explorer.py +++ b/spyder/widgets/explorer.py @@ -19,6 +19,7 @@ import shutil import subprocess import sys +import mimetypes as mime # Third party imports from qtpy import API, is_pyqt46 @@ -106,10 +107,28 @@ def has_subdirectories(path, include, exclude, show_all): class IconProvider(QFileIconProvider): + BIN_FILES = {x: 'ArchiveFileIcon' for x in ['zip', 'x-tar', + 'x-7z-compressed', 'rar']} + DOCUMENT_FILES = {'vnd.ms-powerpoint': 'PowerpointFileIcon', + 'vnd.openxmlformats-officedocument.' + 'presentationml.presentation': 'PowerpointFileIcon', + 'msword': 'WordFileIcon', + 'vnd.openxmlformats-officedocument.' + 'wordprocessingml.document': 'WordFileIcon', + 'vnd.ms-excel': 'ExcelFileIcon', + 'vnd.openxmlformats-officedocument.' + 'spreadsheetml.sheet': 'ExcelFileIcon', + 'pdf': 'PDFIcon'} + OFFICE_FILES = {'.xlsx': 'ExcelFileIcon', '.docx': 'WordFileIcon', + '.pptx': 'PowerpointFileIcon'} + """Project tree widget icon provider""" def __init__(self, treeview): super(IconProvider, self).__init__() self.treeview = treeview + self.application_icons = {} + self.application_icons.update(self.BIN_FILES) + self.application_icons.update(self.DOCUMENT_FILES) @Slot(int) @Slot(QFileInfo) @@ -123,7 +142,28 @@ def icon(self, icontype_or_qfileinfo): if osp.isdir(fname): return ima.icon('DirOpenIcon') else: - return ima.icon('FileIcon') + basename = osp.basename(fname) + _, extension = osp.splitext(basename) + mime_type, _ = mime.guess_type(basename) + icon = ima.icon('FileIcon') + + if extension in self.OFFICE_FILES: + icon = ima.icon(self.OFFICE_FILES[extension]) + + if mime_type is not None: + file_type, bin_name = mime_type.split('/') + if file_type == 'text': + icon = ima.icon('TextFileIcon') + elif file_type == 'audio': + icon = ima.icon('AudioFileIcon') + elif file_type == 'video': + icon = ima.icon('VideoFileIcon') + elif file_type == 'image': + icon = ima.icon('ImageFileIcon') + elif file_type == 'application': + if bin_name in self.application_icons: + icon = ima.icon(self.application_icons[bin_name]) + return icon class DirView(QTreeView):