Python and GObject-Introspection     Yuren Ju <yurenju@gmail.com>
About me●    http://about.me/yurenju●    Hacking Thursday●    KaLUG●    Twitter: @yurenju
GObject
D-BUS  notifyGlade           GTK   VTE
GNOME platform
Binding Librarybased on GObject
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
Originalpython-gobject   metadata    GTK+     GTK+
GObject-Introspection  python-gobject       parser      metadata      GTK+       GTK+
Same metadata format           python-gobject                parsermetadata       metadata     metadataGTK+GTK+      gstre...
Parser + metadata = GObject-Introspection
tut-triangle  tut.triangle+ get_color()+ set_color()+ get_centroid()+ get_centroidu()
MetadataComments in Source code               g-ir-scanner      Gir XML file               g-ir-compiler   Typelib binary ...
Comments in Source codehttp://live.gnome.org/GObjectIntrospection/Annotations
Gir XML file
Metadata                  Comments in Source code                                 g-ir-scanner                        Gir ...
python-gobjectPyGTK 2.24.0 has been released. This is a stable release supporting the GTK+2.24 API. New users wishing to d...
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()        –   Cre...
Objectfrom gi.repository import Gtk                                                - Widget                               ...
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,    Gstrea...
一人成佛,雞犬升天
Python and GObject Introspection
Upcoming SlideShare
Loading in …5
×

Python and GObject Introspection

6,434 views

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,434
On SlideShare
0
From Embeds
0
Number of Embeds
2,110
Actions
Shares
0
Downloads
39
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Python and GObject Introspection

  1. 1. Python and GObject-Introspection Yuren Ju <yurenju@gmail.com>
  2. 2. About me● http://about.me/yurenju● Hacking Thursday● KaLUG● Twitter: @yurenju
  3. 3. GObject
  4. 4. D-BUS notifyGlade GTK VTE
  5. 5. GNOME platform
  6. 6. Binding Librarybased on GObject
  7. 7. Use codegen to generate GTK C Wrapper for Python gtk.c number of lines: 128,469
  8. 8. If GTK+ add APIs in new version,python-gtk also need to upgrade for new APIs.
  9. 9. Implement in Python,Also need to re-implement in Ruby, Perl, Java, Javscript again.
  10. 10. GObject-Introspection
  11. 11. Originalpython-gobject metadata GTK+ GTK+
  12. 12. GObject-Introspection python-gobject parser metadata GTK+ GTK+
  13. 13. Same metadata format python-gobject parsermetadata metadata metadataGTK+GTK+ gstreamer GTK+ ... GTK+
  14. 14. Parser + metadata = GObject-Introspection
  15. 15. tut-triangle tut.triangle+ get_color()+ set_color()+ get_centroid()+ get_centroidu()
  16. 16. MetadataComments in Source code g-ir-scanner Gir XML file g-ir-compiler Typelib binary file
  17. 17. Comments in Source codehttp://live.gnome.org/GObjectIntrospection/Annotations
  18. 18. Gir XML file
  19. 19. Metadata Comments in Source code g-ir-scanner Gir XML file g-ir-compilerlibgirepository Typelib binary file
  20. 20. 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+ arerecommended to use the GObject-Introspection features available inPyGObject. Existing authors of PyGTK applications are also recommended toport their applications to PyGObject to take advantage of new featuresappearing in GTK-3 and beyond.
  21. 21. gtk.c number of lines:128,469
  22. 22. How to use GI?from gi.repository import Gtk;
  23. 23. PEP-0302: New Import Hooks Append finder to sys.meta_path,Use finder.find_module() dynamic to find module.
  24. 24. Load module● find_module()● load_module() ● Create DynamicModule ● Module._load() – Create self._introspection_module ● IntrospectionModule => repository.requre to load typelib
  25. 25. Objectfrom gi.repository import Gtk - Widget - ContainerInitial all items in Gtk - WindowGet info from ...etc.repository.find_by_name()If item is a object instance, Use a MetaClass“GobjectMeta” to create a class wrapperFinally, you have a Python Class to create Object!
  26. 26. Method – relative easy object.method() Call info.invoke() g_function_info_invoke
  27. 27. Summary● GI Migrate metadata from language-binding to library● python-gobject let you use GTK, GObject, Gstreamer, VTE, Dbus,...etc.
  28. 28. 一人成佛,雞犬升天

×