Upload
yuren-ju
View
5.596
Download
5
Tags:
Embed Size (px)
Citation preview
Python and GObject-Introspection
Yuren Ju <[email protected]>
About me
● http://about.me/yurenju ● Hacking Thursday● KaLUG● Twitter: @yurenju
GObject
D-BUS
VTE
notify
Glade GTK
GNOME platform
Library based on GObject
Binding
Use codegen to generate GTK C Wrapper for Python
gtk.c number of lines:
128,469
If GTK+ add APIs in new version,python-gtk also need to upgrade for new APIs.
Implement in Python,Also need to re-implement in Ruby, Perl, Java,
Javscript again.
GObject-Introspection
python-gobject
GTK+GTK+
metadata
Original
GTK+GTK+metadata
python-gobjectparser
GObject-Introspection
GTK+GTK+metadata
GTK+gstreamermetadata
GTK+...metadata
Same metadata format
python-gobjectparser
Parser + metadata = GObject-Introspection
tut-triangle
tut.triangle
+ get_color()+ set_color()+ get_centroid()+ get_centroidu()
Metadata
Comments in Source code
Gir XML file
Typelib binary file
g-ir-scanner
g-ir-compiler
Comments in Source code
http://live.gnome.org/GObjectIntrospection/Annotations
Gir XML file
Metadata
Comments in Source code
Gir XML file
Typelib binary file
g-ir-scanner
g-ir-compiler
libgirepository
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.
gtk.c number of lines:
128,469
How to use GI?from gi.repository import Gtk;
PEP-0302: New Import Hooks
Append finder to sys.meta_path,Use finder.find_module() dynamic to find module.
Load module
● find_module()● load_module()
● Create DynamicModule● Module._load()
– Create self._introspection_module● IntrospectionModule => repository.requre to load typelib
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!
Method – relative easy
object.method()
Call info.invoke()
g_function_info_invoke
Summary
● GI Migrate metadata from language-binding to library
● python-gobject let you use GTK, GObject, Gstreamer, VTE, Dbus,...etc.
一人成佛,雞犬升天