Texture browser: nicer handling of still-loading menu items.

This commit is contained in:
Sybren A. Stüvel 2016-07-22 16:50:25 +02:00
parent b33ec74347
commit 76ca59251b

View File

@ -125,6 +125,7 @@ class MenuItem:
self._thumb_path = '' self._thumb_path = ''
self.icon = None self.icon = None
self._is_folder = node['node_type'] in self.FOLDER_NODE_TYPES self._is_folder = node['node_type'] in self.FOLDER_NODE_TYPES
self._is_spinning = False
# Determine sorting order. # Determine sorting order.
# by default, sort all the way at the end and folders first. # by default, sort all the way at the end and folders first.
@ -150,6 +151,8 @@ class MenuItem:
@thumb_path.setter @thumb_path.setter
def thumb_path(self, new_thumb_path: str): def thumb_path(self, new_thumb_path: str):
self._is_spinning = new_thumb_path == 'SPINNER'
self._thumb_path = self.DEFAULT_ICONS.get(new_thumb_path, new_thumb_path) self._thumb_path = self.DEFAULT_ICONS.get(new_thumb_path, new_thumb_path)
if self._thumb_path: if self._thumb_path:
self.icon = bpy.data.images.load(filepath=self._thumb_path) self.icon = bpy.data.images.load(filepath=self._thumb_path)
@ -191,6 +194,10 @@ class MenuItem:
def is_folder(self) -> bool: def is_folder(self) -> bool:
return self._is_folder return self._is_folder
@property
def is_spinning(self) -> bool:
return self._is_spinning
def update_placement(self, x, y, width, height): def update_placement(self, x, y, width, height):
"""Use OpenGL to draw this one menu item.""" """Use OpenGL to draw this one menu item."""
@ -346,7 +353,10 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
selected = self.get_clicked() selected = self.get_clicked()
if selected: if selected:
context.window.cursor_set('HAND') if selected.is_spinning:
context.window.cursor_set('WAIT')
else:
context.window.cursor_set('HAND')
else: else:
context.window.cursor_set('DEFAULT') context.window.cursor_set('DEFAULT')
@ -367,15 +377,13 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin,
# No item clicked, ignore it. # No item clicked, ignore it.
return {'RUNNING_MODAL'} return {'RUNNING_MODAL'}
if selected.is_spinning:
# This can happen when the thumbnail information isn't loaded yet.
return {'RUNNING_MODAL'}
if selected.is_folder: if selected.is_folder:
self.descend_node(selected) self.descend_node(selected)
else: else:
if selected.file_desc is None:
# This can happen when the thumbnail information isn't loaded yet.
# Just ignore the click for now.
# TODO: think of a way to handle this properly.
self.log.debug('Selected item %r has no file_desc', selected)
return {'RUNNING_MODAL'}
self.handle_item_selection(context, selected) self.handle_item_selection(context, selected)
if event.type in {'RIGHTMOUSE', 'ESC'}: if event.type in {'RIGHTMOUSE', 'ESC'}: