Python and GObject Introspection

29
Python and GObject-Introspection Yuren Ju <[email protected]>

Transcript of Python and GObject Introspection

Page 1: Python and GObject Introspection

Python and GObject-Introspection

Yuren Ju <[email protected]>

Page 2: Python and GObject Introspection

About me

● http://about.me/yurenju ● Hacking Thursday● KaLUG● Twitter: @yurenju

Page 3: Python and GObject Introspection

GObject

Page 4: Python and GObject Introspection

D-BUS

VTE

notify

Glade GTK

Page 5: Python and GObject Introspection

GNOME platform

Page 6: Python and GObject Introspection

Library based on GObject

Binding

Page 7: Python and GObject Introspection
Page 8: Python and GObject Introspection

Use codegen to generate GTK C Wrapper for Python

gtk.c number of lines:

128,469

Page 9: Python and GObject Introspection

If GTK+ add APIs in new version,python-gtk also need to upgrade for new APIs.

Page 10: Python and GObject Introspection

Implement in Python,Also need to re-implement in Ruby, Perl, Java,

Javscript again.

Page 11: Python and GObject Introspection

GObject-Introspection

Page 12: Python and GObject Introspection

python-gobject

GTK+GTK+

metadata

Original

Page 13: Python and GObject Introspection

GTK+GTK+metadata

python-gobjectparser

GObject-Introspection

Page 14: Python and GObject Introspection

GTK+GTK+metadata

GTK+gstreamermetadata

GTK+...metadata

Same metadata format

python-gobjectparser

Page 15: Python and GObject Introspection

Parser + metadata = GObject-Introspection

Page 16: Python and GObject Introspection

tut-triangle

tut.triangle

+ get_color()+ set_color()+ get_centroid()+ get_centroidu()

Page 17: Python and GObject Introspection

Metadata

Comments in Source code

Gir XML file

Typelib binary file

g-ir-scanner

g-ir-compiler

Page 18: Python and GObject Introspection

Comments in Source code

http://live.gnome.org/GObjectIntrospection/Annotations

Page 19: Python and GObject Introspection

Gir XML file

Page 20: Python and GObject Introspection

Metadata

Comments in Source code

Gir XML file

Typelib binary file

g-ir-scanner

g-ir-compiler

libgirepository

Page 21: Python and GObject Introspection

python-gobjectPyGTK 2.24.0 has been released. This is a stable release supporting the GTK+ 2.24 API. New users wishing to develop Python applications using GTK+ are recommended to use the GObject-Introspection features available in PyGObject. Existing authors of PyGTK applications are also recommended to port their applications to PyGObject to take advantage of new features appearing in GTK-3 and beyond.

Page 22: Python and GObject Introspection

gtk.c number of lines:

128,469

Page 23: Python and GObject Introspection

How to use GI?from gi.repository import Gtk;

Page 24: Python and GObject Introspection

PEP-0302: New Import Hooks

Append finder to sys.meta_path,Use finder.find_module() dynamic to find module.

Page 25: Python and GObject Introspection

Load module

● find_module()● load_module()

● Create DynamicModule● Module._load()

– Create self._introspection_module● IntrospectionModule => repository.requre to load typelib

Page 26: Python and GObject Introspection

Objectfrom gi.repository import Gtk

Initial all items in Gtk

- Widget- Container- Window

...etc.Get info fromrepository.find_by_name()

If item is a object instance, Use a MetaClass“GobjectMeta” to create a class wrapper

Finally, you have a Python Class to create Object!

Page 27: Python and GObject Introspection

Method – relative easy

object.method()

Call info.invoke()

g_function_info_invoke

Page 28: Python and GObject Introspection

Summary

● GI Migrate metadata from language-binding to library

● python-gobject let you use GTK, GObject, Gstreamer, VTE, Dbus,...etc.

Page 29: Python and GObject Introspection

一人成佛,雞犬升天