Fix T44822: python enums' itemf callback did not handle 'NULL' context case.

Enum's itemf callback can be called without context in some cases (UI, doc generation...).
Python's enum properties did not handle this at all - it's kind of odd this did not cause
more trouble and wasn't notice earlier... Probably dynamic enums using context are not
much used in py code.

Note about nodes: those are heavy users of dynamic enum with context. Now,
we expect `NodeCategory.poll()` and `NodeItem.poll()` to always be called with
a valid context (since when there is no context available, we can assume `poll()`
is always True). `NodeCategory.items()`, however, must accept NULL context, so if
you use custom `items` callable for your custom node categories, you may need
to update it (as was done here for builtin `node_group_items()`).
This commit is contained in:
2015-05-25 14:19:51 +02:00
parent 39b85e452f
commit a80c1e50bc
4 changed files with 30 additions and 9 deletions

View File

@@ -25,9 +25,12 @@ import bpy
def enum_previews_from_directory_items(self, context):
"""EnumProperty callback"""
wm = context.window_manager
enum_items = []
if context is None:
return enum_items
wm = context.window_manager
directory = wm.my_previews_dir
# Get the preview collection (defined in register func).