diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-05-25 15:19:51 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-05-25 15:24:49 +0300 |
commit | a80c1e50bc7f57bc4d4c41bc51ac92d1d4c39030 (patch) | |
tree | 8fe72199e33ab4edf8e966b5e95690819dc766d4 /release/scripts | |
parent | 39b85e452faae543d10831e4fa66fdffbc22e0a1 (diff) |
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()`).
Diffstat (limited to 'release/scripts')
-rw-r--r-- | release/scripts/modules/nodeitems_utils.py | 4 | ||||
-rw-r--r-- | release/scripts/startup/nodeitems_builtins.py | 2 | ||||
-rw-r--r-- | release/scripts/templates_py/ui_previews_dynamic_enum.py | 7 |
3 files changed, 9 insertions, 4 deletions
diff --git a/release/scripts/modules/nodeitems_utils.py b/release/scripts/modules/nodeitems_utils.py index 2882a08fbd4..ff2100916fc 100644 --- a/release/scripts/modules/nodeitems_utils.py +++ b/release/scripts/modules/nodeitems_utils.py @@ -37,7 +37,7 @@ class NodeCategory: else: def items_gen(context): for item in items: - if item.poll is None or item.poll(context): + if item.poll is None or context is None or item.poll(context): yield item self.items = items_gen @@ -136,7 +136,7 @@ def register_node_categories(identifier, cat_list): def node_categories_iter(context): for cat_type in _node_categories.values(): for cat in cat_type[0]: - if cat.poll and cat.poll(context): + if cat.poll and ((context is None) or cat.poll(context)): yield cat diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py index 98c524b0b37..bee48de42f5 100644 --- a/release/scripts/startup/nodeitems_builtins.py +++ b/release/scripts/startup/nodeitems_builtins.py @@ -66,6 +66,8 @@ node_tree_group_type = { # generic node group items generator for shader, compositor and texture node groups def node_group_items(context): + if context is None: + return space = context.space_data if not space: return diff --git a/release/scripts/templates_py/ui_previews_dynamic_enum.py b/release/scripts/templates_py/ui_previews_dynamic_enum.py index 5269f7fa40b..5169b82992e 100644 --- a/release/scripts/templates_py/ui_previews_dynamic_enum.py +++ b/release/scripts/templates_py/ui_previews_dynamic_enum.py @@ -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). |