Add utility method to retrieve Thumbnail url for an entity
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..
todo: get latest image content from Comments on Task?
I think it's an information we can add in Zou.
@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.
Yes, it sounds better to have this function in gazu.