Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1037 - trunk/SwigInterface
- Date: Tue, 2 May 2006 17:19:05 -0600 (MDT)
Author: bigler
Date: Tue May 2 17:19:05 2006
New Revision: 1037
Modified:
trunk/SwigInterface/wxManta.py
Log:
Got rid of code that tried to send events. It turns out this is not a
safe thing to do. One should use the CallAfter command.
Added ability to switch what type of display to use at creation time.
You can now quit using the 'q' button. Getting focus to the canvas
requires a mouse click. I'm not sure why yet.
Modified: trunk/SwigInterface/wxManta.py
==============================================================================
--- trunk/SwigInterface/wxManta.py (original)
+++ trunk/SwigInterface/wxManta.py Tue May 2 17:19:05 2006
@@ -56,16 +56,6 @@
scene.getRenderParameters().maxDepth = 5
return scene
-EVT_MANTA_FRAME_READY_ID = wx.NewId()
-
-class FrameReadyEvent(wx.PyEvent):
- """Simple event to notify that a frame is ready."""
- def __init__(self):
- """Init Frame Ready event."""
- wx.PyEvent.__init__(self)
- self.SetEventType(EVT_MANTA_FRAME_READY_ID)
-
-
class DisplayThread(threading.Thread):
"""Display Thread that will trigger a display event when the manta
pipeline is ready to display an image."""
def __init__(self, notify_window, sync_display):
@@ -83,7 +73,7 @@
# before triggerring another event (which blocks and keeps
# the program from exiting properly.
if (not self.want_abort):
- wx.PostEvent(self.notify_window, FrameReadyEvent())
+ wx.CallAfter(self.notify_window.FrameReady)
def abort(self):
"""abort this thread."""
@@ -96,9 +86,11 @@
wxGLCanvas.__init__(self, parent, -1, style=wx.NO_BORDER)
self.sync_display = sync_display
self.opengl_display = opengl_display
+ # We bind the paint event to allow for some initialization
+ # after the window appears. We'll unbind it after that, since
+ # we don't care about expose or "paint me" events.
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.init = 0
- self.Connect(-1,-1, EVT_MANTA_FRAME_READY_ID, self.OnFrameReady)
def OnPaint(self, event):
# Note that you must always generate a wxPaintDC object,
@@ -108,7 +100,7 @@
if not self.init:
self.InitGL()
self.init = 1
- # Probably should unbind the OnPaint event
+ # Unbind the OnPaint event, since we don't need it anymore.
self.Bind(wx.EVT_PAINT, None)
self.clearScreen()
@@ -125,12 +117,16 @@
self.opengl_display.init()
self.clearScreen()
- def OnFrameReady(self, event):
+ def FrameReady(self):
self.SetCurrent()
self.opengl_display.displayImage(self.sync_display.getCurrentImage())
self.sync_display.doneRendering()
self.SwapBuffers()
+
+class Frame(wx.Frame):
+ pass
+
class App(wx.App) :
@@ -138,8 +134,8 @@
## OnInit
###########################################################################
def OnInit(self) :
- self.frame = wx.Frame(parent=None, title='Manta',
- size=wx.Size(xres, yres) )
+ self.frame = Frame(parent=None, title='Manta',
+ size=wx.Size(xres, yres) )
self.frame.Show()
@@ -162,22 +158,34 @@
# Image display.
use_stereo = False
-# display = manta_new( OpenGLDisplay( None, self.frame.GetHandle() )
)
-# self.sync_display = manta_new(SyncDisplay(vectorStr()))
-# self.sync_display.setChild(display)
-# self.Connect(-1,-1, EVT_MANTA_FRAME_READY_ID, self.OnFrameReady)
-# self.sync_thread = DisplayThread(self, self.sync_display)
-
- self.sync_display = manta_new(SyncDisplay(vectorStr()))
- self.sync_display.setChild(manta_new( NullDisplay(vectorStr()) ))
- opengl_display = manta_new(PureOpenGLDisplay(""))
- self.canvas = mantaGLCanvas(self.frame, self.sync_display,
- opengl_display)
- self.sync_thread = DisplayThread(self.canvas, self.sync_display)
+# renderFrameType = "glx"
+# renderFrameType = "glx_sync"
+ renderFrameType = "ogl"
+ display = None
+ if (renderFrameType == "glx"):
+ # This uses GLX directly
+ display = manta_new( OpenGLDisplay( None,
self.frame.GetHandle()))
+ self.canvas = self.frame
+ elif (renderFrameType == "glx_sync"):
+ # This uses the GLX with SyncDisplay
+ glx_display =
manta_new(OpenGLDisplay(None,self.frame.GetHandle()))
+ self.sync_display = manta_new(SyncDisplay(vectorStr()))
+ display = self.sync_display
+ self.sync_display.setChild(glx_display)
+ self.sync_thread = DisplayThread(self, self.sync_display)
+ self.canvas = self.frame
+ elif (renderFrameType == "ogl"):
+ # This uses PureOpenGLDisplay
+ self.sync_display = manta_new(SyncDisplay(vectorStr()))
+ display = self.sync_display
+ self.sync_display.setChild(manta_new( NullDisplay(vectorStr()) ))
+ opengl_display = manta_new(PureOpenGLDisplay(""))
+ self.canvas = mantaGLCanvas(self.frame, self.sync_display,
+ opengl_display)
+ self.sync_thread = DisplayThread(self.canvas, self.sync_display)
# Create a display channel.
- self.engine.createChannel( self.sync_display, camera, use_stereo,
xres, yres )
-# self.engine.createChannel( display, camera, use_stereo, xres, yres )
+ self.engine.createChannel( display, camera, use_stereo, xres, yres )
# Basic scene.
self.engine.setScene( createDefaultScenePython() )
@@ -204,10 +212,17 @@
###########################################################################
def OnExit(self):
print "Exiting the engine"
- self.sync_thread.abort()
+ # sync_thread and sync_display only exist for when we use a
+ # SyncDisplay class. Since this doesn't happen all the time
+ # we use the try block to allow continued progress
+ try:
+ self.sync_thread.abort()
+ except: pass
self.engine.finish()
- self.sync_display.doneRendering()
- self.sync_display.doneRendering()
+ try:
+ self.sync_display.doneRendering()
+ self.sync_display.doneRendering()
+ except: pass
self.engine.blockUntilFinished()
print "Engine exited"
@@ -225,19 +240,26 @@
def OnChar( self, event ):
print "OnChar"
key = event.GetKeyCode()
- if key == 'p':
- print "Found a 'p'"
- elif key == 'v':
- print "Found a 'v'"
+ if (key < 256):
+ key = chr(key)
+ if key == 'P':
+ print "Found a 'p'"
+ elif key == 'V':
+ print "Found a 'v'"
+ elif key == 'Q':
+ print "Quitting"
+ self.frame.Close()
+ else:
+ print "Unknown key '%s'" % key
else:
- print "Unknown key '%s'" % key
-
+ print "Found special key '%s'" % key
+
event.Skip()
###########################################################################
## OnChar
###########################################################################
- def OnFrameReady(self, event):
+ def FrameReady(self):
self.sync_display.renderFrame()
self.sync_display.doneRendering()
- [MANTA] r1037 - trunk/SwigInterface, bigler, 05/02/2006
Archive powered by MHonArc 2.6.16.