def __init__(self, parent=None):
        QtOpenGL.QGLWidget.__init__(self, QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers), parent)

        self.list_ = []

        self.startTimer(40)
        self.setWindowTitle(self.tr("Sample Buffers"))
Exemple #2
0
 def __init__(self, parent=None):
     glformat = QtOpenGL.QGLFormat()
     glformat.setVersion(1, 1)
     glformat.setProfile(QtOpenGL.QGLFormat.CoreProfile)
     QtOpenGL.QGLWidget.__init__(self, glformat, parent)
     # Test we have a valid context
     ver = QtOpenGL.QGLFormat.openGLVersionFlags()
     if not ver & QtOpenGL.QGLFormat.OpenGL_Version_1_1:
         raise Exception("Requires OpenGL Version 1.1 or above.")
     # Default values
     self.setFocusPolicy(QtCore.Qt.ClickFocus)
     self._background_color = QtGui.QColor("silver")
     self._display_wireframe = False
     self._voxel_color = QtGui.QColor.fromHsvF(0, 1.0, 1.0)
     self._voxeledges = True
     # Mouse position
     self._mouse = QtCore.QPoint()
     self._mouse_absolute = QtCore.QPoint()
     self.mouse_delta_relative = (0, 0)
     self.mouse_delta_absolute = (0, 0)
     self.mouse_position = (0, 0)
     # Default camera
     self.reset_camera(False)
     # zoom
     import platform as p
     if p.system() == "Darwin":
         self._zoom_speed = 0.1
     else:
         self._zoom_speed = -0.1
     # Render axis grids?
     self._display_axis_grids = True
     # Our voxel scene
     self.voxels = voxel.VoxelData()
     # Grid manager
     self._grids = VoxelGrid(self.voxels)
     # create the default _grids
     self.grids.add_grid_plane(GridPlanes.X,
                               offset=0,
                               visible=True,
                               color=QtGui.QColor(0x6c, 0x7d, 0x67))
     self.grids.add_grid_plane(GridPlanes.Y,
                               offset=0,
                               visible=True,
                               color=QtGui.QColor(0x65, 0x65, 0x7b))
     self.grids.add_grid_plane(GridPlanes.Z,
                               offset=self.voxels.depth,
                               visible=True,
                               color=QtGui.QColor(0x7b, 0x65, 0x68))
     # Used to track the z component of various mouse activity
     self._depth_focus = 1
     # Keep track how long mouse buttons are down for
     self._mousedown_time = 0
     self.button_down = None
     self._dragging = False
     self._rotating = False
     self._key_modifiers = 0
     self._keystate = set()
     self.ready = False
Exemple #3
0
 def opengl_set_version(self, version):
     major, minor = version
     gl_format = QtOpenGL.QGLFormat()
     gl_format.setVersion(major, minor)
     gl_format.setProfile(QtOpenGL.QGLFormat.CoreProfile)
     gl_format.setSampleBuffers(True)
     # gl_format.setDefaultFormat(gl_format)
     self.view.context().setFormat(gl_format)
     self.view.context().create()
     self.view.glInit()
Exemple #4
0
def main():
    import sys

    app = QtGui.QApplication(sys.argv)

    glformat = QtOpenGL.QGLFormat()
    glformat.setVersion(3, 3)
    glformat.setProfile(QtOpenGL.QGLFormat.CoreProfile)
    w = MyWidget(glformat)
    w.resize(640, 480)
    w.show()
    sys.exit(app.exec_())
