qtazu icon indicating copy to clipboard operation
qtazu copied to clipboard

Add utility method to retrieve Thumbnail url for an entity

Open BigRoy opened this issue 6 years ago • 3 comments

Issue

The ThumbnailBase label widget is relatively low level in that you have to pass it the required URL it needs to retrieve the thumbnail from using its load method.

Meaning getting a Thumbnail for a User is something like this:

# Load user thumbnail
thumbnail = ThumbnailBase()
thumbnail.setFixedWidth(75)
thumbnail.setFixedHeight(75)
thumbnail.load("pictures/thumbnails/persons/{0}.png".format(user["id"]))

The URL changes dependent on the type of entity you are working with making this slightly more involved, plus you'll need to know the URLs for the entities.

Approach

What if we would hide away these URLs and make it easily accessible through a get_thumbnail_url function.

Here's a quick prototype that has some parts unfinished:

def get_thumbnail_url(entity):
    """Get the related thumbnail for an entity"""
    
    entity_id = entity["id"]
    entity_type = entity["type"]
    if entity_type == "Person":
        return "pictures/thumbnails/persons/{0}.png".format(entity_id)
    elif entity_type == "Project":
        return "pictures/thumbnails/projects/{0}.png".format(entity_id)
    elif entity_type == "Shot" or entity_type == "Asset":
        # Get Main Preview
        preview_file_id = entity.get("preview_file_id")
        if not preview_file_id:
            return
        return "pictures/thumbnails/preview-files/{0}.png".format(preview_file_id)
    elif entity_type == "Task":
        # todo: get latest image content from Comments on Task?
        raise NotImplementedError("Not implemented.")

This way, if any of the URLs change on CG-Wire's API side we would only need to update this one function as opposed to all codebases using qtazu requiring to update the URLs in their code..

BigRoy avatar Dec 10 '19 08:12 BigRoy

todo: get latest image content from Comments on Task?

I think it's an information we can add in Zou.

frankrousseau avatar Dec 14 '19 15:12 frankrousseau

@frankrousseau awesome. Maybe gazu could also provide the utilitity function to fetch a thumbnail URL for an entity as described above? Or isn't it generic enough?

And it'd be perfect if it was possible to get the URL as opposed to just a download function, so that it's doable to download it in different ways, e.g. threaded.

BigRoy avatar Dec 14 '19 15:12 BigRoy

Yes, it sounds better to have this function in gazu.

frankrousseau avatar Dec 14 '19 17:12 frankrousseau