Making PyQt4 widgets with SIP
SIP is a tool for making a Python API for C and C++ libraries, and it is used to make PyQt. Both packages we will find in many Linux distributions. SIP has a documentation - for Qt3, or "look at python qscintilla bindings" :) But with the help of Phil and Google I've came up with a working solution for making PyQt4 widgets from Qt4 widgets.
To make a PyQt4 API we need the widget header file - like QLabel.h, and the libraries it "depends" on. When we have that file we will have to create few extra:
- afile.sip - file named (recommended) like the header file. Contains SIP-readable description of the wrapped class.
- config.py - config file, that will make Makefile and other goodies for compiling
- config.py.in - extra config file (usualy blank?)
qmake make make install
- %Module QtermWidget 0 - name of the module
%Import QtCore/QtCoremod.sip %Import QtGui/QtGuimod.sipthis adds PyQt4 SIP files needed to describe a Qt4 widget for SIP
%TypeHeaderCode #includeadding the header file, where wrapped class can be found
Next stage is the config file. config.py looks like this: It's mostly a generic file, and for other projects like this only the name "qtermwidget" should changes. Note that "qtermwidgetconfig.py" is a config that will be generated (and it's not config.py). Create also a blank config.py.in.
If we have all the configuration done we can finish our work by compiling the API. First parse sip file with:
- Qt_4_4_1: is the ID of PyQt4 install (can be found in /usr/lib/python*/site-packages/PyQt4/pyqtconfig.py)
- /usr/share/sip/: path to SIP folder, with installed sip files (for example PyQt4 sip files that we need)
python config.py make make install