Improved pyside_cache decorator

This one should work properly when multiple properties use the same
callback function.
This commit is contained in:
Sybren A. Stüvel 2016-11-03 12:53:03 +01:00
parent 079f8ff4c3
commit d2ae3f9cb7

View File

@ -45,7 +45,12 @@ def redraw(self, context):
context.area.tag_redraw() context.area.tag_redraw()
def pyside_cache(wrapped): def pyside_cache(propname):
if callable(propname):
raise TypeError('Usage: pyside_cache("property_name")')
def decorator(wrapped):
"""Stores the result of the callable in Python-managed memory. """Stores the result of the callable in Python-managed memory.
This is to work around the warning at This is to work around the warning at
@ -63,11 +68,13 @@ def pyside_cache(wrapped):
result = wrapped(self, context) result = wrapped(self, context)
return result return result
finally: finally:
wrapped._cached_result = result rna_type, rna_info = getattr(self.bl_rna, propname)
rna_info['_cached_result'] = result
return wrapper return wrapper
return decorator
@pyside_cache @pyside_cache('version')
def blender_syncable_versions(self, context): def blender_syncable_versions(self, context):
"""Returns the list of items used by SyncStatusProperties.version EnumProperty.""" """Returns the list of items used by SyncStatusProperties.version EnumProperty."""
@ -130,7 +137,7 @@ class SyncStatusProperties(PropertyGroup):
self['available_blender_versions'] = new_versions self['available_blender_versions'] = new_versions
@pyside_cache @pyside_cache('project')
def bcloud_available_projects(self, context): def bcloud_available_projects(self, context):
"""Returns the list of items used by BlenderCloudProjectGroup.project EnumProperty.""" """Returns the list of items used by BlenderCloudProjectGroup.project EnumProperty."""