PySide Binding Generation Tutorial: Module 2 Binding libfoo using Shiboken: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Convert ExpressionEngine links)
No edit summary
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
 


[[Category:LanguageBindings::PySide::Shiboken::PySide Binding Generation Tutorial]]
[[Category:LanguageBindings::PySide::Shiboken::PySide Binding Generation Tutorial]]
[toc align_right="yes" depth="3"]
 


'''English''' [http://qt-devnet.developpez.com/tutoriels/python/pyside/binding-shiboken/#LIV French]
'''English''' [http://qt-devnet.developpez.com/tutoriels/python/pyside/binding-shiboken/#LIV French]


* '''Note:''' this article is a member of the multipart [http://developer.qt.nokia.com/wiki/Category:LanguageBindings::PySide::Shiboken::PySide_Binding_Generation_Tutorial PySide Binding Generation Tutorial]
* '''Note:''' this article is a member of the multipart [https://wiki.qt.io/PySide_Binding_Generation_Tutorial PySide Binding Generation Tutorial]


= Binding libfoo using Shiboken =
= Binding libfoo using Shiboken =
Line 12: Line 12:
In order to create bindings for a library based on Qt, a number of components must be available on the system:
In order to create bindings for a library based on Qt, a number of components must be available on the system:


* Qt library (with headers and '''pkg-config''' <code>.pc</code> files for development – the '''-dev''' packages in a Debian-like distribution).
* Qt library (with headers and '''pkg-config''' '''.pc''' files for development – the '''-dev''' packages in a Debian-like distribution).
* Qt Python bindings made with Shiboken, i.e. PySide.
* Qt Python bindings made with Shiboken, i.e. PySide.
* Type systems for the Qt Python bindings.
* Type systems for the Qt Python bindings.
Line 20: Line 20:


* Type system file describing the way the binding must be done.
* Type system file describing the way the binding must be done.
* <code>global.h</code> including all the '''libfoo''' headers and defining required macros.
* '''global.h''' including all the '''libfoo''' headers and defining required macros.
* A build system to direct the process of generating, compiling and linking the binding.
* A build system to direct the process of generating, compiling and linking the binding.


Line 36: Line 36:
</code>
</code>


The <code>foobinding-makefile</code> directory should contain the <code>global.h</code>, which is a central point to include all the '''libfoo''' headers (ok, it's just one header, but a real life library will certainly have more headers), it could also contain '''#define''' clauses that will influence the parsing of the headers by the generator. Nevermind the <code>pyside_global.h</code> file, it'll be explained later. The <code>typesystem_foo.xml</code> describes how to export the wrapped C++ library to Python as explained in [https://developer.qt.nokia.com/wiki/PySide_Binding_Generation_Tutorial:_Module_3_Creating_Type_System_Description Module 3].
The '''foobinding-makefile''' directory should contain the '''global.h''', which is a central point to include all the '''libfoo''' headers (ok, it's just one header, but a real life library will certainly have more headers), it could also contain '''#define''' clauses that will influence the parsing of the headers by the generator. Nevermind the '''pyside_global.h''' file, it'll be explained later. The '''typesystem_foo.xml''' describes how to export the wrapped C++ library to Python as explained in [[PySide Binding Generation Tutorial: Module 3 Creating Type System Description | Module 3]].


The <code>foo</code> directory is the place where the generated sources will be placed. It starts empty and its name will be the same as the package name found in the type system file:
The '''foo''' directory is the place where the generated sources will be placed. It starts empty and its name will be the same as the package name found in the type system file:


<code>
<code>
Line 44: Line 44:
</code>
</code>


If there is any need for handwritten source code longer than a couple of lines, making it inconvenient to put them in the type system xml file, the sources could be orderly placed in a <code>glue</code> directory. For the '''foo''' bindings no custom code will be needed.
If there is any need for handwritten source code longer than a couple of lines, making it inconvenient to put them in the type system xml file, the sources could be orderly placed in a '''glue''' directory. For the '''foo''' bindings no custom code will be needed.


When writing the type system file (more on this later) there is no need to refer to the other required type system files with absolute paths, the locations where they can be found could be passed to the generator through a command line option (—typesystem-paths=PATH1:PATH2:[…]) or the environment variable '''TYPESYSTEMPATH'''.
When writing the type system file (more on this later) there is no need to refer to the other required type system files with absolute paths, the locations where they can be found could be passed to the generator through a command line option (—typesystem-paths=PATH1:PATH2:[…]) or the environment variable '''TYPESYSTEMPATH'''.

Revision as of 11:36, 13 April 2015


English French

Binding libfoo using Shiboken

In order to create bindings for a library based on Qt, a number of components must be available on the system:

  • Qt library (with headers and pkg-config .pc files for development – the -dev packages in a Debian-like distribution).
  • Qt Python bindings made with Shiboken, i.e. PySide.
  • Type systems for the Qt Python bindings.
  • Headers for the library to be wrapped.

With the items listed above the developer must collect information used by the generator to create the binding source code:

  • Type system file describing the way the binding must be done.
  • global.h including all the libfoo headers and defining required macros.
  • A build system to direct the process of generating, compiling and linking the binding.

libfoo bindings with Makefile

The directory structure and contents for the Makefile binding project could be something like the tree shown below:

foobinding-makefile/
| foo/
| global.h
| Makefile
| pyside_global.h
`— typesystem_foo.xml

The foobinding-makefile directory should contain the global.h, which is a central point to include all the libfoo headers (ok, it's just one header, but a real life library will certainly have more headers), it could also contain #define clauses that will influence the parsing of the headers by the generator. Nevermind the pyside_global.h file, it'll be explained later. The typesystem_foo.xml describes how to export the wrapped C++ library to Python as explained in Module 3.

The foo directory is the place where the generated sources will be placed. It starts empty and its name will be the same as the package name found in the type system file:

<typesystem package="foo">

If there is any need for handwritten source code longer than a couple of lines, making it inconvenient to put them in the type system xml file, the sources could be orderly placed in a glue directory. For the foo bindings no custom code will be needed.

When writing the type system file (more on this later) there is no need to refer to the other required type system files with absolute paths, the locations where they can be found could be passed to the generator through a command line option (—typesystem-paths=PATH1:PATH2:[…]) or the environment variable TYPESYSTEMPATH.

libfoo bindings with CMake

The directory structure for the CMake based libfoo bindings is a bit more elaborate:

foobinding-cmake/
| CMakeLists.txt
| foo/
| | CMakeLists.txt
| | global.h
| | pyside_global.h
| `— typesystem_foo.xml
`— tests/
 `— CMakeLists.txt
 `— math_test.py