Statistics
| Revision:

root / PyOpenGL-Demo / tom / demo.py @ 1

History | View | Annotate | Download (2.6 kB)

1 1 equemene
#!/usr/bin/python
2 1 equemene
3 1 equemene
# This is statement is required by the build system to query build info
4 1 equemene
if __name__ == '__build__':
5 1 equemene
        raise Exception
6 1 equemene
7 1 equemene
8 1 equemene
import string
9 1 equemene
__version__ = string.split('$Revision: 1.1.1.1 $')[1]
10 1 equemene
__date__ = string.join(string.split('$Date: 2007/02/15 19:25:38 $')[1:3], ' ')
11 1 equemene
__author__ = 'Tarn Weisner Burton <twburton@users.sourceforge.net>'
12 1 equemene
13 1 equemene
from OpenGL.GL import *
14 1 equemene
from OpenGL.Tk import *
15 1 equemene
16 1 equemene
def new_file(self):
17 1 equemene
    print "opening new file"
18 1 equemene
19 1 equemene
def open_file(self):
20 1 equemene
    print "opening OLD file"
21 1 equemene
22 1 equemene
def print_something(self):
23 1 equemene
    print "picked a menu item"
24 1 equemene
25 1 equemene
26 1 equemene
class Demo:
27 1 equemene
        def __init__(self, root):
28 1 equemene
                self.mBar = Frame(root, relief=RAISED, borderwidth=2)
29 1 equemene
                self.mBar.pack(fill=X)
30 1 equemene
                demo = self.makeDemoMenu()
31 1 equemene
                self.mBar.tk_menuBar(demo)
32 1 equemene
                self.ogl = Opengl(width = 300, height = 300, double = 1, depth = 1)
33 1 equemene
                self.ogl.redraw = self.draw_lines
34 1 equemene
                self.ogl.set_centerpoint(30, 0, 0)
35 1 equemene
                self.ogl.set_eyepoint(140)
36 1 equemene
                self.ogl.pack(side = 'top', expand = 1, fill = 'both')
37 1 equemene
                self.ogl.grob = -1
38 1 equemene
39 1 equemene
        def makeDemoMenu(self):
40 1 equemene
                demo = Menubutton(self.mBar, text='Demos', underline=0)
41 1 equemene
                demo.pack(side=LEFT, padx="2m")
42 1 equemene
                demo.menu = Menu(demo)
43 1 equemene
44 1 equemene
                demo.menu.add_command(label='Blue', underline=0, command=self.set_blue)
45 1 equemene
                demo.menu.add_command(label='Lines', underline=0,command=self.set_lines)
46 1 equemene
                demo.menu.add_command(label='Text', underline=0,command=self.set_text)
47 1 equemene
48 1 equemene
                demo.menu.add('separator')
49 1 equemene
                demo.menu.add_command(label='Quit', underline=0, background='red',
50 1 equemene
                                                                     activebackground='green',
51 1 equemene
                                                                         command=demo.quit)
52 1 equemene
53 1 equemene
                demo['menu'] = demo.menu
54 1 equemene
                return demo
55 1 equemene
56 1 equemene
        def draw_lines(self, ogl):
57 1 equemene
                glClearColor(0, 0, 0, 0)
58 1 equemene
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
59 1 equemene
                glDisable(GL_LIGHTING)
60 1 equemene
                glBegin(GL_LINES)
61 1 equemene
                glColor3f(1,1,0)
62 1 equemene
                glVertex2f(0,-30)
63 1 equemene
                glColor3f(1,0,1)
64 1 equemene
                glVertex2f(60,30)
65 1 equemene
                glColor3f(1,0,0)
66 1 equemene
                glVertex2f(60,-30)
67 1 equemene
                glColor3f(0,0,1)
68 1 equemene
                glVertex2f(0,30)
69 1 equemene
                glEnd()
70 1 equemene
                glEnable(GL_LIGHTING)
71 1 equemene
72 1 equemene
        def set_lines(self):
73 1 equemene
                self.ogl.redraw = self.draw_lines
74 1 equemene
                self.ogl.tkRedraw()
75 1 equemene
76 1 equemene
        def draw_blue(self, ogl):
77 1 equemene
                glClearColor(0, 0, 1, 0)
78 1 equemene
                glClear(GL_COLOR_BUFFER_BIT)
79 1 equemene
80 1 equemene
        def set_blue(self):
81 1 equemene
                self.ogl.redraw = self.draw_blue
82 1 equemene
                self.ogl.tkRedraw()
83 1 equemene
84 1 equemene
        def draw_text(self, ogl):
85 1 equemene
                glClearColor(0, 0, 0.5, 0)
86 1 equemene
                glClear(GL_COLOR_BUFFER_BIT)
87 1 equemene
                if ogl.grob == -1:
88 1 equemene
                        from logo import define_logo
89 1 equemene
                        ogl.grob = glGenLists(1);
90 1 equemene
                        glNewList(ogl.grob, GL_COMPILE_AND_EXECUTE);
91 1 equemene
                        glMaterialfv(GL_FRONT, GL_DIFFUSE, [1, 0, 0, 0])
92 1 equemene
                        define_logo()
93 1 equemene
                        glEndList()
94 1 equemene
                else:
95 1 equemene
                        glCallList(ogl.grob)
96 1 equemene
97 1 equemene
        def set_text(self):
98 1 equemene
                self.ogl.redraw = self.draw_text
99 1 equemene
                self.ogl.tkRedraw()
100 1 equemene
101 1 equemene
root = Tk()
102 1 equemene
d = Demo(root)
103 1 equemene
root.mainloop()