Improved pyside_cache
decorator
This one should work properly when multiple properties use the same callback function.
This commit is contained in:
parent
079f8ff4c3
commit
d2ae3f9cb7
@ -45,7 +45,12 @@ def redraw(self, context):
|
||||
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.
|
||||
|
||||
This is to work around the warning at
|
||||
@ -63,11 +68,13 @@ def pyside_cache(wrapped):
|
||||
result = wrapped(self, context)
|
||||
return result
|
||||
finally:
|
||||
wrapped._cached_result = result
|
||||
rna_type, rna_info = getattr(self.bl_rna, propname)
|
||||
rna_info['_cached_result'] = result
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
|
||||
@pyside_cache
|
||||
@pyside_cache('version')
|
||||
def blender_syncable_versions(self, context):
|
||||
"""Returns the list of items used by SyncStatusProperties.version EnumProperty."""
|
||||
|
||||
@ -130,7 +137,7 @@ class SyncStatusProperties(PropertyGroup):
|
||||
self['available_blender_versions'] = new_versions
|
||||
|
||||
|
||||
@pyside_cache
|
||||
@pyside_cache('project')
|
||||
def bcloud_available_projects(self, context):
|
||||
"""Returns the list of items used by BlenderCloudProjectGroup.project EnumProperty."""
|
||||
|
||||
|
Reference in New Issue
Block a user