ges: docs: Fix enum introspection in document-children-props.py
The script was failing with newer pygobject versions because the __enum_values__ attribute has been removed. Updated to use proper introspection by: - Getting enum type from property default value - Using enum_class.values for the first enum value (index 0) - Creating other enum values with enum_type(i) constructor - Extracting name and nick from enum values properly Also fixed ruff linting issues: - Removed unused imports and variables - Used specific exception types instead of bare except - Added noqa comment for gi import ordering Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5987>
This commit is contained in:
parent
e8cb82137c
commit
b27bcf1751
@ -69,8 +69,8 @@ Valid values:
|
||||
- **left** (0) – left
|
||||
- **center** (1) – center
|
||||
- **right** (2) – right
|
||||
- **Value_3** (3) – value-3
|
||||
- **position** (4) – Absolute position clamped to canvas
|
||||
- **absolute** (5) – Absolute position
|
||||
|
||||
See #GstBaseTextOverlay:halignment
|
||||
|
||||
|
@ -69,8 +69,8 @@ Valid values:
|
||||
- **left** (0) – left
|
||||
- **center** (1) – center
|
||||
- **right** (2) – right
|
||||
- **Value_3** (3) – value-3
|
||||
- **position** (4) – Absolute position clamped to canvas
|
||||
- **absolute** (5) – Absolute position
|
||||
|
||||
See #GstBaseTextOverlay:halignment
|
||||
|
||||
|
60
subprojects/gst-editing-services/docs/libs/document-children-props.py
Normal file → Executable file
60
subprojects/gst-editing-services/docs/libs/document-children-props.py
Normal file → Executable file
@ -5,17 +5,17 @@ Simple script to update the children properties information for
|
||||
GESTrackElement-s that add children properties all the time
|
||||
"""
|
||||
|
||||
import gi
|
||||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
from itertools import chain
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version("Gst", "1.0")
|
||||
gi.require_version("GObject", "2.0")
|
||||
gi.require_version("GES", "1.0")
|
||||
|
||||
from gi.repository import Gst, GES, GObject
|
||||
from gi.repository import Gst, GES, GObject # noqa: E402
|
||||
|
||||
overrides = {
|
||||
"GstFramePositioner": False,
|
||||
@ -25,6 +25,44 @@ overrides = {
|
||||
"GESVideoTransition": "GESVideoTransition",
|
||||
}
|
||||
|
||||
|
||||
def get_enum_values_from_property(prop):
|
||||
"""
|
||||
Get enum values using proper introspection for newer pygobject versions.
|
||||
"""
|
||||
enum_class = prop.enum_class
|
||||
|
||||
# Get the enum type from the default value
|
||||
try:
|
||||
default_val = prop.get_default_value()
|
||||
enum_type = type(default_val)
|
||||
except Exception:
|
||||
# Fallback: create enum values as integers
|
||||
return [(i, f"Value_{i}", f"value-{i}") for i in range(enum_class.n_values)]
|
||||
|
||||
values = []
|
||||
|
||||
# Get all enum values by creating them with integer values
|
||||
for i in range(enum_class.n_values):
|
||||
try:
|
||||
# For other values, create them using the enum type
|
||||
enum_val = enum_type(i)
|
||||
values.append((i, enum_val.value_name, enum_val.value_nick))
|
||||
except Exception:
|
||||
# Fallback for any failed value
|
||||
if i == 0:
|
||||
# Try to get first value info
|
||||
try:
|
||||
first_val = enum_class.values
|
||||
values.append((first_val.value, first_val.value_name, first_val.value_nick))
|
||||
except Exception:
|
||||
values.append((i, f"Value_{i}", f"value-{i}"))
|
||||
else:
|
||||
values.append((i, f"Value_{i}", f"value-{i}"))
|
||||
|
||||
return values
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Gst.init(None)
|
||||
GES.init()
|
||||
@ -47,7 +85,8 @@ if __name__ == "__main__":
|
||||
else:
|
||||
elements.append(c)
|
||||
|
||||
add_clip(GES.UriClipAsset.request_sync(Gst.filename_to_uri(os.path.join("../../", "tests/check/assets/audio_video.ogg"))).extract())
|
||||
add_clip(GES.UriClipAsset.request_sync(Gst.filename_to_uri(
|
||||
os.path.join("../../", "tests/check/assets/audio_video.ogg"))).extract())
|
||||
add_clip(GES.TestClip.new())
|
||||
add_clip(GES.TitleClip.new())
|
||||
|
||||
@ -71,9 +110,16 @@ if __name__ == "__main__":
|
||||
|
||||
if GObject.type_is_a(prop, GObject.ParamSpecEnum.__gtype__):
|
||||
lines += ["", "Valid values:"]
|
||||
for value in prop.enum_class.__enum_values__.values():
|
||||
lines.append(" - **%s** (%d) – %s" % (value.value_name,
|
||||
int(value), value.value_nick))
|
||||
try:
|
||||
# Try the deprecated method first for backward compatibility
|
||||
for value in prop.enum_class.__enum_values__.values():
|
||||
lines.append(" - **%s** (%d) – %s" % (value.value_name,
|
||||
int(value), value.value_nick))
|
||||
except AttributeError:
|
||||
# Handle newer pygobject versions - use proper introspection
|
||||
enum_values = get_enum_values_from_property(prop)
|
||||
for value, name, nick in enum_values:
|
||||
lines.append(" - **%s** (%d) – %s" % (name, value, nick))
|
||||
else:
|
||||
lines += ["", "Value type: #" + prop.value_type.name]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user