Skip to content

Using Graphene from Python

Emmanuele Bassi edited this page Jan 10, 2015 · 1 revision

Graphene can optionally generate GObject types, and thus introspection data through GObject-Introspection.

PyGObject can consume the introspection data, and allow access to the Graphene data types in Python. There are a couple of "gotchas" in the usage of Graphene API from Python, though.

Types

The Graphene types exposed through introspection are the wrappers for GObject, and thus adhere to the GObject CamelCase style. For instance, graphene_matrix_t becomes GrapheneMatrix. The rule of thumb for translating Graphene types is:

graphene_<type>_t → Graphene<Type>

Construction

New instances of Graphene types should be instantiated using the alloc() class method.

>>> m = Graphene.Matrix.alloc()
>>> m.init_identity()

You can chain alloc() with one of the initializer functions. For instance, the two lines above are equivalent to the single line below:

>>> m = Graphene.Matrix.alloc().init_from_identity()

Do not use the normal Python form:

>>> m = Graphene.Matrix()

The normal Python form for Graphene types won't accept arguments either, so you'll still need to initialize the type explicitly.

...

Clone this wiki locally