OSDN Git Service

fix for python2.7
[meshio/pymeshio.git] / examples / togl.py
1 #!/usr/bin/env python\r
2 # coding: utf-8\r
3 \r
4 import OpenGL.Tk\r
5 \r
6 \r
7 class Widget(OpenGL.Tk.RawOpengl):\r
8     def __init__(self, master, engine, *args, **kw):\r
9         #super(Widget, self).__init__(master, *args, **kw)\r
10         OpenGL.Tk.RawOpengl.__init__(self, master, *args, **kw)\r
11         self.engine=engine\r
12         self.bind('<Map>', self.onDraw)\r
13         self.bind('<Expose>', self.onDraw)\r
14         self.bind('<Configure>', self.onResize)\r
15         self.bind('<ButtonPress-1>', lambda e: self.engine.onLeftDown(e.x, e.y) and self.onDraw())\r
16         self.bind('<ButtonRelease-1>', lambda e: self.engine.onLeftUp(e.x, e.y) and self.onDraw())\r
17         self.bind('<B1-Motion>', lambda e: self.engine.onMotion(e.x, e.y) and self.onDraw())\r
18         self.bind('<ButtonPress-2>', lambda e: self.engine.onMiddleDown(e.x, e.y) and self.onDraw())\r
19         self.bind('<ButtonRelease-2>', lambda e: self.engine.onMiddleUp(e.x, e.y) and self.onDraw())\r
20         self.bind('<B2-Motion>', lambda e: self.engine.onMotion(e.x, e.y) and self.onDraw())\r
21         self.bind('<ButtonPress-3>', lambda e: self.engine.onRightDown(e.x, e.y) and self.onDraw())\r
22         self.bind('<ButtonRelease-3>', lambda e: self.engine.onRightUp(e.x, e.y) and self.onDraw())\r
23         self.bind('<B3-Motion>', lambda e: self.engine.onMotion(e.x, e.y) and self.onDraw())\r
24 \r
25     def onDraw(self, *dummy):\r
26         self.tk.call(self._w, 'makecurrent')\r
27         self.update_idletasks()\r
28         self.engine.draw()\r
29         self.tk.call(self._w, 'swapbuffers')\r
30 \r
31     def onResize(self, event):\r
32         self.engine.onResize(event.width, event.height)\r
33         self.onDraw()\r
34 \r