summaryrefslogtreecommitdiff
path: root/cad/src/experimental/pyrex-example/putz.pyx
blob: 0f1d5495569a3eb8fcd2bf1356dbed14e72140ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Copyright 2006-2007 Nanorex, Inc.  See LICENSE file for details. 
import math
import qt
import qtgl
import sys
import random

cdef extern from "futz.c":
    # Does OpenGL compel the use of floats, or are doubles OK?
    void line(float x1, float y1, float z1,
              float x2, float y2, float z2,
              float r, float g, float b)
    void sphere(double x, double y, double z,
                double radius,
                double r, double g, double b)
    void glSetup(int windowWidth, int windowHeight)


class GLPane(qtgl.QGLWidget):
    def __init__(self, master=None, name=None, win=None):
        qtgl.QGLWidget.__init__(self, master, name)
        self.win = win
        self.redrawGL = True
        self.setFocusPolicy(qt.QWidget.StrongFocus)
        glSetup(600, 400)
        print "GLPane constructor ran"
        self.update()
    def update(self):
        line(100 * random.random(), 100 * random.random(), 100 * random.random(),
             100 * random.random(), 100 * random.random(), 100 * random.random(),
             random.random(), random.random(), random.random())
        qtgl.QGLWidget.update(self)
    # use self.update to repaint

class MainWindow(qt.QMainWindow):
    def __init__(self):
        qt.QMainWindow.__init__(self)
        self.setEnabled(1)
        self.setOpaqueMoving(0)
        self.glpane = GLPane(self, "glpane", self)
    def show(self):
        self.glpane.show()
        qt.QMainWindow.show(self)

def main():
    qt.QApplication.setColorSpec(qt.QApplication.CustomColor)
    app = qt.QApplication(sys.argv)
    win = MainWindow()
    win.show()
    app.connect(app, qt.SIGNAL("lastWindowClosed()"), app.quit)