Exemple #5
0
def set_configuration(config):
    global __glformat__

    # WARNING: does not work on osx
    # http://stackoverflow.com/questions/...
    # ...7868882/enabling-opengl-core-profile-in-qt4-on-os-x

    __glformat__ = QtOpenGL.QGLFormat()
    __glformat__.setRedBufferSize(config.red_size)
    __glformat__.setGreenBufferSize(config.green_size)
    __glformat__.setBlueBufferSize(config.blue_size)
    __glformat__.setAlphaBufferSize(config.alpha_size)
    __glformat__.setAccum(False)
    __glformat__.setRgba(True)

    if config.double_buffer:
        __glformat__.setDoubleBuffer(True)
    else:
        __glformat__.setDoubleBuffer(False)

    if config.depth_size:
        __glformat__.setDepth(True)
        __glformat__.setDepthBufferSize(config.depth_size)
    else:
        __glformat__.setDepth(False)
        __glformat__.setDepthBufferSize(0)

    if config.stencil_size:
        __glformat__.setStencil(True)
        __glformat__.setStencilBufferSize(config.stencil_size)
    else:
        __glformat__.setStencil(False)
        __glformat__.setStencilBufferSize(0)

    if config.samples:
        __glformat__.setSampleBuffers(True)
        __glformat__.setSamples(config.samples)
    else:
        __glformat__.setSampleBuffers(False)
        __glformat__.setSamples(0)
    __glformat__.setStereo(config.stereo)

    __glformat__.setVersion(config.major_version, config.minor_version)
    if config.major_version >= 3 and config.profile == "core":
        __glformat__.setProfile(__glformat__.CoreProfile)
    elif config.major_version >= 3 and config.profile == "compatibility":
        __glformat__.setProfile(__glformat__.CompatibilityProfile)
    else:
        __glformat__.setProfile(__glformat__.NoProfile)
Exemple #6
0
def _SetupOpenGLContext(width=100, height=100):
    try:
        from PySide2 import QtOpenGL
        from PySide2.QtWidgets import QApplication
    except ImportError:
        from PySide import QtOpenGL
        from PySide.QtGui import QApplication

    application = QApplication(sys.argv)

    glFormat = QtOpenGL.QGLFormat()
    glFormat.setSampleBuffers(True)
    glFormat.setSamples(4)

    glWidget = QtOpenGL.QGLWidget(glFormat)
    glWidget.setFixedSize(width, height)
    glWidget.show()
    glWidget.setHidden(True)

    return glWidget
Exemple #7
0
    def __init__(self, parent):
        super(View, self).__init__(parent)
        self.setRenderHint(QtGui.QPainter.Antialiasing)
        self._manipulationMode = 0

        gl_format = QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers)
        gl_format.setSamples(10)
        gl_widget = QtOpenGL.QGLWidget(gl_format)

        self._pan = False
        self._panStartX = 0
        self._panStartY = 0
        self._numScheduledScalings = 0
        self.lastMousePos = QtCore.QPoint()

        self.setViewport(gl_widget)

        self.setTransformationAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)
        self.setResizeAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setFrameShape(QtWidgets.QFrame.NoFrame)
Exemple #8
0
def _SetupOpenGLContext(width=100, height=100):
    try:
        from PySide2 import QtOpenGL
        from PySide2.QtWidgets import QApplication
    except ImportError:
        from PySide import QtOpenGL
        from PySide.QtGui import QApplication

    application = QApplication(sys.argv)

    glFormat = QtOpenGL.QGLFormat()
    glFormat.setSampleBuffers(True)
    glFormat.setSamples(4)

    glWidget = QtOpenGL.QGLWidget(glFormat)
    glWidget.setFixedSize(width, height)
    # note that we need to bind the gl context here, instead of explicitly
    # showing the glWidget. Binding the gl context will make sure framebuffer is
    # ready for gl operations.
    glWidget.makeCurrent()

    return glWidget
Exemple #9
0
    def setRenderingSystem(self):
        if Colors.direct3dRendering:
            viewport.setAttribute(QtCore.Qt.WA_MSWindowsUseDirect3D)
            self.setCacheMode(QtGui.QGraphicsView.CacheNone)
            Colors.debug("- using Direct3D")
        elif Colors.openGlRendering:
            from PySide2 import QtOpenGL

            viewport = QtOpenGL.QGLWidget(
                QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers))

            if Colors.noScreenSync:
                viewport.format().setSwapInterval(0)

            viewport.setAutoFillBackground(False)
            self.setCacheMode(QtGui.QGraphicsView.CacheNone)
            Colors.debug("- using OpenGL")
        else:
            viewport = QtGui.QWidget()
            self.setCacheMode(QtGui.QGraphicsView.CacheBackground)
            Colors.debug("- using software rendering")

        self.setViewport(viewport)
