Extra python modules
The python interpreter inside FreeCAD can easily be extended by adding new modules to your system's python installation. Those modules will be automatically detected and used by FreeCAD.
All pyhton modules can be used from within FreeCAD, but several of them, listed below, have a special importance because they allow python programs complete access to core functionality of FreeCAD. Examples of use of those modules can also be found on the Code snippets page.
PyQt4
homepage: http://www.riverbankcomputing.co.uk/pyqt
PyQt (version 4) is a python bindings library which allow programs to access, create or modify Qt interfaces. Since the FreeCAD interface is built with Qt, installing PyQt4 on your system allow python programs inside FreeCAD to access all the interface, modify its parts, create new widgets or gather info from interface parts.
PyQt is released under a multiple licensing system, same system as used by Qt. To resume, there is a commercial version and a free GPL version. If you want to use it to make commercial (closed source) programs, you need to purchase the commercial license, otherwise you can simply install and use freely the GPL version.
Installation
Before installing PyQt4, you obviously need a python environment installed and working.
Linux
The simplest way to install PyQt4 is through your distribution's package manager. On Debian/Ubuntu systems, the package name is generally python-qt4, while on RPM-based systems it is named pyqt4. The necessary dependencies (Qt and SIP) will be taken care of automatically.
Windows
The program can be downloaded from here. You'll need to install the Qt and SIP libraries before installing pyqt4 (to be documented).
Usage
Once it is installed, you can check that everything is working by typing in FreeCAD python console:
import PyQt4
To access the FreeCAD interface, type:
from PyQt4 import QtCore,QtGui
app = QtGui.qApp
FreeCADWindow = app.activeWindow()
Now you can start to explore the interface with the dir() command. You can add new elements, like a custom widget, with commands like:
FreeCADWindow.addDockWidget(QtCore.Qt.RghtDockWidgetArea,my_custom_widget)
More pyQt4 tutorials (including how to build interfaces with Qt Designer to use with FreeCAD):
http://www.rkblog.rk.edu.pl/w/p/introduction-pyqt4/ - a simple introduction
http://www.zetcode.com/tutorials/pyqt4/ - very complete in-depth tutorial