How can I use GObject.GEnum as a property type in PyGobject. For example Gtk.Box has a property halign of type Gtk.Align enum. Now let’s say I’ve the following:
It isn’t currently possible to register new enumeration types with current stable releases of PyGObject. Support was merged to main earlier today though:
With those changes, your example_enum class definition will automatically register a new GType for the enumeration with the two values you’ve defined. You should then be able to use it the same way as any other registered enumeration:
Under the covers, GEnum and GFlags are now subclasses of the standard libraryenum.IntEnum and enum.IntFlag classes respectively. A custom metaclass is used to hook into the attempt to create a subclass: it notices that example_enum doesn’t have a GType, so registers a new one based on the declared enumeration values.
Thanks for the reply. Can you please tell me how can I add a GObect.GEnum as a property type with required parameters? In my case for example_enum I’m trying to do it like this: