PySide
Python Bindings for the Qt Framework
Marcelo Lira - setanta
March, 10th / Manaus - AM
Prologue
Who Am I?



 • Paid Open Source developer (lucky me!)
 • Computer Engineering Undergrad
 • I like Python but code mostly in C++
   (it’s the "binding developer paradox")
 • PySide / PyMaemo team member at INdT
Who We Are?



  • INdT - Instituto Nokia de Tecnologia
  • openBossa - INdT’s open source stream
  • Known projects: Canola, Carman, PyMaemo
  • Friends of Qt Development Frameworks / KDE
Qt Labs Americas




  • openBossa initiative
  • Development of Qt and KDE communities on the
   Americas

           http://qtlabs.openbossa.org
Python




  "Python is the best language ever invented!" -- me

               import antigravity
Qt Frameworks




      Cross-platform application development framework.

A little while after Nokia’s acquisition of Trolltech Qt started being
                  distributed under the LGPL license.
Today’s Topics



  • PySide
  • Binding Generation
  • Current Status
  • Future
PySide == Python + Qt




 PySide is how we call the Python bindings of the Qt
 Framework produced by INdT/openBossa/Qt Labs
   Americas and released under the LGPL license.
PySide Motivation

Python bindings for Qt under the LGPL license, aligned
            with the new licensing of Qt.



                       Make the Qt-Python bindings fit
                       hand-in-glove on the Maemo platform
                       and devices.



                Because we are the INdT.
PySide Overview




  • PySide: the thing that you import
  • libpyside: takes care of Qt signals/slots
  • libshiboken: helps interfacing Python with C++
Binding Assembly Line




  • Qt Headers: the basic information about Qt libraries comes
    from here.
  • Type System files: here the binding developer modifies the
    collected information to fit the Python language.
  • Handwritten code: code to handle the C++ idiosyncrasies
    that could appear.
And Why Not...?


  • Cython
  • ctypes
  • Swig
  • SIP
  • SMOKE
  • Boost.Python
  • My favorite technology...
Binding Generation
PySide Goals


Besides delivering LGPL Python bindings for Qt, our
other important goal was to deliver the complete
binding factory.
                    fishes + fishing rod
                             or
                PySide + Binding Generator

And we care about your fishing skills too, so we try to
document every part of the system.
Binding C++ libraries

Things one must take care in the binding business:
  • C++ object to Python wrapper association
  • Inheritance
  • Multiple inheritance and casting pointers
  • Implicit type conversions
  • Methods with multiple signatures
  • Protected methods
  • Function arguments that return values
  • Virtual method overrides
  • Object ownership
Shiboken


  • Shiboken is the binding generator used to create
    the PySide bindings.
  • It can generate bindings not only for Qt, but for
    any C++ library.
  • The word means nothing at all. I was trying to
    remember some name and instead of returning an
    empty string my brain made that up.
Shiboken


          Ok, if you really need a meaning...



 • Shi: Death
 • Bo: Something, someone or somewhere
 • Ken: Sword


                (Disclaimer: I don’t know Japanese.)
Binding Generator Pedigree
Boost.Python

The code created by the first Python binding generator used
Boost.Python as sugar coating over the C Python API.
In the beginning it was good because:
   • Quick start
   • Runtime speed
Nevertheless, there was a bad part that showed up later:
   • The size problem
     templates over templates over templates == huge   binaries
   • Lack of flexibility
     indirect access to the C Python API became a
     problem when flexibility was needed.
Binding Assembly Line (Again)




  • API Extractor: collects information from library headers, merges it with
    the modifications and handwritten code defined in the type system
    description.
  • Generator Runner: dynamic loader of generator front-ends.
  • Shiboken: generator front-end that outputs CPython source code.
libshiboken


  Bindings generated with Shiboken will also need
      libshiboken (which is LGPL, by the way).


                        libshiboken helps with:
                           • Association of C++ objects
                               with Python wrappers
                           •   Multiple inheritance
                           •   Implicit type conversions
                           •   Virtual method overrides
                           •   Object ownership
The Type System Description

<typesystem package="sample">
  <primitive-type name="int"/>
  <primitive-type name="Complex" target-lang-api-name="PyComplex">
    <conversion-rule file="complex_conversions.h"/>
    <include file-name="complex.h" location="global"/>
  </primitive-type>

 <namespace-type name="SampleNamespace"/>

 <value-type name="Number" />

  <value-type name="SimpleFile">
    <modify-function signature="open()">
      <modify-argument index="return">
        <remove-argument/>
      </modify-argument>
      <inject-code class="target" position="end" file="simplefile_glue.cpp"/>
    </modify-function>
  </value-type>
</typesystem>
Current Status
Getting Rid of Boost.Python




            Die Boost.Python!
                  Die!
Working Qt Modules


  • QtCore
  • QtGui
   (almost done)

  • QtNetwork and QtSvg
   (community effort! Go cgoncalves!)

  • QtWebkit
  • QtTest
And Now What?



  • Bug Fixing
    A couple of important generator bugs must be
    fixed.
  • Release
    We intend to release the Shiboken generated
    PySide in a month from now.
Future
Better Generation Process



Help others to help themselves.
  • A tool to quick start binding development.
  • A visual binding creation/editing tool.
    (Perhaps a QtCreator plugin.)
The Other Side


Our focus is on Maemo but there are other worlds we
care about.
  • Linux Distros: were taken care by the community
    (Cheers to odyx! And to chaz6 for the build patches.)

  • MacOS X: it needs a little love. Anyone with a good
    heart and a white laptop?
  • Microsoft Windows: some work is already done,
    but still needs love. Lovers?
Pythonization


         One of PySide requisites was to be
           API compatible with PyQt4.

  But we want to make PySide’s API more Pythonic.

Great, but... what makes something Pythonic?

                    What is good?
                     What is right?
                      What is real?
PSEPs



    PySide Enhancement Proposals
  • Inspired by Python’s PEPs.
  • Discussed with the community.
Questions?
Directions


                  www.pyside.org

      http://lists.openbossa.org/listinfo/pyside

                #pyside at Freenode

           http://qt.gitorious.org/pyside

               Marcelo Lira (setanta)
            marcelo.lira@openbossa.org
Thanks
  :)

PySide

  • 1.
    PySide Python Bindings forthe Qt Framework Marcelo Lira - setanta March, 10th / Manaus - AM
  • 2.
  • 3.
    Who Am I? • Paid Open Source developer (lucky me!) • Computer Engineering Undergrad • I like Python but code mostly in C++ (it’s the "binding developer paradox") • PySide / PyMaemo team member at INdT
  • 4.
    Who We Are? • INdT - Instituto Nokia de Tecnologia • openBossa - INdT’s open source stream • Known projects: Canola, Carman, PyMaemo • Friends of Qt Development Frameworks / KDE
  • 5.
    Qt Labs Americas • openBossa initiative • Development of Qt and KDE communities on the Americas http://qtlabs.openbossa.org
  • 6.
    Python "Pythonis the best language ever invented!" -- me import antigravity
  • 7.
    Qt Frameworks Cross-platform application development framework. A little while after Nokia’s acquisition of Trolltech Qt started being distributed under the LGPL license.
  • 8.
    Today’s Topics • PySide • Binding Generation • Current Status • Future
  • 10.
    PySide == Python+ Qt PySide is how we call the Python bindings of the Qt Framework produced by INdT/openBossa/Qt Labs Americas and released under the LGPL license.
  • 11.
    PySide Motivation Python bindingsfor Qt under the LGPL license, aligned with the new licensing of Qt. Make the Qt-Python bindings fit hand-in-glove on the Maemo platform and devices. Because we are the INdT.
  • 12.
    PySide Overview • PySide: the thing that you import • libpyside: takes care of Qt signals/slots • libshiboken: helps interfacing Python with C++
  • 13.
    Binding Assembly Line • Qt Headers: the basic information about Qt libraries comes from here. • Type System files: here the binding developer modifies the collected information to fit the Python language. • Handwritten code: code to handle the C++ idiosyncrasies that could appear.
  • 14.
    And Why Not...? • Cython • ctypes • Swig • SIP • SMOKE • Boost.Python • My favorite technology...
  • 15.
  • 16.
    PySide Goals Besides deliveringLGPL Python bindings for Qt, our other important goal was to deliver the complete binding factory. fishes + fishing rod or PySide + Binding Generator And we care about your fishing skills too, so we try to document every part of the system.
  • 17.
    Binding C++ libraries Thingsone must take care in the binding business: • C++ object to Python wrapper association • Inheritance • Multiple inheritance and casting pointers • Implicit type conversions • Methods with multiple signatures • Protected methods • Function arguments that return values • Virtual method overrides • Object ownership
  • 18.
    Shiboken •Shiboken is the binding generator used to create the PySide bindings. • It can generate bindings not only for Qt, but for any C++ library. • The word means nothing at all. I was trying to remember some name and instead of returning an empty string my brain made that up.
  • 19.
    Shiboken Ok, if you really need a meaning... • Shi: Death • Bo: Something, someone or somewhere • Ken: Sword (Disclaimer: I don’t know Japanese.)
  • 20.
  • 21.
    Boost.Python The code createdby the first Python binding generator used Boost.Python as sugar coating over the C Python API. In the beginning it was good because: • Quick start • Runtime speed Nevertheless, there was a bad part that showed up later: • The size problem templates over templates over templates == huge binaries • Lack of flexibility indirect access to the C Python API became a problem when flexibility was needed.
  • 22.
    Binding Assembly Line(Again) • API Extractor: collects information from library headers, merges it with the modifications and handwritten code defined in the type system description. • Generator Runner: dynamic loader of generator front-ends. • Shiboken: generator front-end that outputs CPython source code.
  • 23.
    libshiboken Bindingsgenerated with Shiboken will also need libshiboken (which is LGPL, by the way). libshiboken helps with: • Association of C++ objects with Python wrappers • Multiple inheritance • Implicit type conversions • Virtual method overrides • Object ownership
  • 24.
    The Type SystemDescription <typesystem package="sample"> <primitive-type name="int"/> <primitive-type name="Complex" target-lang-api-name="PyComplex"> <conversion-rule file="complex_conversions.h"/> <include file-name="complex.h" location="global"/> </primitive-type> <namespace-type name="SampleNamespace"/> <value-type name="Number" /> <value-type name="SimpleFile"> <modify-function signature="open()"> <modify-argument index="return"> <remove-argument/> </modify-argument> <inject-code class="target" position="end" file="simplefile_glue.cpp"/> </modify-function> </value-type> </typesystem>
  • 25.
  • 26.
    Getting Rid ofBoost.Python Die Boost.Python! Die!
  • 27.
    Working Qt Modules • QtCore • QtGui (almost done) • QtNetwork and QtSvg (community effort! Go cgoncalves!) • QtWebkit • QtTest
  • 28.
    And Now What? • Bug Fixing A couple of important generator bugs must be fixed. • Release We intend to release the Shiboken generated PySide in a month from now.
  • 29.
  • 30.
    Better Generation Process Helpothers to help themselves. • A tool to quick start binding development. • A visual binding creation/editing tool. (Perhaps a QtCreator plugin.)
  • 31.
    The Other Side Ourfocus is on Maemo but there are other worlds we care about. • Linux Distros: were taken care by the community (Cheers to odyx! And to chaz6 for the build patches.) • MacOS X: it needs a little love. Anyone with a good heart and a white laptop? • Microsoft Windows: some work is already done, but still needs love. Lovers?
  • 32.
    Pythonization One of PySide requisites was to be API compatible with PyQt4. But we want to make PySide’s API more Pythonic. Great, but... what makes something Pythonic? What is good? What is right? What is real?
  • 33.
    PSEPs PySide Enhancement Proposals • Inspired by Python’s PEPs. • Discussed with the community.
  • 34.
  • 35.
    Directions www.pyside.org http://lists.openbossa.org/listinfo/pyside #pyside at Freenode http://qt.gitorious.org/pyside Marcelo Lira (setanta) marcelo.lira@openbossa.org
  • 36.