Ejemplo n.º 1
0
def as_qicon(obj):
    pixmap = None

    if isinstance(obj, QtGui.QIcon):
        return obj

    if isinstance(obj, str):
        obj = Path(obj)

    try:
        PathLike = os.PathLike
    except AttributeError:
        PathLike = Path

    if isinstance(obj, PathLike):
        #                if obj.is_file():
        pixmap = QtGui.QPixmap(str(obj))

    if (Image is not None) and isinstance(obj, Image.Image):
        pixmap = obj.toqpixmap()

    if pixmap is not None:
        return QtGui.QIcon(pixmap)  #.scaled(00, 100))
    else:
        raise TypeError("""Icons can be created from any of the following:
    - str
    - os.Pathlike
    - QtGui.QIcon
    - PIL.Image.Image
Received {}""".format(type(obj)))