コード例 #1
0
    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"))
コード例 #2
0
    def useOpenGL(self, b=True):
        if b:
            from PySide2 import QtOpenGL
            v = QtOpenGL.QGLWidget()
        else:
            v = QtWidgets.QWidget()

        self.setViewport(v)
コード例 #3
0
ファイル: voxel_widget.py プロジェクト: lriecken/zoxel
 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
コード例 #4
0
ファイル: controller.py プロジェクト: jf---/compas_viewers
 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()
コード例 #5
0
ファイル: usdrecord.py プロジェクト: zloop1982/USD
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
コード例 #6
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_())
コード例 #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)
コード例 #8
0
ファイル: usdrecord.py プロジェクト: mattyjams/USD
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
コード例 #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)
コード例 #10
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)
コード例 #11
0
    def detectSystemResources(cls):
        try:
            from PySide2 import QtOpenGL
            cls.openGlAvailable = True
        except ImportError:
            cls.openGlAvailable = False

        if cls.openGlAvailable:
            version_flags = QtOpenGL.QGLFormat.openGLVersionFlags()

            if version_flags & QtOpenGL.QGLFormat.OpenGL_Version_2_0:
                cls.glVersion = "2.0 or higher"
            elif version_flags & QtOpenGL.QGLFormat.OpenGL_Version_1_5:
                cls.glVersion = "1.5"
            elif version_flags & QtOpenGL.QGLFormat.OpenGL_Version_1_4:
                cls.glVersion = "1.4"
            elif version_flags & QtOpenGL.QGLFormat.OpenGL_Version_1_3:
                cls.glVersion = "1.3 or lower"

            cls.debug("- OpenGL version:", cls.glVersion)

            glw = QtOpenGL.QGLWidget()

            if (not QtOpenGL.QGLFormat.hasOpenGL()
                    or not glw.format().directRendering() or
                    not (version_flags & QtOpenGL.QGLFormat.OpenGL_Version_1_5)
                    or glw.depth() < 24):
                cls.openGlAdequate = False
                cls.debug("- OpenGL not recommended on this system")
        else:
            cls.openGlAdequate = False
            cls.debug("- OpenGL not supported by current build of Qt")

        if sys.platform == 'win32':
            # For now.
            cls.direct3dAvailable = False

        # Check if X Render is present.
        if hasattr(QtGui.QPixmap, 'x11PictureHandle'):
            tmp = QtGui.QPixmap(1, 1)

            if not tmp.x11PictureHandle():
                cls.xRenderPresent = False
                cls.debug("- X render not present")

        w = QtGui.QWidget()
        cls.debug("- Color depth: %d" % w.depth())
コード例 #12
0
    def __init__(self, filepath, parent=None):
        '''
        This is the constructor for the main widget
        '''
        super(GraphicsWidget, self).__init__(parent)

        # create the layout.
        mainLayout = QtWidgets.QVBoxLayout()

        self.setMinimumSize(350, 350)
        self.resize(800, 800)
        self.scene = graphicsWidgets.GraphicsScene()
        self.view = graphicsWidgets.GraphicsView()
        self.view.setScene(self.scene)
        self.scene.setSceneRect(0, 0, 10000, 10000)
        self.view.setViewport(QtOpenGL.QGLWidget())
        mainLayout.addWidget(self.view)
        self.setLayout(mainLayout)
        pickerData = picker_data.PickerData(self.scene)
        pickerData.read(filepath)
        pickerData.applyData(pickerData.getData().keys())
        self.view.fitInView(self.scene.itemsBoundingRect(),
                            QtCore.Qt.KeepAspectRatio)
コード例 #13
0
ファイル: window.py プロジェクト: aforren1/moderngl_window
    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()
コード例 #14
0
    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")
