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:
parent
d855623fb4
commit
23ab763be0
11
tools/gdctl
11
tools/gdctl
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user