Exemple #10
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        # Specify OpenGL context parameters
        gl = QtOpenGL.QGLFormat()
        gl.setVersion(self.gl_version[0], self.gl_version[1])
        gl.setProfile(QtOpenGL.QGLFormat.CoreProfile)
        gl.setDepthBufferSize(24)
        gl.setDoubleBuffer(True)
        gl.setSwapInterval(1 if self.vsync else 0)

        # Configure multisampling if needed
        if self.samples > 1:
            gl.setSampleBuffers(True)
            gl.setSamples(self.samples)

        # We need an application object, but we are bypassing the library's
        # internal event loop to avoid unnecessary work
        self._app = QtWidgets.QApplication([])

        # Create the OpenGL widget
        self._widget = QtOpenGL.QGLWidget(gl)
        self.title = self._title

        # If fullscreen we change the window to match the desktop on the primary screen
        if self.fullscreen:
            rect = QtWidgets.QDesktopWidget().screenGeometry()
            self._width = rect.width()
            self._height = rect.height()
            self._buffer_width = rect.width() * self._widget.devicePixelRatio()
            self._buffer_height = rect.height(
            ) * self._widget.devicePixelRatio()

        if self.resizable:
            # Ensure a valid resize policy when window is resizable
            size_policy = QtWidgets.QSizePolicy(
                QtWidgets.QSizePolicy.Expanding,
                QtWidgets.QSizePolicy.Expanding,
            )
            self._widget.setSizePolicy(size_policy)
            self._widget.resize(self.width, self.height)
        else:
            self._widget.setFixedSize(self.width, self.height)

        # Center the window on the screen if in window mode
        if not self.fullscreen:
            self._widget.move(QtWidgets.QDesktopWidget().rect().center() -
                              self._widget.rect().center())

        # Needs to be set before show()
        self._widget.resizeGL = self.resize

        self.cursor = self._cursor

        if self.fullscreen:
            self._widget.showFullScreen()
        else:
            self._widget.show()

        # We want mouse position events
        self._widget.setMouseTracking(True)

        # Override event functions in qt
        self._widget.keyPressEvent = self.key_pressed_event
        self._widget.keyReleaseEvent = self.key_release_event
        self._widget.mouseMoveEvent = self.mouse_move_event
        self._widget.mousePressEvent = self.mouse_press_event
        self._widget.mouseReleaseEvent = self.mouse_release_event
        self._widget.wheelEvent = self.mouse_wheel_event
        self._widget.closeEvent = self.close_event
        self._widget.showEvent = self.show_event
        self._widget.hideEvent = self.hide_event

        # Attach to the context
        self.init_mgl_context()

        # Ensure retina and 4k displays get the right viewport
        self._buffer_width = self._width * self._widget.devicePixelRatio()
        self._buffer_height = self._height * self._widget.devicePixelRatio()

        self.set_default_viewport()
    def __init__(self, width, height):
        super(Panel, self).__init__()

        self.selectedX = 0
        self.selectedY = 0
        self.width = width
        self.height = height
        self.flipped = False
        self.flipLeft = True

        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setCacheMode(QtGui.QGraphicsView.CacheBackground)
        self.setViewportUpdateMode(QtGui.QGraphicsView.FullViewportUpdate)
        self.setRenderHints(QtGui.QPainter.Antialiasing
                            | QtGui.QPainter.SmoothPixmapTransform
                            | QtGui.QPainter.TextAntialiasing)

        self.setBackgroundBrush(
            QtGui.QBrush(QtGui.QPixmap('./images/blue_angle_swirl.jpg')))

        if QtOpenGL.QGLFormat.hasOpenGL():
            self.setViewport(
                QtOpenGL.QGLWidget(
                    QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers)))

        self.setMinimumSize(50, 50)

        self.selectionTimeLine = QtCore.QTimeLine(150, self)
        self.flipTimeLine = QtCore.QTimeLine(500, self)
        bounds = QtCore.QRectF((-width / 2.0) * 150, (-height / 2.0) * 150,
                               width * 150, height * 150)

        self.scene = QtGui.QGraphicsScene(bounds, self)
        self.setScene(self.scene)

        self.baseItem = RoundRectItem(bounds, QtGui.QColor(226, 255, 92, 64))
        self.scene.addItem(self.baseItem)

        embed = QtGui.QWidget()

        self.ui = Ui_BackSide()
        self.ui.setupUi(embed)
        self.ui.hostName.setFocus()

        self.backItem = RoundRectItem(bounds, embed.palette().window(), embed)
        self.backItem.setTransform(QtGui.QTransform().rotate(
            180, QtCore.Qt.YAxis))
        self.backItem.setParentItem(self.baseItem)

        self.selectionItem = RoundRectItem(QtCore.QRectF(-60, -60, 120, 120),
                                           QtCore.Qt.gray)
        self.selectionItem.setParentItem(self.baseItem)
        self.selectionItem.setZValue(-1)
        self.selectionItem.setPos(self.posForLocation(0, 0))
        self.startPos = self.selectionItem.pos()
        self.endPos = QtCore.QPointF()

        self.grid = []

        for y in range(height):
            self.grid.append([])
            for x in range(width):
                item = RoundRectItem(QtCore.QRectF(-54, -54, 108, 108),
                                     QtGui.QColor(214, 240, 110, 128))
                item.setPos(self.posForLocation(x, y))

                item.setParentItem(self.baseItem)
                item.setFlag(QtGui.QGraphicsItem.ItemIsFocusable)
                self.grid[y].append(item)

                rand = QtCore.qrand() % 9
                if rand == 0:
                    item.setPixmap(
                        QtGui.QPixmap(':/images/kontact_contacts.png'))
                elif rand == 1:
                    item.setPixmap(
                        QtGui.QPixmap(':/images/kontact_journal.png'))
                elif rand == 2:
                    item.setPixmap(QtGui.QPixmap(':/images/kontact_notes.png'))
                elif rand == 3:
                    item.setPixmap(
                        QtGui.QPixmap(':/images/kopeteavailable.png'))
                elif rand == 4:
                    item.setPixmap(
                        QtGui.QPixmap(':/images/metacontact_online.png'))
                elif rand == 5:
                    item.setPixmap(QtGui.QPixmap(':/images/minitools.png'))
                elif rand == 6:
                    item.setPixmap(
                        QtGui.QPixmap(':/images/kontact_journal.png'))
                elif rand == 7:
                    item.setPixmap(
                        QtGui.QPixmap(':/images/kontact_contacts.png'))
                elif rand == 8:
                    item.setPixmap(
                        QtGui.QPixmap(':/images/kopeteavailable.png'))
                else:
                    pass

                item.qobject.activated.connect(self.flip)

        self.grid[0][0].setFocus()

        self.backItem.qobject.activated.connect(self.flip)
        self.selectionTimeLine.valueChanged.connect(self.updateSelectionStep)
        self.flipTimeLine.valueChanged.connect(self.updateFlipStep)

        self.splash = SplashItem()
        self.splash.setZValue(5)
        self.splash.setPos(-self.splash.rect().width() / 2,
                           self.scene.sceneRect().top())
        self.scene.addItem(self.splash)

        self.splash.grabKeyboard()

        self.updateSelectionStep(0)

        self.setWindowTitle("Pad Navigator Example")
Exemple #12
0
            self.image_plane.update_ocio_proc(display=display,
                                              view=self.view())

    @QtCore.Slot(str)
    def _on_view_changed(self, view):
        self.image_plane.update_ocio_proc(view=view)

    @QtCore.Slot(float)
    def _on_exposure_changed(self, value):
        self.image_plane.update_exposure(value)

    @QtCore.Slot(float)
    def _on_gamma_changed(self, value):
        self.image_plane.update_gamma(value)


if __name__ == "__main__":
    # OpenGL core profile needed on macOS to access programmatic pipeline
    gl_format = QtOpenGL.QGLFormat()
    gl_format.setProfile(QtOpenGL.QGLFormat.CoreProfile)
    gl_format.setSampleBuffers(True)
    gl_format.setSwapInterval(1)
    gl_format.setVersion(4, 0)
    QtOpenGL.QGLFormat.setDefaultFormat(gl_format)

    app = QtWidgets.QApplication(sys.argv)
    viewer = ImageView()
    viewer.show()
    app.exec_()