Hello,
Chris Spencer wrote:
If you mean some example code, then certainly. It's
actually rather simple:
.....
Has the VTK widget is no longer running on wxPython
2.5, I wonder if it is a problem o thread. So I wrote
the small test program based on the example. It works
fine on 2.4.2, but on 2.5 (The interesting version,
since VTK woks on 2.4.2 without subtilities) the
programs returns without calling the OnInit method.
The program can be test without VTK by removing the
calls to VTK.
If someone can tell me what is wrong with this
program, even without VTK, I would be grateful.
Thanks.
I join both version, with and without VTK.
program with VTK:
import vtk
from vtk.wx.wxVTKRenderWindow import wxVTKRenderWindow
from vtk import *
class SelfImportingProxyClass:
def __init__(self, imp, obj, call, *args,
**kargs):
exec 'import '+imp
self.imp = eval(imp)
self.obj = eval('self.imp.' + obj)
self.call = call
self.args = args
self.kargs = kargs
self.obj.OnInit = self.OnInit
def __call__(self, *args, **kargs):
self.obj = self.obj(*self.args, **self.kargs)
eval('self.obj.'+self.call)(*args, **kargs)
return self.obj
def OnInit(self):
print 'In OnInit'
self.frame = self.imp.wxFrame(None, -1,
"wxRenderWindow", size=self.imp.wxSize(400,400))
self.frame.Show(1)
#self.obj.SetTopWindow(self, self.frame)
widget = wxVTKRenderWindow(self.frame, -1)
ren = vtkRenderer()
widget.GetRenderWindow().AddRenderer(ren)
cone = vtkConeSource()
cone.SetResolution(8)
coneMapper = vtkPolyDataMapper()
coneMapper.SetInput(cone.GetOutput())
coneActor = vtkActor()
coneActor.SetMapper(coneMapper)
ren.AddActor(coneActor)
# show the window
return 1
if __name__ == "__main__":
#from vtkpython import *
import threading
## the normal way wx doesn't like
#import Gui
#app = Gui.App()
#t = threading.Thread(target=app.MainLoop)
#t.start()
## work around
proxy = SelfImportingProxyClass(imp='wxPython.wx',
obj='wxApp', call='MainLoop')
t = threading.Thread(target=proxy)
t.start()
# go about your buisness...
Program without VTK:
class SelfImportingProxyClass:
def __init__(self, imp, obj, call, *args,
**kargs):
exec 'import '+imp
self.imp = eval(imp)
self.obj = eval('self.imp.' + obj)
self.call = call
self.args = args
self.kargs = kargs
self.obj.OnInit = self.OnInit
def __call__(self, *args, **kargs):
self.obj = self.obj(*self.args, **self.kargs)
eval('self.obj.'+self.call)(*args, **kargs)
return self.obj
def OnInit(self):
print 'In OnInit'
self.frame = self.imp.wxFrame(None, -1,
"wxRenderWindow", size=self.imp.wxSize(400,400))
self.frame.Show(1)
#self.obj.SetTopWindow(self, self.frame)
return 1
if __name__ == "__main__":
#from vtkpython import *
import threading
## the normal way wx doesn't like
#import Gui
#app = Gui.App()
#t = threading.Thread(target=app.MainLoop)
#t.start()
## work around
proxy = SelfImportingProxyClass(imp='wxPython.wx',
obj='wxApp', call='MainLoop')
t = threading.Thread(target=proxy)
t.start()
# go about your buisness...
Pierre-Alain Moret
Vous manquez despace pour stocker vos mails ?
Yahoo! Mail vous offre GRATUITEMENT 100 Mo !
Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/
Le nouveau Yahoo! Messenger est arrivé ! Découvrez toutes les nouveautés pour dialoguer instantanément avec vos amis. A télécharger gratuitement sur http://fr.messenger.yahoo.com