Well, there was the long-awaited release of PySide. Some habravchane begin to use it for the first time, some have already dealt with it.
In my work, we have to use Mayavi cross-platform visualizer and Chaco chart builder (
if you are interested, read
code.enthought.com/chaco and
code.enthought.com/projects/mayavi ). My task was to embed their frames in my HPGL-GUI application. Initially, I wrote everything on PyQt4 and everything suited me, except for one thing. The problem was the license. PySide is released under the LGPL v2.1, which is just right for commercial needs.
PySide came to the rescue, which has already begun to be actively used as a backend to Enthought products. It was then that the first pitfalls awaited me.
')
Lack of documentation on exactly how to use PySide for embedding.
Having a little browsing through the sources, I found out that it is enough to specify the environment variable 'QT_API' to the value 'pyside':
import os
os . environ [ 'QT_API' ] = 'pyside'
Despite this, the application refused to work. It is useful to edit the source. It seemed that there were not so many changes, but finding problems from scratch is rather disgusting and time consuming. I hope further instructions will help someone.
The first thing you need to collect packages from the gita. We set ourselves PySide, git, subversion, setuptools, swig, numpy, scipy, vtk, wxpython. For Windows, you also need to install mingw (vtk and wxpython for Win, I advise you to take from here to save time
www.lfd.uci.edu/~gohlke/pythonlibs ).
- Download and put in the ETS daddy, go to it and clone the repositories:
git clone git: // github.com / enthought / traits.git Traits
git clone git: // github.com / enthought / traitsbackendqt.git TraitsBackendQt
git clone git: // github.com / enthought / traitsbackendwx.git TraitsBackendWX
git clone git: // github.com / enthought / traitsgui.git TraitsGUI
git clone git: // github.com / enthought / enable.git Enable
git clone git: // github.com / enthought / chaco.git Chaco
git clone git: // github.com / enthought / mayavi.git Mayavi
git clone git: // github.com / enthought / enthoughtbase.git EnthoughtBase
git clone git: // github.com / enthought / envisagecore.git EnvisageCore
git clone git: // github.com / enthought / envisageplugins.git EnvisagePlugins
git clone git: // github.com / enthought / etsdevtools.git ETSDevTools
git clone git: // github.com / enthought / blockcanvas.git BlockCanvas
git clone git: // github.com / enthought / graphcanvas.git GraphCanvas
git clone git: // github.com / enthought / codetools.git CodeTools
git clone git: // github.com / enthought / apptools.git AppTools
git clone git: // github.com / enthought / scimath.git SciMath
- Run the build:
python ets. py develop
- If the build fails, then install the necessary packages and restart the script.
- After successful assembly, go to the directory Mayavi / enthought / tvtk / pyface / ui / qt4 /
Open all the files one by one and change the import of PyQt4 to PySide.
If desired, you can use the design of the form:
import os
qt_api = os . environ . get ( 'QT_API' , 'pyqt' )
if qt_api == 'pyqt' :
from PyQt4 import QtGui, QtCore
else :
from PySide import QtGui, QtCore
- In the init.py file from the same directory, you need to comment out lines 26-30 with checking the version of PyQt:
#if QtCore.QT_VERSION <0x040200:
# raise RuntimeError, "Need Qt v4.2 or higher, but not got v% s"% QtCore.QT_VERSION_STR
#if QtCore.PYQT_VERSION <0x040100:
# raise RuntimeError, "Need PyQt v4.1 or higher, but not got% s"% QtCore.PYQT_VERSION_STR
- edit the TraitsBackendQt / enthought / traits / ui / qt4 / ui_panel.py file in lines 920-926 (__add_widget (...) function):
if row < 0 :
if isinstance ( w, QtGui. QWidget ) :
layout. addWidget ( w )
elif isinstance ( w, QtGui. QLayout ) :
layout. addLayout ( w )
else :
layout. addWidget ( w )
- For those who want to work under Win, you need to fix the file Mayavi \ enthought \ tvtk \ pyface \ ui \ qt4 \ QVTKRenderWindowInteractor.py
Add to imports:
from ctypes import pythonapi, c_void_p, py_object
pythonapi. PyCObject_AsVoidPtr . restype = c_void_p
pythonapi. PyCObject_AsVoidPtr . argtypes = [ py_object ]
and, using a text editor replacement, change str (int (self.winId ())) to str (int (pythonapi.PyCObject_AsVoidPtr (self.winId ())))
After all these manipulations, you can run an example.
For Chaco:
pastebin.ubuntu.com/575888For Mayavi:
pastebin.ubuntu.com/575889Screenshots of working widgets:

PS If someone is interested, I can write articles on the possibilities and pitfalls of Chaco and Mayavi.