def get_icon_by_extension(fname, scale_factor):
    """Return the icon depending on the file extension"""
    application_icons = {}
    application_icons.update(BIN_FILES)
    application_icons.update(DOCUMENT_FILES)
    if osp.isdir(fname):
        return icon('DirOpenIcon', scale_factor)
    else:
        basename = osp.basename(fname)
        __, extension = osp.splitext(basename.lower())
        mime_type, __ = mime.guess_type(basename)
        icon_by_extension = icon('FileIcon', scale_factor)

        if extension in OFFICE_FILES:
            icon_by_extension = icon(OFFICE_FILES[extension], scale_factor)

        if extension in LANGUAGE_ICONS:
            icon_by_extension = icon(LANGUAGE_ICONS[extension], scale_factor)
        else:
            if extension == '.ipynb':
                if is_dark_interface():
                    icon_by_extension = QIcon(
                        get_image_path('notebook_dark.svg'))
                else:
                    icon_by_extension = QIcon(
                        get_image_path('notebook_light.svg'))
            elif mime_type is not None:
                try:
                    # Fix for issue 5080. Even though
                    # mimetypes.guess_type documentation states that
                    # the return value will be None or a tuple of
                    # the form type/subtype, in the Windows registry,
                    # .sql has a mimetype of text\plain
                    # instead of text/plain therefore mimetypes is
                    # returning it incorrectly.
                    file_type, bin_name = mime_type.split('/')
                except ValueError:
                    file_type = 'text'
                if file_type == 'text':
                    icon_by_extension = icon('TextFileIcon', scale_factor)
                elif file_type == 'audio':
                    icon_by_extension = icon('AudioFileIcon', scale_factor)
                elif file_type == 'video':
                    icon_by_extension = icon('VideoFileIcon', scale_factor)
                elif file_type == 'image':
                    icon_by_extension = icon('ImageFileIcon', scale_factor)
                elif file_type == 'application':
                    if bin_name in application_icons:
                        icon_by_extension = icon(
                            application_icons[bin_name], scale_factor)
    return icon_by_extension
Return the icon depending on the file extension