diff --git a/blender_cloud/__init__.py b/blender_cloud/__init__.py index a669700..93c3fa0 100644 --- a/blender_cloud/__init__.py +++ b/blender_cloud/__init__.py @@ -72,6 +72,7 @@ def register(): reload_mod('blendfile') reload_mod('home_project') + reload_mod('utils') blender = reload_mod('blender') async_loop = reload_mod('async_loop') diff --git a/blender_cloud/pillar.py b/blender_cloud/pillar.py index 1a8d7d9..01ef73f 100644 --- a/blender_cloud/pillar.py +++ b/blender_cloud/pillar.py @@ -592,7 +592,8 @@ async def download_texture_thumbnail(texture_node, desired_size: str, # Load the File that belongs to this texture node's picture. loop.call_soon_threadsafe(thumbnail_loading, texture_node, texture_node) file_desc = await pillar_call(pillarsdk.File.find, pic_uuid, params={ - 'projection': {'filename': 1, 'variations': 1, 'width': 1, 'height': 1}, + 'projection': {'filename': 1, 'variations': 1, 'width': 1, 'height': 1, + 'length': 1}, }) if file_desc is None: diff --git a/blender_cloud/texture_browser.py b/blender_cloud/texture_browser.py index 8a0fc8f..2ef869d 100644 --- a/blender_cloud/texture_browser.py +++ b/blender_cloud/texture_browser.py @@ -26,7 +26,7 @@ import bgl import blf import pillarsdk -from . import async_loop, pillar, cache, blender +from . import async_loop, pillar, cache, blender, utils REQUIRED_ROLES_FOR_TEXTURE_BROWSER = {'subscriber', 'demo'} MOUSE_SCROLL_PIXELS_PER_TICK = 50 @@ -511,10 +511,14 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin, self.update_menu_item(node, file_desc, thumb_path) def hdri_thumbnail_loading(node, texture_node): - self.add_menu_item(node, None, 'SPINNER', node.resolution) + self.add_menu_item(node, None, 'SPINNER', + 'Resolution: %s' % node.resolution) def hdri_thumbnail_loaded(node, file_desc, thumb_path): - self.update_menu_item(node, file_desc, thumb_path) + filesize = utils.sizeof_fmt(file_desc.length) + + self.update_menu_item(node, file_desc, thumb_path, + 'Resolution: %s (%s)' % (node.resolution, filesize)) project_uuid = self.current_path.project_uuid node_uuid = self.current_path.node_uuid diff --git a/blender_cloud/utils.py b/blender_cloud/utils.py new file mode 100644 index 0000000..635b25e --- /dev/null +++ b/blender_cloud/utils.py @@ -0,0 +1,31 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + + +def sizeof_fmt(num: int, suffix='B') -> str: + """Returns a human-readable size. + + Source: http://stackoverflow.com/a/1094933/875379 + """ + + for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']: + if abs(num) < 1024: + return '%.1f %s%s' % (num, unit, suffix) + num /= 1024 + + return '%.1f Yi%s' % (num, suffix)