For all of you who would like to have an OpenGL widget for Python. Here you have it! It’s very basic. The minimal thing is to overload the paintGL() method. Here is a screenshot:
Good for prototyping or writing small test programs.
A collection of coding snippets, tips, hints and random thoughts.
For all of you who would like to have an OpenGL widget for Python. Here you have it! It’s very basic. The minimal thing is to overload the paintGL() method. Here is a screenshot:
Good for prototyping or writing small test programs.
I have written a neat little Spherical Harmonics explorer. Right now, the projection function has some weird bug still, but the basis functions, and arbitrary combinations of them can be viewed nicely. The tool is written in Python, using PyQt4 and PyOpenGL. Python is excellent for prototyping such a tool. It might not be as fast as C++, but the rendering speed using PyOpenGL is more than enough and very smooth. I might put the small 3D viewer widget online later, because it might be useful for many people. Here’s some eyecandy:
One more stupid bug in Qt found. When using the Designer, you can’t drag and drop QActions, if you are using the Cocoa version of Qt. The bug is described here, a fix will be available in Qt 4.6.3.
Here is a minimal example for PyQt4, to set up a main window and connect a simple action to some slot. The documentation on doing this is sparse to say the least. So I hope this is helpful for anyone trying something similar. I assume that you have created a ui_MainWindow.ui file with Qt Designer, which contains a form derived from QMainWindow.
import sys
from PyQt4 import QtCore, QtGui, uic
class MyMainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.ui = uic.loadUi("ui_MainWindow.ui", self)
self.connect(self.ui.actionOpen, QtCore.SIGNAL('triggered()'), self, QtCore.SLOT('open()'))
@QtCore.pyqtSlot()
def open(self):
fileDialog = QtGui.QFileDialog(self, "Open file")
fileDialog.show()
app = QtGui.QApplication(sys.argv)
mainWindow = MyMainWindow()
mainWindow.show()
sys.exit(app.exec_())
I really don’t get happy with Qt 4.6 on OS X 10.6. Nokia rates Qt on that platform as Tier 2. Which means, it is not fully supported. This results in stupid things happening. With Licq, I currently have the problem that the whole program crashes with the following message:
Good news: The Qt port of MacPorts is working again. The port was upgraded to Qt 4.6 and now it compiles again. Now all I need is a 64 bit CUDA package for Snow Leopard, and I’ll be happy.