コード例 #15
0
    def __init__( self, width=256, height=256, title=None, visible=True, aspect=None,
                  decoration=True, fullscreen=False, config=None, context=None, color=(0,0,0,1), vsync=False):

        window.Window.__init__(self, width=width,
                                     height=height,
                                     title=title,
                                     visible=visible,
                                     aspect=aspect,
                                     decoration=decoration,
                                     fullscreen=fullscreen,
                                     config=config,
                                     context=context,
                                     color=color)

        if config is None:
            config = configuration.Configuration()
        set_configuration(config)

        __glformat__.setSwapInterval(1 if vsync else 0)

        self._native_app = QtWidgets.QApplication.instance()
        if self._native_app is None:
            self._native_app = QtWidgets.QApplication(sys.argv)

        context = QtOpenGL.QGLContext(__glformat__)
        if context.isValid():
            self._native_window = QtOpenGL.QGLWidget(context)
        else:
            self._native_window = QtOpenGL.QGLWidget(__glformat__)

        self._native_window.resize(width, height)
        self._native_window.makeCurrent()
        self._native_window.setAutoBufferSwap(False)
        self._native_window.setMouseTracking(True)
        self._native_window.setWindowTitle(self._title)
        #self._native_window.show()

        def paint_gl():
            self.dispatch_event("on_draw", 0.0)
        self._native_window.paintGL = paint_gl

        def resize_gl(width, height):
            self.dispatch_event("on_resize", width, height)
        self._native_window.resizeGL = resize_gl

        def close_event(event):
            __windows__.remove(self)
            for i in range(len(self._timer_stack)):
                handler, interval = self._timer_stack[i]
                self._clock.unschedule(handler)
            self.dispatch_event("on_close")
        self._native_window.closeEvent = close_event

        def mouse_press_event(event):
            x = event.pos().x()
            y = event.pos().y()
            button = __mouse_map__.get(event.button(), window.mouse.UNKNOWN)
            self._button = button
            self._mouse_x = x
            self._mouse_y = y
            self.dispatch_event("on_mouse_press", x, y, button)
        self._native_window.mousePressEvent = mouse_press_event

        def mouse_release_event(event):
            x = event.pos().x()
            y = event.pos().y()
            button = __mouse_map__.get(event.button(), window.mouse.UNKNOWN)
            self._button = window.mouse.NONE
            self._mouse_x = x
            self._mouse_y = y
            self.dispatch_event("on_mouse_release", x, y, button)
        self._native_window.mouseReleaseEvent = mouse_release_event

        def mouse_move_event(event):
            x = event.pos().x()
            y = event.pos().y()
            dx = x - self._mouse_x
            dy = y - self._mouse_y
            self._mouse_x = x
            self._mouse_y = y
            if self._button is not window.mouse.NONE:
                self.dispatch_event('on_mouse_drag', x, y, dx, dy, self._button)
            else:
                self.dispatch_event('on_mouse_motion', x, y, dx, dy)
        self._native_window.mouseMoveEvent = mouse_move_event

        def wheel_event(event):
            if event.orientation == QtCore.Qt.Horizontal:
                offset_x = event.delta()
                offset_y = 0
            else:
                offset_x = 0
                offset_y = event.delta()
            x = event.pos().x()
            y = event.pos().y()
            self.dispatch_event("on_mouse_scroll", x, y, offset_x/10.0, offset_y/10.0)
        self._native_window.wheelEvent = wheel_event

        def key_press_event(event):
            code = self._keyboard_translate(event.key())
            modifiers = self._modifiers_translate(event.modifiers())
            self.dispatch_event("on_key_press", code, modifiers)
            self.dispatch_event("on_character", event.text())
        self._native_window.keyPressEvent = key_press_event

        def key_release_event(event):
            code = self._keyboard_translate(event.key())
            modifiers = self._modifiers_translate(event.modifiers())
            self.dispatch_event("on_key_release", code, modifiers)
        self._native_window.keyReleaseEvent = key_release_event

        __windows__.append(self)
コード例 #16
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_()