예제 #1
0
    class CommandDocsWidget(QScrollArea):
        def __init__(self, command, parent=None):
            super(CommandDocsWidget, self).__init__(parent)
            self.command = CommandDocsParser.parse(command)
            self._setupUi()
    
        def _setupUi(self):
            self.setWidgetResizable(True)
            
            self.docsWidget = QWidget()
            docsLayout = QVBoxLayout()
            self.docsWidget.setLayout(docsLayout)

            lblCmdName = QLabel("<h1>{0}</h1>".format(self.command.name))
            docsLayout.addWidget(lblCmdName)
            
            lblDesc = QLabel(self.command.description)
            docsLayout.addWidget(lblDesc)

            self.flagsWidget = QWidget()
            self.flagsWidget.setLayout(QVBoxLayout())
            docsLayout.addWidget(self.flagsWidget)
    
            self.setWidget(self.docsWidget)
            
            self.refreshDocs()
            
        def refreshDocs(self, modes=None):
            if modes:
                docsLayout = self.docsWidget.layout()
                docsLayout.removeWidget(self.flagsWidget)
                self.flagsWidget.hide()
                self.flagsWidget.deleteLater()
                self.flagsWidget = QWidget()
                self.flagsWidget.setLayout(QVBoxLayout())
                docsLayout.addWidget(self.flagsWidget)
                flags = []
                for mode in modes:
                    for name in self.command.modes[mode]:
                        flags.append(self.command.flags[name])
            else:
                flags = self.command.flags.values()
                docsLayout = self.docsWidget.layout()
                docsLayout.removeWidget(self.flagsWidget)
                self.flagsWidget.hide()
                self.flagsWidget.deleteLater()
                self.flagsWidget = QWidget()
                self.flagsWidget.setLayout(QVBoxLayout())
                docsLayout.addWidget(self.flagsWidget)

            flagsLayout = self.flagsWidget.layout()
            
            for flag in flags:
                lblFlag = QLabel("<h2>{0.longName} - {0.shortName} - {0.type}</h2>".format(flag))
                flagsLayout.addWidget(lblFlag)
                lblModes = QLabel("{0}".format(', '.join(flag.modes) if flag.modes else "Undefined"))
                flagsLayout.addWidget(lblModes)
                lblFlagDesc = QLabel(flag.description)
                flagsLayout.addWidget(lblFlagDesc)
예제 #2
0
파일: editor.py 프로젝트: altawu/everpad
 def hide(self):
     QWidget.hide(self)
     if not self.visible:
         return
     self.update_highlight(clear=True)
     self.editor.ui.centralwidget.layout().removeWidget(self)
     self.setParent(None)
     self.visible = False
     self.editor.find_action.setChecked(False)
예제 #3
0
파일: actions.py 프로젝트: MikeyG/gevernote
 def hide(self):
     QWidget.hide(self)
     if not self.visible:
         return
     self.update_highlight(clear=True)
     self.editor.ui.centralwidget.layout().removeWidget(self)
     self.setParent(None)
     self.visible = False
     self.editor.find_action.setChecked(False)
예제 #4
0
    class WidgetPySignal(UsesQApplication):
        """Tests the connection of python signals to QWidget qt slots."""

        def setUp(self):
            super(WidgetPySignal, self).setUp()
            self.obj = Dummy()
            self.widget = QWidget()

        def tearDown(self):
            super(WidgetPySignal, self).tearDown()
            del self.obj
            del self.widget

        def testShow(self):
            """Emission of a python signal to QWidget slot show()"""
            self.widget.hide()

            QObject.connect(self.obj, SIGNAL('dummy()'), self.widget, SLOT('show()'))
            self.assert_(not self.widget.isVisible())

            self.obj.emit(SIGNAL('dummy()'))
            self.assert_(self.widget.isVisible())
예제 #5
0
 def hide(self):
     QWidget.hide(self)
