Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-05-31 07:07:14 +0300
committerCampbell Barton <campbell@blender.org>2022-05-31 07:19:06 +0300
commit1c6b66c9cf80b3c9b4542b27948ae232f930a211 (patch)
treef517a723e7935f486cbd683fc3756dc1d6338ff8 /release/scripts/modules/rna_info.py
parent94444aaadf238ab2de4226d6b1b66284d479a931 (diff)
PyDoc: replace in-lined enum references with links where possible
Avoid in-lining large enums such as icons and event types, linking to them instead. This mitigates T76453, where long enums took a lot of space in the docs, this was a problem with `UILayout` where each icon argument would list all icons. [0] worked around the issue using CSS to scroll the list. However this has the draw-back where some items are clipped in a way that's not obvious, see: T87008. The reason this isn't a complete solution is that Python defined enums aren't written into their own pages which can be linked to, although currently there are no large Python enums included in the API docs. All in-lined enums are now under 20 items. [0]: 1e8f2665916c049748a3985a2fce736701925095
Diffstat (limited to 'release/scripts/modules/rna_info.py')
-rw-r--r--release/scripts/modules/rna_info.py36
1 files changed, 32 insertions, 4 deletions
diff --git a/release/scripts/modules/rna_info.py b/release/scripts/modules/rna_info.py
index 04120508df5..4788ed6a5fa 100644
--- a/release/scripts/modules/rna_info.py
+++ b/release/scripts/modules/rna_info.py
@@ -242,6 +242,7 @@ class InfoPropertyRNA:
"default_str",
"default",
"enum_items",
+ "enum_pointer",
"min",
"max",
"array_length",
@@ -285,9 +286,17 @@ class InfoPropertyRNA:
else:
self.fixed_type = None
+ self.enum_pointer = 0
if self.type == "enum":
- self.enum_items[:] = [(item.identifier, item.name, item.description) for item in rna_prop.enum_items]
+ items = tuple(rna_prop.enum_items)
+ items_static = tuple(rna_prop.enum_items_static)
+ self.enum_items[:] = [(item.identifier, item.name, item.description) for item in items]
self.is_enum_flag = rna_prop.is_enum_flag
+ # Prioritize static items as this is never going to be allocated data and is therefor
+ # will be a stable match to compare against.
+ item = (items_static or items)
+ if item:
+ self.enum_pointer = item[0].as_pointer()
else:
self.is_enum_flag = False
@@ -342,7 +351,19 @@ class InfoPropertyRNA:
return "%s=%s" % (self.identifier, default)
return self.identifier
- def get_type_description(self, as_ret=False, as_arg=False, class_fmt="%s", collection_id="Collection"):
+ def get_type_description(
+ self, *,
+ as_ret=False,
+ as_arg=False,
+ class_fmt="%s",
+ collection_id="Collection",
+ enum_descr_override=None,
+ ):
+ """
+ :arg enum_descr_override: Optionally override items for enum.
+ Otherwise expand the literal items.
+ :type enum_descr_override: string or None when unset.
+ """
type_str = ""
if self.fixed_type is None:
type_str += self.type
@@ -357,10 +378,17 @@ class InfoPropertyRNA:
if self.type in {"float", "int"}:
type_str += " in [%s, %s]" % (range_str(self.min), range_str(self.max))
elif self.type == "enum":
+ enum_descr = enum_descr_override
+ if not enum_descr:
+ if self.is_enum_flag:
+ enum_descr = "{%s}" % ", ".join(("'%s'" % s[0]) for s in self.enum_items)
+ else:
+ enum_descr = "[%s]" % ", ".join(("'%s'" % s[0]) for s in self.enum_items)
if self.is_enum_flag:
- type_str += " set in {%s}" % ", ".join(("'%s'" % s[0]) for s in self.enum_items)
+ type_str += " set in %s" % enum_descr
else:
- type_str += " in [%s]" % ", ".join(("'%s'" % s[0]) for s in self.enum_items)
+ type_str += " in %s" % enum_descr
+ del enum_descr
if not (as_arg or as_ret):
# write default property, ignore function args for this