def _get_win_id(self): WId = self.winId() # Python2 if type(WId).__name__ == 'PyCObject': from ctypes import pythonapi, c_void_p, py_object pythonapi.PyCObject_AsVoidPtr.restype = c_void_p pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object] WId = pythonapi.PyCObject_AsVoidPtr(WId) # Python3 elif type(WId).__name__ == 'PyCapsule': from ctypes import pythonapi, c_void_p, py_object, c_char_p pythonapi.PyCapsule_GetName.restype = c_char_p pythonapi.PyCapsule_GetName.argtypes = [py_object] name = pythonapi.PyCapsule_GetName(WId) pythonapi.PyCapsule_GetPointer.restype = c_void_p pythonapi.PyCapsule_GetPointer.argtypes = [py_object, c_char_p] WId = pythonapi.PyCapsule_GetPointer(WId, name) return str(int(WId))
def __init__(self, parent=None, wflags=Qt.WindowFlags(), **kw): # the current button self._ActiveButton = Qt.NoButton # private attributes self.__saveX = 0 self.__saveY = 0 self.__saveModifiers = Qt.NoModifier self.__saveButtons = Qt.NoButton self.__wheelDelta = 0 # do special handling of some keywords: # stereo, rw try: stereo = bool(kw['stereo']) except KeyError: stereo = False try: rw = kw['rw'] except KeyError: rw = None # create qt-level widget QWidget.__init__(self, parent, wflags | Qt.MSWindowsOwnDC) if rw: # user-supplied render window self._RenderWindow = rw else: self._RenderWindow = vtk.vtkRenderWindow() WId = self.winId() # Python2 if type(WId).__name__ == 'PyCObject': from ctypes import pythonapi, c_void_p, py_object pythonapi.PyCObject_AsVoidPtr.restype = c_void_p pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object] WId = pythonapi.PyCObject_AsVoidPtr(WId) # Python3 elif type(WId).__name__ == 'PyCapsule': from ctypes import pythonapi, c_void_p, py_object, c_char_p pythonapi.PyCapsule_GetName.restype = c_char_p pythonapi.PyCapsule_GetName.argtypes = [py_object] name = pythonapi.PyCapsule_GetName(WId) pythonapi.PyCapsule_GetPointer.restype = c_void_p pythonapi.PyCapsule_GetPointer.argtypes = [py_object, c_char_p] WId = pythonapi.PyCapsule_GetPointer(WId, name) self._RenderWindow.SetWindowInfo(str(int(WId))) if stereo: # stereo mode self._RenderWindow.StereoCapableWindowOn() self._RenderWindow.SetStereoTypeToCrystalEyes() try: self._Iren = kw['iren'] except KeyError: self._Iren = vtk.vtkGenericRenderWindowInteractor() self._Iren.SetRenderWindow(self._RenderWindow) # do all the necessary qt setup self.setAttribute(Qt.WA_OpaquePaintEvent) self.setAttribute(Qt.WA_PaintOnScreen) self.setMouseTracking(True) # get all mouse events self.setFocusPolicy(Qt.WheelFocus) self.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self._Timer = QTimer(self) self._Timer.timeout.connect(self.TimerEvent) self._Iren.AddObserver('CreateTimerEvent', self.CreateTimer) self._Iren.AddObserver('DestroyTimerEvent', self.DestroyTimer) self._Iren.GetRenderWindow().AddObserver('CursorChangedEvent', self.CursorChangedEvent) #Create a hidden child widget and connect its destroyed signal to its #parent ``Finalize`` slot. The hidden children will be destroyed before #its parent thus allowing cleanup of VTK elements. self._hidden = QWidget(self) self._hidden.hide() self._hidden.destroyed.connect(self.Finalize)
def capsule_name(capsule): return pythonapi.PyCapsule_GetName(capsule)
def __init__(self, parent=None, **kw): # the current button self._ActiveButton = Qt.NoButton # private attributes self.__saveX = 0 self.__saveY = 0 self.__saveModifiers = Qt.NoModifier self.__saveButtons = Qt.NoButton self.__wheelDelta = 0 # do special handling of some keywords: # stereo, rw try: stereo = bool(kw['stereo']) except KeyError: stereo = False try: rw = kw['rw'] except KeyError: rw = None # create base qt-level widget if QVTKRWIBase == "QWidget": if "wflags" in kw: wflags = kw['wflags'] else: wflags = Qt.WindowFlags() QWidget.__init__(self, parent, wflags | Qt.MSWindowsOwnDC) elif QVTKRWIBase == "QOpenGLWidget": QOpenGLWidget.__init__(self, parent) if rw: # user-supplied render window self._RenderWindow = rw else: self._RenderWindow = vtkRenderWindow() WId = self.winId() # Python2 if type(WId).__name__ == 'PyCObject': from ctypes import pythonapi, c_void_p, py_object pythonapi.PyCObject_AsVoidPtr.restype = c_void_p pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object] WId = pythonapi.PyCObject_AsVoidPtr(WId) # Python3 elif type(WId).__name__ == 'PyCapsule': from ctypes import pythonapi, c_void_p, py_object, c_char_p pythonapi.PyCapsule_GetName.restype = c_char_p pythonapi.PyCapsule_GetName.argtypes = [py_object] name = pythonapi.PyCapsule_GetName(WId) pythonapi.PyCapsule_GetPointer.restype = c_void_p pythonapi.PyCapsule_GetPointer.argtypes = [py_object, c_char_p] WId = pythonapi.PyCapsule_GetPointer(WId, name) self._RenderWindow.SetWindowInfo(str(int(WId))) if stereo: # stereo mode self._RenderWindow.StereoCapableWindowOn() self._RenderWindow.SetStereoTypeToCrystalEyes() try: self._Iren = kw['iren'] except KeyError: self._Iren = vtkGenericRenderWindowInteractor() self._Iren.SetRenderWindow(self._RenderWindow) # do all the necessary qt setup self.setAttribute(Qt.WA_OpaquePaintEvent) self.setAttribute(Qt.WA_PaintOnScreen) self.setMouseTracking(True) # get all mouse events self.setFocusPolicy(Qt.WheelFocus) self.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self._Timer = QTimer(self) self._Timer.timeout.connect(self.TimerEvent) self._Iren.AddObserver('CreateTimerEvent', self.CreateTimer) self._Iren.AddObserver('DestroyTimerEvent', self.DestroyTimer) self._Iren.GetRenderWindow().AddObserver('CursorChangedEvent', self.CursorChangedEvent) # If we've a parent, it does not close the child when closed. # Connect the parent's destroyed signal to this widget's close # slot for proper cleanup of VTK objects. if self.parent(): self.parent().destroyed.connect(self.close, Qt.DirectConnection)
def __init__(self, parent=None, wflags=Qt.WindowFlags()): # the current button self._ActiveButton = Qt.NoButton # private attributes self.__saveX = 0 self.__saveY = 0 self.__saveModifiers = Qt.NoModifier self.__saveButtons = Qt.NoButton # create qt-level widget glFormat = QtOpenGL.QGLFormat() glFormat.setAlpha(True) QtOpenGL.QGLWidget.__init__(self, glFormat, parent, None) # Create a wender window self._RenderWindow = vtk.vtkRenderWindow() self._RenderWindow.SetAlphaBitPlanes(1) self._RenderWindow.SetMultiSamples(0) # Create a renderer self._Renderer = vtk.vtkRenderer() self._Renderer.SetUseDepthPeeling(1) #self._Renderer.SetMaximumNumberOfPeels(100) #self._Renderer.SetOcclusionRatio(0.0) self._RenderWindow.AddRenderer(self._Renderer) WId = self.winId() # Python2 if type(WId).__name__ == 'PyCObject': from ctypes import pythonapi, c_void_p, py_object pythonapi.PyCObject_AsVoidPtr.restype = c_void_p pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object] WId = pythonapi.PyCObject_AsVoidPtr(WId) # Python3 elif type(WId).__name__ == 'PyCapsule': from ctypes import pythonapi, c_void_p, py_object, c_char_p pythonapi.PyCapsule_GetName.restype = c_char_p pythonapi.PyCapsule_GetName.argtypes = [py_object] name = pythonapi.PyCapsule_GetName(WId) pythonapi.PyCapsule_GetPointer.restype = c_void_p pythonapi.PyCapsule_GetPointer.argtypes = [py_object, c_char_p] WId = pythonapi.PyCapsule_GetPointer(WId, name) self._RenderWindow.SetWindowInfo(str(int(WId))) self._Iren = vtk.vtkGenericRenderWindowInteractor() self._Iren.SetRenderWindow(self._RenderWindow) # do all the necessary qt setup self.setAttribute(Qt.WA_OpaquePaintEvent) self.setAttribute(Qt.WA_PaintOnScreen) self.setMouseTracking(True) # get all mouse events self.setFocusPolicy(Qt.WheelFocus) self.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self._Timer = QTimer(self) self._Timer.timeout.connect(self.TimerEvent) self._Iren.AddObserver('CreateTimerEvent', self.CreateTimer) self._Iren.AddObserver('DestroyTimerEvent', self.DestroyTimer) self._Iren.GetRenderWindow().AddObserver('CursorChangedEvent', self.CursorChangedEvent) #Create a hidden child widget and connect its destroyed signal to its #parent ``Finalize`` slot. The hidden children will be destroyed before #its parent thus allowing cleanup of VTK elements. self._hidden = QWidget(self) self._hidden.hide() self._hidden.destroyed.connect(self.Finalize)
def __init__(self, parent=None, **kw): # the current button self._ActiveButton = Qt.NoButton # private attributes self.__saveX = 0 self.__saveY = 0 self.__saveModifiers = Qt.NoModifier self.__saveButtons = Qt.NoButton self.__wheelDelta = 0 # do special handling of some keywords: # stereo, rw try: stereo = bool(kw['stereo']) except KeyError: stereo = False try: rw = kw['rw'] except KeyError: rw = None # create base qt-level widget if QVTKRWIBase == "QWidget": if "wflags" in kw: wflags = kw['wflags'] else: wflags = Qt.WindowFlags() QWidget.__init__(self, parent, wflags | Qt.MSWindowsOwnDC) elif QVTKRWIBase == "QGLWidget": QGLWidget.__init__(self, parent) if rw: # user-supplied render window self._RenderWindow = rw else: self._RenderWindow = vtk.vtkRenderWindow() WId = self.winId() print 'WId=', WId # print 'widget id = ', widget.winId() win_id = int(WId) print 'win_id=', win_id l_int = c_long(win_id) # lib.cpp_disableGLHiDPI(4621918512) lib.cpp_disableGLHiDPI(l_int) # # disableGLHiDPI(widget.winId()) # Python2 if type(WId).__name__ == 'PyCObject': from ctypes import pythonapi, c_void_p, py_object pythonapi.PyCObject_AsVoidPtr.restype = c_void_p pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object] WId = pythonapi.PyCObject_AsVoidPtr(WId) # Python3 elif type(WId).__name__ == 'PyCapsule': from ctypes import pythonapi, c_void_p, py_object, c_char_p pythonapi.PyCapsule_GetName.restype = c_char_p pythonapi.PyCapsule_GetName.argtypes = [py_object] name = pythonapi.PyCapsule_GetName(WId) pythonapi.PyCapsule_GetPointer.restype = c_void_p pythonapi.PyCapsule_GetPointer.argtypes = [py_object, c_char_p] WId = pythonapi.PyCapsule_GetPointer(WId, name) self._RenderWindow.SetWindowInfo(str(int(WId))) # if stereo: # stereo mode # self._RenderWindow.StereoCapableWindowOn() # self._RenderWindow.SetStereoTypeToCrystalEyes() try: self._Iren = kw['iren'] except KeyError: self._Iren = vtk.vtkGenericRenderWindowInteractor() self._Iren.SetRenderWindow(self._RenderWindow) # this is needed to get nice'n'smooth mouse interaction self.interactorStyle = vtk.vtkInteractorStyleSwitch() # self.interactorStyle.SetCurrentStyleToTrackballActor() self.interactorStyle.SetCurrentStyleToTrackballCamera() self._Iren.SetInteractorStyle(self.interactorStyle) # do all the necessary qt setup self.setAttribute(Qt.WA_OpaquePaintEvent) self.setAttribute(Qt.WA_PaintOnScreen) self.setMouseTracking(True) # get all mouse events self.setFocusPolicy(Qt.WheelFocus) self.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self._Timer = QTimer(self) self._Timer.timeout.connect(self.TimerEvent) self._Iren.AddObserver('CreateTimerEvent', self.CreateTimer) self._Iren.AddObserver('DestroyTimerEvent', self.DestroyTimer) self._Iren.GetRenderWindow().AddObserver('CursorChangedEvent', self.CursorChangedEvent) #Create a hidden child widget and connect its destroyed signal to its #parent ``Finalize`` slot. The hidden children will be destroyed before #its parent thus allowing cleanup of VTK elements. self._hidden = QWidget(self) self._hidden.hide() self._hidden.destroyed.connect(self.Finalize) self.mousePressEventFcn = self.mousePressEvent2DStyle