def native_item_icon(item_path): """Returns the system icon for the given file or folder. If there is no item at the given path, the systems default file icon will be returned. :param str item_path: Path to local item. """ while not osp.exists(item_path): # We create a temporary file with the given extension to get the correct icon # this is necessary because QFileIconProvider has no API to get an icon for a # file extension. _, extension = osp.splitext(item_path) try: item_path = _tmp_file_for_ext[extension] except KeyError: tmp_file = QtCore.QTemporaryFile( osp.join(QtCore.QDir.tempPath(), f"XXXXXX{extension}")) tmp_file.setAutoRemove(False) # open and close to create tmp_file.open() tmp_file.close() item_path = tmp_file.fileName() _tmp_file_for_ext[extension] = item_path return _icon_provider.icon(QtCore.QFileInfo(item_path))
def native_file_icon(): """Returns the system's default file icon.""" # use a real file here because Qt may otherwise # return the wrong folder icon in some cases return _icon_provider.icon(QtCore.QFileInfo(resource_path("file")))
def native_folder_icon(): """Returns the system's default folder icon.""" # use a real folder here because Qt may otherwise # return the wrong folder icon in some cases return _icon_provider.icon(QtCore.QFileInfo("/usr"))