--- /dev/null
+#!/bin/env python
+
+# Dependencies:
+# PyQt4
+
+import sys
+
+from OpenGL.GL import *
+
+from PyQt4.Qt import QApplication, QMainWindow, QLabel
+from PyQGLViewer import QGLViewer, Vec
+
+from openalea.lpy import Lsystem
+from openalea.plantgl.all import Discretizer, GLRenderer
+
+# Qt Plant Viewer
+class Viewer(QGLViewer):
+ def __init__(self, lfile):
+ QGLViewer.__init__(self)
+
+ center = Vec(0.16104, 0.00831, 2.53128)
+ position = Vec(4.74832, 4.66647, 8.79487)
+
+ self.discretizer = Discretizer()
+ self.renderer = GLRenderer(self.discretizer)
+ self.lsystem = Lsystem(lfile)
+ self.scene = self.lsystem.sceneInterpretation(self.lsystem.iterate())
+
+ camera = self.camera()
+ camera.setRevolveAroundPoint(center)
+ camera.setPosition(position)
+ camera.setUpVector(Vec(0,0,1))
+ camera.lookAt(center)
+ camera.setSceneRadius(7)
+
+ def draw(self):
+ light_pos = list(self.camera().position())+[1.0]
+ light_dir = list(self.camera().viewDirection())+[1.0]
+
+ glEnable(GL_LIGHTING)
+ glEnable(GL_LIGHT0)
+
+ glLightfv(GL_LIGHT0, GL_POSITION, light_pos)
+ glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_dir)
+ glLightfv(GL_LIGHT0, GL_AMBIENT, (0.6,0.6,0.6,1.0))
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, (1.0,1.0,1.0,1.0))
+ glLightfv(GL_LIGHT0, GL_SPECULAR, (1.0,1.0,1.0,1.0))
+
+ if self.renderer.beginSceneList():
+ glEnable(GL_RESCALE_NORMAL)
+ self.scene.apply(self.renderer)
+ self.renderer.endSceneList()
+
+# Test Qt
+class TestQt:
+ def __init__(self, args):
+ self.args = args;
+
+ def run(self):
+ app = QApplication(self.args)
+ win = QMainWindow()
+ btn = QLabel("Hello, World");
+
+ win.setCentralWidget(btn)
+ win.resize(800,600)
+ win.show()
+
+ app.exec_()
+
+# Test PlantGL
+class TestPlantGL:
+ def __init__(self, args):
+ self.args = args;
+
+ def run(self):
+ app = QApplication(self.args)
+ win = QMainWindow()
+ view = Viewer("plant.lpy");
+
+ win.setCentralWidget(view)
+ win.resize(800,600)
+ win.show()
+
+ app.exec_()
+
+# Main
+for test in sys.argv[1:]:
+
+ if test == 'qt':
+ qt = TestQt(sys.argv)
+ qt.run()
+
+ if test == 'plantgl' or test == 'pgl':
+ pgl = TestPlantGL(sys.argv)
+ pgl.run()