Here’s early code on getting Panda integrated with PyQt as a widget. Its really slow since converting the frame buffer into images PyQt can use is really slow, theres probably a better way though.
To run the demo you’ll need PyQt4
from pandac.PandaModules import loadPrcFileData
#loadPrcFileData("", "window-type offscreen") # Set Panda to draw its main window in an offscreen buffer
# PyQt imports
from PyQt4 import QtGui, QtCore
import sys
# Panda imports
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import GraphicsOutput, Texture, StringStream, PNMImage
from direct.interval.LerpInterval import LerpHprInterval
from pandac.PandaModules import Point3
# Set up Panda environment
import direct.directbase.DirectStart
class QtPandaWidget(QtGui.QWidget):
"""
This takes a texture from Panda and draws it as a QWidget
"""
def __init__(self, texture, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(50, 50, 800, 600)
self.setWindowTitle("PandaQt")
self.pandaTexture = texture
# Setup a timer in Qt that runs taskMgr.step() to simulate Panda's own main loop
pandaTimer = QtCore.QTimer(self)
self.connect(pandaTimer, QtCore.SIGNAL("timeout()"), taskMgr.step)
pandaTimer.start(0)
# Setup another timer that redraws this widget in a specific FPS
redrawTimer = QtCore.QTimer(self)
self.connect(redrawTimer, QtCore.SIGNAL("timeout()"), self, QtCore.SLOT("update()"))
redrawTimer.start(1000/60)
# Setup a QLabel to paint the pixmap on
self.paintSurface = QtGui.QLabel(self)
self.paintSurface.setGeometry(0, 0, 800, 600)
self.paintSurface.show()
self.paintPixmap = QtGui.QPixmap(800, 600)
# Use the paint event to pull the contents of the panda texture to the widget
def paintEvent(self, event):
screenData = StringStream() # Used to pass the data as a string
screenImage = PNMImage() # Converts the texture data into a format usable with Qt
if self.pandaTexture.hasRamImage():
print "Should draw yes?"
self.pandaTexture.store(screenImage)
screenImage.write(screenData, "test.ppm")
self.paintPixmap.loadFromData(screenData.getData())
self.paintSurface.setPixmap(self.paintPixmap)
class PandaHandler(DirectObject):
def __init__(self):
base.disableMouse()
base.cam.setPos(0, -28, 6)
self.testModel = loader.loadModel('panda')
self.testModel.reparentTo(render)
print self.testModel.getPos()
self.rotateInterval = LerpHprInterval(self.testModel, 3, Point3(360, 0, 0))
self.rotateInterval.loop()
self.screenTexture = Texture()
self.screenTexture.setMinfilter(Texture.FTLinear)
base.win.addRenderTexture(self.screenTexture, GraphicsOutput.RTMCopyRam)
if __name__ == "__main__":
#lol teh hobo
panHandler = PandaHandler()
app = QtGui.QApplication(sys.argv)
pandaWidget = QtPandaWidget(panHandler.screenTexture)
pandaWidget.show()
sys.exit(app.exec_())