예제 #6
0
    class CommandDocsWidget(QScrollArea):
        def __init__(self, command, parent=None):
            super(CommandDocsWidget, self).__init__(parent)
            self.command = CommandDocsParser.parse(command)
            self._setupUi()

        def _setupUi(self):
            self.setWidgetResizable(True)

            self.docsWidget = QWidget()
            docsLayout = QVBoxLayout()
            self.docsWidget.setLayout(docsLayout)

            lblCmdName = QLabel("<h1>{0}</h1>".format(self.command.name))
            docsLayout.addWidget(lblCmdName)

            lblDesc = QLabel(self.command.description)
            docsLayout.addWidget(lblDesc)

            self.flagsWidget = QWidget()
            self.flagsWidget.setLayout(QVBoxLayout())
            docsLayout.addWidget(self.flagsWidget)

            self.setWidget(self.docsWidget)

            self.refreshDocs()

        def refreshDocs(self, modes=None):
            if modes:
                docsLayout = self.docsWidget.layout()
                docsLayout.removeWidget(self.flagsWidget)
                self.flagsWidget.hide()
                self.flagsWidget.deleteLater()
                self.flagsWidget = QWidget()
                self.flagsWidget.setLayout(QVBoxLayout())
                docsLayout.addWidget(self.flagsWidget)
                flags = []
                for mode in modes:
                    for name in self.command.modes[mode]:
                        flags.append(self.command.flags[name])
            else:
                flags = self.command.flags.values()
                docsLayout = self.docsWidget.layout()
                docsLayout.removeWidget(self.flagsWidget)
                self.flagsWidget.hide()
                self.flagsWidget.deleteLater()
                self.flagsWidget = QWidget()
                self.flagsWidget.setLayout(QVBoxLayout())
                docsLayout.addWidget(self.flagsWidget)

            flagsLayout = self.flagsWidget.layout()

            for flag in flags:
                lblFlag = QLabel(
                    "<h2>{0.longName} - {0.shortName} - {0.type}</h2>".format(
                        flag))
                flagsLayout.addWidget(lblFlag)
                lblModes = QLabel("{0}".format(
                    ', '.join(flag.modes) if flag.modes else "Undefined"))
                flagsLayout.addWidget(lblModes)
                lblFlagDesc = QLabel(flag.description)
                flagsLayout.addWidget(lblFlagDesc)
