<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hello,<div><br></div><div>I'm using the module vtkWeb for Remote Rendering, following this simple python example:</div><div><br></div><div><font color="#1155cc"><u><a href="https://github.com/dmreagan/vtk-remote-render/blob/master/server/vtk_server.py">https://github.com/dmreagan/vtk-remote-render/blob/master/server/vtk_server.py</a></u></font><br></div><div><font color="#1155cc"><u><br></u></font></div><div>and I have modified it in order to include a keyPress event. The code works but the </div><div>key event is not working . Please find my code below (the only modification from the link is the class MyInteractorStyle ).</div><div><br></div><div>I'll really appreciate any help with this! </div><div><br></div><div>Thanks !!</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>##########################################################################</div><div>##########################################################################</div><div><br></div><div><div># import to process args</div><div>import sys</div><div>import os</div><div><br></div><div># import vtk modules.</div><div>import vtk</div><div>from vtk.web import protocols</div><div>from vtk.web import wslink as vtk_wslink</div><div>from wslink import server</div><div><br></div><div>try:</div><div>    import argparse</div><div>except ImportError:</div><div>    # since  Python 2.6 and earlier don't have argparse, we simply provide</div><div>    # the source for the same as _argparse and we use it instead.</div><div>    from vtk.util import _argparse as argparse</div><div><br></div><div># =============================================================================</div><div># Create custom ServerProtocol class to handle clients requests</div><div># =============================================================================</div><div><br></div><div><br></div><div>class MyInteractorStyle(vtk.vtkInteractorStyleTrackballCamera):</div><div><br></div><div>    def __init__(self,renderer, cone):</div><div>        self.parent = renderer.GetInteractor()</div><div><span style="white-space:pre">        </span>self.resolution=5</div><div><span style="white-space:pre">     </span>self.cone = cone</div><div><br></div><div>        self.AddObserver("KeyPressEvent",self.keyPressEvent)</div><div><br></div><div>    def keyPressEvent(self,obj,event):</div><div>        key = self.parent.GetKeySym()</div><div>        if key == 'l':</div><div><span style="white-space:pre">   </span>    print(key)</div><div><span style="white-space:pre">      </span>    self.cone.SetResolution(self.resolution)</div><div><span style="white-space:pre">        </span>    self.resolution+=1</div><div>        return</div><div><br></div><div><br></div><div><br></div><div><br></div><div>class _WebCone(vtk_wslink.ServerProtocol):</div><div><br></div><div>    # Application configuration</div><div>    view    = None</div><div>    authKey = "wslink-secret"</div><div><br></div><div>    def initialize(self):</div><div>        global renderer, renderWindow, renderWindowInteractor, cone, mapper, actor</div><div><br></div><div>        # Bring used components</div><div>        self.registerVtkWebProtocol(protocols.vtkWebMouseHandler())</div><div>        self.registerVtkWebProtocol(protocols.vtkWebViewPort())</div><div>        self.registerVtkWebProtocol(protocols.vtkWebViewPortImageDelivery())</div><div>        self.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery())</div><div><br></div><div>        # Update authentication key to use</div><div>        self.updateSecret(_WebCone.authKey)</div><div><br></div><div>        # Create default pipeline (Only once for all the session)</div><div>        if not _WebCone.view:</div><div>            # VTK specific code</div><div>            renderer = vtk.vtkRenderer()</div><div>            renderWindow = vtk.vtkRenderWindow()</div><div>            renderWindow.AddRenderer(renderer)</div><div><br></div><div>            renderWindowInteractor = vtk.vtkRenderWindowInteractor()</div><div>            renderWindowInteractor.SetRenderWindow(renderWindow)</div><div>            </div><div><span style="white-space:pre">   </span>    <br></div><div><br></div><div>            cone = vtk.vtkConeSource()</div><div>            mapper = vtk.vtkPolyDataMapper()</div><div>            actor = vtk.vtkActor()</div><div><br></div><div>            mapper.SetInputConnection(cone.GetOutputPort())</div><div>            actor.SetMapper(mapper)</div><div><br></div><div><span style="white-space:pre">       </span>    renderWindowInteractor.SetInteractorStyle(MyInteractorStyle(renderWindow, cone))</div><div><br></div><div>            renderer.AddActor(actor)</div><div>            renderer.ResetCamera()</div><div>            renderWindow.Render()</div><div><br></div><div>            # VTK Web application specific</div><div>            _WebCone.view = renderWindow</div><div>            self.getApplication().GetObjectIdMap().SetActiveObject("VIEW", renderWindow)</div><div><br></div><div><span style="white-space:pre">    </span>  #  renderWindowInteractor.Start()</div><div><br></div><div># =============================================================================</div><div># Main: Parse args and start server</div><div># =============================================================================</div><div><br></div><div>if __name__ == "__main__":</div><div>    # Create argument parser</div><div>    parser = argparse.ArgumentParser(description="VTK/Web Cone web-application")</div><div><br></div><div>    # Add default arguments</div><div>    server.add_arguments(parser)</div><div><br></div><div>    # Extract arguments</div><div>    args = parser.parse_args()</div><div><br></div><div>    # Configure our current application</div><div>    _WebCone.authKey = args.authKey</div><div><br></div><div>    # Start server</div><div>    server.start_webserver(options=args, protocol=_WebCone)</div></div><div><br></div></div></div></div></div>