Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add more file type icons to File Explorer #4598

Merged
merged 5 commits into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions spyder/utils/icon_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',), {}],
Expand Down
42 changes: 41 additions & 1 deletion spyder/widgets/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import shutil
import subprocess
import sys
import mimetypes as mime

# Third party imports
from qtpy import API, is_pyqt46
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down