-
Notifications
You must be signed in to change notification settings - Fork 82
Using Graphene from Python
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.
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>
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.