SlideShare a Scribd company logo
Python and GObject-Introspection

     Yuren Ju <yurenju@gmail.com>
About me
●
    http://about.me/yurenju
●
    Hacking Thursday
●
    KaLUG
●
    Twitter: @yurenju
GObject
D-BUS
  notify




Glade
           GTK   VTE
GNOME platform
Binding



 Library
based on GObject
Python and GObject Introspection
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
Original

python-gobject
   metadata




    GTK+
     GTK+
GObject-Introspection

  python-gobject
       parser


      metadata
      GTK+
       GTK+
Same metadata format



           python-gobject
                parser


metadata       metadata     metadata
GTK+GTK+      gstreamer
                     GTK+      ... GTK+
Parser + metadata = GObject-Introspection
tut-triangle

  tut.triangle
+ get_color()
+ set_color()
+ get_centroid()
+ get_centroidu()
Metadata

Comments in Source code

               g-ir-scanner

      Gir XML file

               g-ir-compiler


   Typelib binary file
Comments in Source code




http://live.gnome.org/GObjectIntrospection/Annotations
Gir XML file
Metadata

                  Comments in Source code

                                 g-ir-scanner

                        Gir XML file

                                 g-ir-compiler


libgirepository      Typelib binary file
python-gobject
PyGTK 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
Object
from gi.repository import Gtk
                                                - Widget
                                                - Container
Initial all items in Gtk                        - Window


Get info from                                        ...etc.
repository.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.
一人成佛,雞犬升天

More Related Content

PDF
Binary Reading in C#
PDF
Andrew Goldberg. The Binary Blocking Flow Algorithm for the Maximum Flow Problem
PDF
Unifying Network Filtering Rules for the Linux Kernel with eBPF
PDF
JIT のコードを読んでみた
ODP
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
PDF
TiDB for Big Data
PPTX
Python Streaming Pipelines with Beam on Flink
Binary Reading in C#
Andrew Goldberg. The Binary Blocking Flow Algorithm for the Maximum Flow Problem
Unifying Network Filtering Rules for the Linux Kernel with eBPF
JIT のコードを読んでみた
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
TiDB for Big Data
Python Streaming Pipelines with Beam on Flink

What's hot (13)

PDF
Faster packet processing in Linux: XDP
PDF
LineairDB: Fast and Embedded Transactional Key-Value Storage
PDF
MySQL Scalability and Reliability for Replicated Environment
PDF
Linux binary Exploitation - Basic knowledge
PDF
寫給大家的 Git 教學
PDF
Go入門
PDF
Docker infiniband
PDF
ScyllaDBユーザー勉強会 #1
PPT
Timing wheels
PDF
超簡単!TELNETの話
PDF
SSE4.2の文字列処理命令の紹介
PDF
Jakarta EE 10 - Simplicity for Modern and Lighweight Cloud
PPTX
このPHP QAツールがすごい!2019
Faster packet processing in Linux: XDP
LineairDB: Fast and Embedded Transactional Key-Value Storage
MySQL Scalability and Reliability for Replicated Environment
Linux binary Exploitation - Basic knowledge
寫給大家的 Git 教學
Go入門
Docker infiniband
ScyllaDBユーザー勉強会 #1
Timing wheels
超簡単!TELNETの話
SSE4.2の文字列処理命令の紹介
Jakarta EE 10 - Simplicity for Modern and Lighweight Cloud
このPHP QAツールがすごい!2019
Ad

Similar to Python and GObject Introspection (20)

PDF
Basics of gtk_ilugc
PDF
Gtk development-using-glade-3
PDF
Intro to Git and GitHub
PDF
CHEP 2018: A Python upgrade to the GooFit package for parallel fitting
PDF
Javascript in linux desktop (ICOS ver.)
PDF
SqueakGTK
PDF
Stetl-engine-nlextract-smartem
PDF
Javascript, the GNOME way (JSConf EU 2011)
ODP
How to use WebKitGtk+
PDF
نگاهی به Gtk3
PDF
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
PDF
Introducing GWT Polymer (vaadin)
PPTX
GDG Kuwait - Modern android development
ODP
G T K+ 101
PDF
Learn Git Fundamentals
PPTX
Introduce gobject introspection
PPTX
Git, Docker, Python Package and Module
PDF
Python GTK (Hacking Camp)
PDF
Pkg-config support for Eclipse CDT documentation
Basics of gtk_ilugc
Gtk development-using-glade-3
Intro to Git and GitHub
CHEP 2018: A Python upgrade to the GooFit package for parallel fitting
Javascript in linux desktop (ICOS ver.)
SqueakGTK
Stetl-engine-nlextract-smartem
Javascript, the GNOME way (JSConf EU 2011)
How to use WebKitGtk+
نگاهی به Gtk3
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
Introducing GWT Polymer (vaadin)
GDG Kuwait - Modern android development
G T K+ 101
Learn Git Fundamentals
Introduce gobject introspection
Git, Docker, Python Package and Module
Python GTK (Hacking Camp)
Pkg-config support for Eclipse CDT documentation
Ad

More from Yuren Ju (8)

PDF
捷克之旅
PDF
Ksdg customize-your-firefoxos
PDF
GNOME3 延伸套件教學
PDF
step by step to write a gnome-shell extension
PDF
Python-GTK
ODP
Ibus pinyin
ODP
Ibus pinyin
ODP
Javascript in Linux Desktop
捷克之旅
Ksdg customize-your-firefoxos
GNOME3 延伸套件教學
step by step to write a gnome-shell extension
Python-GTK
Ibus pinyin
Ibus pinyin
Javascript in Linux Desktop

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Spectroscopy.pptx food analysis technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
Teaching material agriculture food technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Big Data Technologies - Introduction.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Machine learning based COVID-19 study performance prediction
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Diabetes mellitus diagnosis method based random forest with bat algorithm
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectroscopy.pptx food analysis technology
sap open course for s4hana steps from ECC to s4
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Teaching material agriculture food technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Big Data Technologies - Introduction.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Chapter 3 Spatial Domain Image Processing.pdf
Unlocking AI with Model Context Protocol (MCP)
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Understanding_Digital_Forensics_Presentation.pptx
Machine learning based COVID-19 study performance prediction

Python and GObject Introspection