Context: implement indexing for list properties in path_resolve.
The real RNA path_resolve method supports indexing lists, but the python version on the Context object does not. This patch adds the missing feature for completeness. Differential Revision: https://developer.blender.org/D15413
This commit is contained in:
parent
1f8567ac68
commit
935b7a6f65
@ -56,6 +56,21 @@ class Context(StructRNA):
|
||||
if value is None:
|
||||
return value
|
||||
|
||||
# If the attribute is a list property, apply subscripting.
|
||||
if isinstance(value, list) and path_rest.startswith("["):
|
||||
index_str, div, index_tail = path_rest[1:].partition("]")
|
||||
if not div:
|
||||
raise ValueError("Path index is not terminated: %s%s" % (attr, path_rest))
|
||||
try:
|
||||
index = int(index_str)
|
||||
except ValueError:
|
||||
raise ValueError("Path index is invalid: %s[%s]" % (attr, index_str))
|
||||
if 0 <= index < len(value):
|
||||
path_rest = index_tail
|
||||
value = value[index]
|
||||
else:
|
||||
raise IndexError("Path index out of range: %s[%s]" % (attr, index_str))
|
||||
|
||||
# Resolve the rest of the path if necessary.
|
||||
if path_rest:
|
||||
path_resolve_fn = getattr(value, "path_resolve", None)
|
||||
|
Loading…
Reference in New Issue
Block a user