예제 #7
0
class QVTKRenderWindowInteractor(QWidget):
    """ A QVTKRenderWindowInteractor for Python and Qt.  Uses a
    vtkGenericRenderWindowInteractor to handle the interactions.  Use
    GetRenderWindow() to get the vtkRenderWindow.  Create with the
    keyword stereo=1 in order to generate a stereo-capable window.
    The user interface is summarized in vtkInteractorStyle.h:
    - Keypress j / Keypress t: toggle between joystick (position
    sensitive) and trackball (motion sensitive) styles. In joystick
    style, motion occurs continuously as long as a mouse button is
    pressed. In trackball style, motion occurs when the mouse button
    is pressed and the mouse pointer moves.
    - Keypress c / Keypress o: toggle between camera and object
    (actor) modes. In camera mode, mouse events affect the camera
    position and focal point. In object mode, mouse events affect
    the actor that is under the mouse pointer.
    - Button 1: rotate the camera around its focal point (if camera
    mode) or rotate the actor around its origin (if actor mode). The
    rotation is in the direction defined from the center of the
    renderer's viewport towards the mouse position. In joystick mode,
    the magnitude of the rotation is determined by the distance the
    mouse is from the center of the render window.
    - Button 2: pan the camera (if camera mode) or translate the actor
    (if object mode). In joystick mode, the direction of pan or
    translation is from the center of the viewport towards the mouse
    position. In trackball mode, the direction of motion is the
    direction the mouse moves. (Note: with 2-button mice, pan is
    defined as <Shift>-Button 1.)
    - Button 3: zoom the camera (if camera mode) or scale the actor
    (if object mode). Zoom in/increase scale if the mouse position is
    in the top half of the viewport; zoom out/decrease scale if the
    mouse position is in the bottom half. In joystick mode, the amount
    of zoom is controlled by the distance of the mouse pointer from
    the horizontal centerline of the window.
    - Keypress 3: toggle the render window into and out of stereo
    mode.  By default, red-blue stereo pairs are created. Some systems
    support Crystal Eyes LCD stereo glasses; you have to invoke
    SetStereoTypeToCrystalEyes() on the rendering window.  Note: to
    use stereo you also need to pass a stereo=1 keyword argument to
    the constructor.
    - Keypress e: exit the application.
    - Keypress f: fly to the picked point
    - Keypress p: perform a pick operation. The render window interactor
    has an internal instance of vtkCellPicker that it uses to pick.
    - Keypress r: reset the camera view along the current view
    direction. Centers the actors and moves the camera so that all actors
    are visible.
    - Keypress s: modify the representation of all actors so that they
    are surfaces.
    - Keypress u: invoke the user-defined function. Typically, this
    keypress will bring up an interactor that you can type commands in.
    - Keypress w: modify the representation of all actors so that they
    are wireframe.
    """

    # Map between VTK and Qt cursors.
    _CURSOR_MAP = {
        0: Qt.ArrowCursor,  # VTK_CURSOR_DEFAULT
        1: Qt.ArrowCursor,  # VTK_CURSOR_ARROW
        2: Qt.SizeBDiagCursor,  # VTK_CURSOR_SIZENE
        3: Qt.SizeFDiagCursor,  # VTK_CURSOR_SIZENWSE
        4: Qt.SizeBDiagCursor,  # VTK_CURSOR_SIZESW
        5: Qt.SizeFDiagCursor,  # VTK_CURSOR_SIZESE
        6: Qt.SizeVerCursor,  # VTK_CURSOR_SIZENS
        7: Qt.SizeHorCursor,  # VTK_CURSOR_SIZEWE
        8: Qt.SizeAllCursor,  # VTK_CURSOR_SIZEALL
        9: Qt.PointingHandCursor,  # VTK_CURSOR_HAND
        10: Qt.CrossCursor,  # VTK_CURSOR_CROSSHAIR
    }

    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 "wflags" in kw:
            wflags = kw['wflags']
        else:
            wflags = Qt.WindowFlags()
        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 dispatchEvent(self, eventFunc):
        eventFunc()

    #QTimer.singleShot(0, eventFunc)

    def __getattr__(self, attr):
        """Makes the object behave like a vtkGenericRenderWindowInteractor"""
        if attr == '__vtk__':
            return lambda t=self._Iren: t
        elif hasattr(self._Iren, attr):
            return getattr(self._Iren, attr)
        else:
            raise AttributeError(self.__class__.__name__ +
                                 " has no attribute named " + attr)

    def Finalize(self):
        '''
        Call internal cleanup method on VTK objects
        '''
        self._RenderWindow.Finalize()

    def CreateTimer(self, obj, evt):
        self._Timer.start(10)

    def DestroyTimer(self, obj, evt):
        self._Timer.stop()
        return 1

    def TimerEvent(self):
        self.dispatchEvent(self._Iren.TimerEvent)

    def CursorChangedEvent(self, obj, evt):
        """Called when the CursorChangedEvent fires on the render window."""
        # This indirection is needed since when the event fires, the current
        # cursor is not yet set so we defer this by which time the current
        # cursor should have been set.
        QTimer.singleShot(0, self.ShowCursor)

    def HideCursor(self):
        """Hides the cursor."""
        self.setCursor(Qt.BlankCursor)

    def ShowCursor(self):
        """Shows the cursor."""
        vtk_cursor = self._Iren.GetRenderWindow().GetCurrentCursor()
        qt_cursor = self._CURSOR_MAP.get(vtk_cursor, Qt.ArrowCursor)
        self.setCursor(qt_cursor)

    def closeEvent(self, evt):
        self.Finalize()

    def sizeHint(self):
        return QSize(400, 400)

    def paintEngine(self):
        return None

    def paintEvent(self, ev):
        self._Iren.Render()

    def updateSize(self):
        w, h = self.width(), self.height()
        self._RenderWindow.SetSize(w, h)
        self._Iren.SetSize(w, h)
        self.update()

    def resizeEvent(self, ev):
        self.dispatchEvent(self.updateSize)
        self.dispatchEvent(self._Iren.ConfigureEvent)

    def _GetCtrlShift(self, ev):
        ctrl = shift = False

        if hasattr(ev, 'modifiers'):
            if ev.modifiers() & Qt.ShiftModifier:
                shift = True
            if ev.modifiers() & Qt.ControlModifier:
                ctrl = True
        else:
            if self.__saveModifiers & Qt.ShiftModifier:
                shift = True
            if self.__saveModifiers & Qt.ControlModifier:
                ctrl = True

        return ctrl, shift

    def enterEvent(self, ev):
        ctrl, shift = self._GetCtrlShift(ev)
        self._Iren.SetEventInformationFlipY(self.__saveX, self.__saveY, ctrl,
                                            shift, chr(0), 0, None)
        self.dispatchEvent(self._Iren.EnterEvent)

    def leaveEvent(self, ev):
        ctrl, shift = self._GetCtrlShift(ev)
        self._Iren.SetEventInformationFlipY(self.__saveX, self.__saveY, ctrl,
                                            shift, chr(0), 0, None)
        self.dispatchEvent(self._Iren.LeaveEvent)

    def mousePressEvent(self, ev):
        ctrl, shift = self._GetCtrlShift(ev)
        repeat = 0
        if ev.type() == QEvent.MouseButtonDblClick:
            repeat = 1
        self._Iren.SetEventInformationFlipY(ev.x(), ev.y(), ctrl, shift,
                                            chr(0), repeat, None)

        self._ActiveButton = ev.button()

        if self._ActiveButton == Qt.LeftButton:
            self.dispatchEvent(self._Iren.LeftButtonPressEvent)
        elif self._ActiveButton == Qt.RightButton:
            self.dispatchEvent(self._Iren.RightButtonPressEvent)
        elif self._ActiveButton == Qt.MidButton:
            self.dispatchEvent(self._Iren.MiddleButtonPressEvent)

    def mouseReleaseEvent(self, ev):
        ctrl, shift = self._GetCtrlShift(ev)
        self._Iren.SetEventInformationFlipY(ev.x(), ev.y(), ctrl, shift,
                                            chr(0), 0, None)

        if self._ActiveButton == Qt.LeftButton:
            self.dispatchEvent(self._Iren.LeftButtonReleaseEvent)
        elif self._ActiveButton == Qt.RightButton:
            self.dispatchEvent(self._Iren.RightButtonReleaseEvent)
        elif self._ActiveButton == Qt.MidButton:
            self.dispatchEvent(self._Iren.MiddleButtonReleaseEvent)

    def mouseMoveEvent(self, ev):
        self.__saveModifiers = ev.modifiers()
        self.__saveButtons = ev.buttons()
        self.__saveX = ev.x()
        self.__saveY = ev.y()

        ctrl, shift = self._GetCtrlShift(ev)
        self._Iren.SetEventInformationFlipY(ev.x(), ev.y(), ctrl, shift,
                                            chr(0), 0, None)
        self.dispatchEvent(self._Iren.MouseMoveEvent)

    def keyPressEvent(self, ev):
        ctrl, shift = self._GetCtrlShift(ev)
        if ev.key() < 256:
            key = str(ev.text())
        else:
            key = chr(0)

        keySym = _qt_key_to_key_sym(ev.key())
        if shift and len(keySym) == 1 and keySym.isalpha():
            keySym = keySym.upper()

        self._Iren.SetEventInformationFlipY(self.__saveX, self.__saveY, ctrl,
                                            shift, key, 0, keySym)
        self.dispatchEvent(self._Iren.KeyPressEvent)
        self.dispatchEvent(self._Iren.CharEvent)

    def keyReleaseEvent(self, ev):
        ctrl, shift = self._GetCtrlShift(ev)
        if ev.key() < 256:
            key = chr(ev.key())
        else:
            key = chr(0)

        self._Iren.SetEventInformationFlipY(self.__saveX, self.__saveY, ctrl,
                                            shift, key, 0, None)
        self.dispatchEvent(self._Iren.KeyReleaseEvent)

    def wheelEvent(self, ev):
        if hasattr(ev, 'delta'):
            self.__wheelDelta += ev.delta()
        else:
            self.__wheelDelta += ev.angleDelta().y()

        if self.__wheelDelta >= 120:
            self.dispatchEvent(self._Iren.MouseWheelForwardEvent)
            self.__wheelDelta = 0
        elif self.__wheelDelta <= -120:
            self.dispatchEvent(self._Iren.MouseWheelBackwardEvent)
            self.__wheelDelta = 0

    def GetRenderWindow(self):
        return self._RenderWindow

    def Render(self):
        self.update()
