forked from amiller/libfreenect-goodies
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpykinectwindow.py
More file actions
80 lines (63 loc) · 2.74 KB
/
pykinectwindow.py
File metadata and controls
80 lines (63 loc) · 2.74 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This module requires IPython to work! It is meant to be used from an IPython environment with:
# ipython -wthread and -pylab
# See demo_pykinect.py for an example
import wx
from wx import glcanvas
from OpenGL.GL import *
# Get the app ourselves so we can attach it to each window
if not '__myapp' in wx.__dict__:
wx.__myapp = wx.PySimpleApp()
app = wx.__myapp
class Window(wx.Frame):
# wx events can be put in directly
def eventx(self, target):
def wrapper(*args, **kwargs):
target(*args, **kwargs)
self.canvas.Bind(wx.__dict__[target.__name__], wrapper)
# Events special to this class, just add them this way
def event(self, target):
def wrapper(*args, **kwargs):
target(*args, **kwargs)
self.__dict__[target.__name__] = wrapper
def _wrap(self, name, *args, **kwargs):
try:
self.__getattribute__(name)
except AttributeError:
pass
else:
self.__getattribute__(name)(*args, **kwargs)
def __init__(self, title='WxWindow', id=-1, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE,
name='frame'):
style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE
super(Window,self).__init__(None, id, title, pos, size, style, name)
attribList = (glcanvas.WX_GL_RGBA, # RGBA
glcanvas.WX_GL_DOUBLEBUFFER, # Double Buffered
glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit
self.canvas = glcanvas.GLCanvas(self, attribList=attribList)
self.canvas.Bind(wx.EVT_ERASE_BACKGROUND, self.processEraseBackgroundEvent)
self.canvas.Bind(wx.EVT_SIZE, self.processSizeEvent)
self.canvas.Bind(wx.EVT_PAINT, self.processPaintEvent)
self.Show()
def processEraseBackgroundEvent(self, event):
"""Process the erase background event."""
pass # Do nothing, to avoid flashing on MSWin
def processSizeEvent(self, event):
"""Process the resize event."""
if self.canvas.GetContext():
# Make sure the frame is shown before calling SetCurrent.
#self.Show()
self.canvas.SetCurrent()
size = self.GetClientSize()
self.OnReshape(size.width, size.height)
#self.canvas.Refresh(False)
event.Skip()
def processPaintEvent(self, event=None):
"""Process the drawing event."""
self.canvas.SetCurrent()
self._wrap('on_draw')
self.canvas.SwapBuffers()
if event: event.Skip()
def OnReshape(self, width, height):
"""Reshape the OpenGL viewport based on the dimensions of the window."""
glViewport(0, 0, width, height)