gdctl: Add None friendly named enum helper to create from string

If the string is None, don't create a named enum instance.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4192>
This commit is contained in:
Jonas Ådahl 2024-12-19 00:44:40 +01:00 committed by Marge Bot
parent d855623fb4
commit 23ab763be0

View File

@ -28,6 +28,17 @@ class NamedEnum(Enum):
if string == enum_string
)
@classmethod
def maybe_from_string(cls, string):
if string:
return next(
enum
for enum, enum_string in cls.enum_names()
if string == enum_string
)
else:
return None
class Transform(NamedEnum):
NORMAL = 0