예제 #8
0
class QVTKRenderWindowInteractor(QWidget):

    """ A QVTKRenderWindowInteractor for Python and Qt.  Uses a
    vtkGenericRenderWindowInteractor to handle the interactions.  Use
    GetRenderWindow() to get the vtkRenderWindow.  Create with the
    keyword stereo=1 in order to generate a stereo-capable window.
    The user interface is summarized in vtkInteractorStyle.h:
    - Keypress j / Keypress t: toggle between joystick (position
    sensitive) and trackball (motion sensitive) styles. In joystick
    style, motion occurs continuously as long as a mouse button is
    pressed. In trackball style, motion occurs when the mouse button
    is pressed and the mouse pointer moves.
    - Keypress c / Keypress o: toggle between camera and object
    (actor) modes. In camera mode, mouse events affect the camera
    position and focal point. In object mode, mouse events affect
    the actor that is under the mouse pointer.
    - Button 1: rotate the camera around its focal point (if camera
    mode) or rotate the actor around its origin (if actor mode). The
    rotation is in the direction defined from the center of the
    renderer's viewport towards the mouse position. In joystick mode,
    the magnitude of the rotation is determined by the distance the
    mouse is from the center of the render window.
    - Button 2: pan the camera (if camera mode) or translate the actor
    (if object mode). In joystick mode, the direction of pan or
    translation is from the center of the viewport towards the mouse
    position. In trackball mode, the direction of motion is the
    direction the mouse moves. (Note: with 2-button mice, pan is
    defined as <Shift>-Button 1.)
    - Button 3: zoom the camera (if camera mode) or scale the actor
    (if object mode). Zoom in/increase scale if the mouse position is
    in the top half of the viewport; zoom out/decrease scale if the
    mouse position is in the bottom half. In joystick mode, the amount
    of zoom is controlled by the distance of the mouse pointer from
    the horizontal centerline of the window.
    - Keypress 3: toggle the render window into and out of stereo
    mode.  By default, red-blue stereo pairs are created. Some systems
    support Crystal Eyes LCD stereo glasses; you have to invoke
    SetStereoTypeToCrystalEyes() on the rendering window.  Note: to
    use stereo you also need to pass a stereo=1 keyword argument to
    the constructor.
    - Keypress e: exit the application.
    - Keypress f: fly to the picked point
    - Keypress p: perform a pick operation. The render window interactor
    has an internal instance of vtkCellPicker that it uses to pick.
    - Keypress r: reset the camera view along the current view
    direction. Centers the actors and moves the camera so that all actors
    are visible.
    - Keypress s: modify the representation of all actors so that they
    are surfaces.
    - Keypress u: invoke the user-defined function. Typically, this
    keypress will bring up an interactor that you can type commands in.
    - Keypress w: modify the representation of all actors so that they
    are wireframe.
    """

    # Map between VTK and Qt cursors.
    _CURSOR_MAP = {
        0:  Qt.ArrowCursor,          # VTK_CURSOR_DEFAULT
        1:  Qt.ArrowCursor,          # VTK_CURSOR_ARROW
        2:  Qt.SizeBDiagCursor,      # VTK_CURSOR_SIZENE
        3:  Qt.SizeFDiagCursor,      # VTK_CURSOR_SIZENWSE
        4:  Qt.SizeBDiagCursor,      # VTK_CURSOR_SIZESW
        5:  Qt.SizeFDiagCursor,      # VTK_CURSOR_SIZESE
        6:  Qt.SizeVerCursor,        # VTK_CURSOR_SIZENS
        7:  Qt.SizeHorCursor,        # VTK_CURSOR_SIZEWE
        8:  Qt.SizeAllCursor,        # VTK_CURSOR_SIZEALL
        9:  Qt.PointingHandCursor,   # VTK_CURSOR_HAND
        10: Qt.CrossCursor,          # VTK_CURSOR_CROSSHAIR
    }

    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 "wflags" in kw:
            wflags = kw['wflags']
        else:
            wflags = Qt.WindowFlags()
        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 dispatchEvent(self, eventFunc):
        eventFunc()
    	#QTimer.singleShot(0, eventFunc)

    def __getattr__(self, attr):
        """Makes the object behave like a vtkGenericRenderWindowInteractor"""
        if attr == '__vtk__':
            return lambda t=self._Iren: t
        elif hasattr(self._Iren, attr):
            return getattr(self._Iren, attr)
        else:
            raise AttributeError(self.__class__.__name__ +
                  " has no attribute named " + attr)

    def Finalize(self):
        '''
        Call internal cleanup method on VTK objects
        '''
        self._RenderWindow.Finalize()

    def CreateTimer(self, obj, evt):
        self._Timer.start(10)

    def DestroyTimer(self, obj, evt):
        self._Timer.stop()
        return 1

    def TimerEvent(self):
        self.dispatchEvent(self._Iren.TimerEvent)

    def CursorChangedEvent(self, obj, evt):
        """Called when the CursorChangedEvent fires on the render window."""
        # This indirection is needed since when the event fires, the current
        # cursor is not yet set so we defer this by which time the current
        # cursor should have been set.
        QTimer.singleShot(0, self.ShowCursor)

    def HideCursor(self):
        """Hides the cursor."""
        self.setCursor(Qt.BlankCursor)

    def ShowCursor(self):
        """Shows the cursor."""
        vtk_cursor = self._Iren.GetRenderWindow().GetCurrentCursor()
        qt_cursor = self._CURSOR_MAP.get(vtk_cursor, Qt.ArrowCursor)
        self.setCursor(qt_cursor)

    def closeEvent(self, evt):
        self.Finalize()

    def sizeHint(self):
        return QSize(400, 400)

    def paintEngine(self):
        return None

    def paintEvent(self, ev):
        self._Iren.Render()

    def updateSize(self):
    	w, h = self.width(), self.height()
    	self._RenderWindow.SetSize(w, h)
    	self._Iren.SetSize(w, h)
    	self.update()

    def resizeEvent(self, ev):
    	self.dispatchEvent(self.updateSize)
        self.dispatchEvent(self._Iren.ConfigureEvent)

    def _GetCtrlShift(self, ev):
        ctrl = shift = False

        if hasattr(ev, 'modifiers'):
            if ev.modifiers() & Qt.ShiftModifier:
                shift = True
            if ev.modifiers() & Qt.ControlModifier:
                ctrl = True
        else:
            if self.__saveModifiers & Qt.ShiftModifier:
                shift = True
            if self.__saveModifiers & Qt.ControlModifier:
                ctrl = True

        return ctrl, shift

    def enterEvent(self, ev):
        ctrl, shift = self._GetCtrlShift(ev)
        self._Iren.SetEventInformationFlipY(self.__saveX, self.__saveY,
                                            ctrl, shift, chr(0), 0, None)
        self.dispatchEvent(self._Iren.EnterEvent)

    def leaveEvent(self, ev):
        ctrl, shift = self._GetCtrlShift(ev)
        self._Iren.SetEventInformationFlipY(self.__saveX, self.__saveY,
                                            ctrl, shift, chr(0), 0, None)
        self.dispatchEvent(self._Iren.LeaveEvent)

    def mousePressEvent(self, ev):
        ctrl, shift = self._GetCtrlShift(ev)
        repeat = 0
        if ev.type() == QEvent.MouseButtonDblClick:
            repeat = 1
        self._Iren.SetEventInformationFlipY(ev.x(), ev.y(),
                                            ctrl, shift, chr(0), repeat, None)

        self._ActiveButton = ev.button()

        if self._ActiveButton == Qt.LeftButton:
            self.dispatchEvent(self._Iren.LeftButtonPressEvent)
        elif self._ActiveButton == Qt.RightButton:
            self.dispatchEvent(self._Iren.RightButtonPressEvent)
        elif self._ActiveButton == Qt.MidButton:
            self.dispatchEvent(self._Iren.MiddleButtonPressEvent)

    def mouseReleaseEvent(self, ev):
        ctrl, shift = self._GetCtrlShift(ev)
        self._Iren.SetEventInformationFlipY(ev.x(), ev.y(),
                                            ctrl, shift, chr(0), 0, None)

        if self._ActiveButton == Qt.LeftButton:
            self.dispatchEvent(self._Iren.LeftButtonReleaseEvent)
        elif self._ActiveButton == Qt.RightButton:
            self.dispatchEvent(self._Iren.RightButtonReleaseEvent)
        elif self._ActiveButton == Qt.MidButton:
            self.dispatchEvent(self._Iren.MiddleButtonReleaseEvent)

    def mouseMoveEvent(self, ev):
        self.__saveModifiers = ev.modifiers()
        self.__saveButtons = ev.buttons()
        self.__saveX = ev.x()
        self.__saveY = ev.y()

        ctrl, shift = self._GetCtrlShift(ev)
        self._Iren.SetEventInformationFlipY(ev.x(), ev.y(),
                                            ctrl, shift, chr(0), 0, None)
        self.dispatchEvent(self._Iren.MouseMoveEvent)

    def keyPressEvent(self, ev):
        ctrl, shift = self._GetCtrlShift(ev)
        if ev.key() < 256:
            key = str(ev.text())
        else:
            key = chr(0)

        keySym = _qt_key_to_key_sym(ev.key())
        if shift and len(keySym) == 1 and keySym.isalpha():
            keySym = keySym.upper()

        self._Iren.SetEventInformationFlipY(self.__saveX, self.__saveY,
                                            ctrl, shift, key, 0, keySym)
        self.dispatchEvent(self._Iren.KeyPressEvent)
        self.dispatchEvent(self._Iren.CharEvent)

    def keyReleaseEvent(self, ev):
        ctrl, shift = self._GetCtrlShift(ev)
        if ev.key() < 256:
            key = chr(ev.key())
        else:
            key = chr(0)

        self._Iren.SetEventInformationFlipY(self.__saveX, self.__saveY,
                                            ctrl, shift, key, 0, None)
        self.dispatchEvent(self._Iren.KeyReleaseEvent)

    def wheelEvent(self, ev):
        if hasattr(ev, 'delta'):
            self.__wheelDelta += ev.delta()
        else:
            self.__wheelDelta += ev.angleDelta().y()

        if self.__wheelDelta >= 120:
            self.dispatchEvent(self._Iren.MouseWheelForwardEvent)
            self.__wheelDelta = 0
        elif self.__wheelDelta <= -120:
            self.dispatchEvent(self._Iren.MouseWheelBackwardEvent)
            self.__wheelDelta = 0

    def GetRenderWindow(self):
        return self._RenderWindow

    def Render(self):
        self.update()