How to use python types as property types in PyGobject

I’ve a GObject.Object subclass that declares a list type property. I use __gproperties__ to declare properties:

__gproperties__ = {
    "date": (
        list,
        "date property",
        "A property describing the current date",
        [],
        GObject.ParamFlags.READWRITE
    )
}

But it’s showing TypeError: could not get typecode from object. PyGobject documentation says properties can take GTypes or python types which will get converted to a GType.

Hi,

I’m not sure there is a GType equivalent for tuple

Personally, if the property is only used on Python side, I just set the type to object.
If you need to interact with other languages or bindings (like for plugins), better use a typed list, like GObject.TYPE_STRV for strings.

The Python tuple has not representation in GType. You can only use types that have a corresponding GType as property types.

If you want to add a date representation, use GLib.DateTime, instead of a tuple.

You probably want to file an issue against pygobject to clarify the sentence on the documentation.

Sorry that was a typo :sweat_smile: . I tried with list and dict too but the error was same.

Edit: Nvm found an open issue on their repo regarding list not working.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.