Launch Chaco and Mayavi on PySide
Well, the long-awaited release of PySide has appeared. Some Habravites will start using it for the first time, some have already dealt with it.
In my work I have to use the Mayavi cross-platform visualizer and the Chaco chart builder (who 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 in PyQt4 and everything was fine with me, except for one thing. The problem was the license. PySide is available under 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 wandered around the sources a bit, I found out that it is enough to specify the environment variable 'QT_API' in the value 'pyside':
Despite this, the application refused to work. Useful to edit the source. It seemed that there weren’t so many changes, but finding problems from scratch was rather disgusting and long. Hope further instructions help someone.
First of all, you need to collect packages from the gita. We install PySide, git, subversion, setuptools, swig, numpy, scipy, vtk, wxpython. For Windows, you will also need to install mingw (vtk and wxpython for Win, I advise you to take www.lfd.uci.edu/~gohlke/pythonlibs from here to save time ).
After all these manipulations, you can run the example.
For Chaco: pastebin.ubuntu.com/575888
For Mayavi: pastebin.ubuntu.com/575889
Screenshots of working widgets: PS If anyone is interested, I can write articles on the possibilities and pitfalls of Chaco and Mayavi.
In my work I have to use the Mayavi cross-platform visualizer and the Chaco chart builder (who 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 in PyQt4 and everything was fine with me, except for one thing. The problem was the license. PySide is available under 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 wandered around the sources a bit, I found out that it is enough to specify the environment variable 'QT_API' in the value 'pyside':
import os
os.environ ['QT_API'] = 'pyside'
Despite this, the application refused to work. Useful to edit the source. It seemed that there weren’t so many changes, but finding problems from scratch was rather disgusting and long. Hope further instructions help someone.
First of all, you need to collect packages from the gita. We install PySide, git, subversion, setuptools, swig, numpy, scipy, vtk, wxpython. For Windows, you will also need to install mingw (vtk and wxpython for Win, I advise you to take www.lfd.uci.edu/~gohlke/pythonlibs from here to save time ).
- Download and put in the ETS folder, 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 - We start assembly:
python ets.py develop
- If the assembly failed, then install the necessary packages and restart the script
- After a successful build, go to the Mayavi / enthought / tvtk / pyface / ui / qt4 / directory.
Open all the files one by one and change the PyQt4 import to PySide.
If desired, you can use a 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 the PyQt version check:
#if QtCore.QT_VERSION <0x040200:
# raise RuntimeError, "Need Qt v4.2 or higher, but got v% s"% QtCore.QT_VERSION_STR
#if QtCore.PYQT_VERSION <0x040100:
# raise RuntimeError, "Need PyQt4 higher, but got v% s "% QtCore.PYQT_VERSION_STR - edit the file TraitsBackendQt / enthought / traits / ui / qt4 / ui_panel.py in lines 920-926 (function __add_widget (...)):
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 Mayavi \ enthought \ tvtk \ pyface \ ui \ qt4 \ QVTKRenderWindowInteractor.py file
Add to the 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 the replacement of the text editor, change str (int (self.winId ())) to str (int (pythonapi.PyCObject_AsVoidPtr (self.winId ())))
After all these manipulations, you can run the example.
For Chaco: pastebin.ubuntu.com/575888
For Mayavi: pastebin.ubuntu.com/575889
Screenshots of working widgets: PS If anyone is interested, I can write articles on the possibilities and pitfalls of Chaco and Mayavi.