Ejemplo n.º 1
0
 def testIOr(self):
     '''QFlags |= (ior) operator'''
     flag = Qt.WindowFlags()
     self.assertTrue(Qt.Widget == 0)
     self.assertFalse(flag & Qt.Widget)
     result = flag & Qt.Widget
     self.assertTrue(result == 0)
     flag |= Qt.WindowMinimizeButtonHint
     self.assertTrue(flag & Qt.WindowMinimizeButtonHint)
Ejemplo n.º 2
0
    def __init__(self,
                 iconDirectory,
                 widgetToFocus,
                 parent=None,
                 flags=Qt.WindowFlags()):
        """
        TOWRITE

        :param `iconDirectory`: TOWRITE
        :type `iconDirectory`: QString
        :param `widgetToFocus`: TOWRITE
        :type `widgetToFocus`: QWidget
        :param `parent`: TOWRITE
        :type `parent`: QWidget
        :param `flags`: TOWRITE
        :type `flags`: Qt.WindowFlags
        """
        super(UndoEditor, self).__init__(parent, flags)

        self.iconDir = iconDirectory
        self.iconSize = 16
        self.setMinimumSize(100, 100)

        self.undoGroup = QUndoGroup(self)
        self.undoView = QUndoView(self.undoGroup, self)
        self.undoView.setEmptyLabel(self.tr("New"))
        self.undoView.setCleanIcon(
            QIcon(self.iconDir + os.sep + "new.png")
        )  # TODO: new.png for new drawings, open.png for opened drawings, save.png for saved/cleared drawings?

        self.setWidget(self.undoView)
        self.setWindowTitle(self.tr("History"))
        self.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)

        self.setFocusProxy(widgetToFocus)
        self.undoView.setFocusProxy(widgetToFocus)
Ejemplo n.º 3
0
    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)