Example #1
0
    def __init__(self, parent=None):
        if hasattr(QtOpenGL.QGLFormat, 'setVersion'):
            f = QtOpenGL.QGLFormat();
            f.setVersion(3, 2)
            f.setProfile(QtOpenGL.QGLFormat.CoreProfile)
            c = QtOpenGL.QGLContext(f)
            QtOpenGL.QGLWidget.__init__(self, c, parent)
        else:
            QtOpenGL.QGLWidget.__init__(self, parent)

        self.viewState = ViewState(self.width(), self.height())

        self.viewState.changed.connect(self.update)

        # Nav Handling
        self.move_dragging = False
        self.move_dragged = False
        self.mwemu = False
        self.lastPoint = None

        self.interactionDelegate = None
        self.setMouseTracking(True)

        self.selectionList = set()

        self.open_time = time.time()

        # OpenGL shared resources object. Initialized during initializeGL
        self.gls = GLShared()
Example #2
0
    def getSharedWidget():
        if not GLWidget.sharedWidget:
            fmt = QtOpenGL.QGLFormat()
            fmt.setRgba(True)
            fmt.setAlpha(True)
            fmt.setDepth(True)
            fmt.setDoubleBuffer(True)
            fmt.setSampleBuffers(True)
            fmt.setSwapInterval(0)
            QtOpenGL.QGLFormat.setDefaultFormat(fmt)

            hiddenWindow = QtOpenGL.QGLWidget(QtOpenGL.QGLContext(fmt))
            GLWidget.sharedWidget = hiddenWindow
            hiddenWindow.makeCurrent()

        return GLWidget.sharedWidget
Example #3
0
    def setUp(self):

        if self.ctx is None:
            f = QtOpenGL.QGLFormat()
            f.setVersion(3, 2)
            f.setProfile(QtOpenGL.QGLFormat.CoreProfile)

            self.ctx = QtOpenGL.QGLContext(f)
            self.mockWidget = QtOpenGL.QGLWidget(self.ctx)

        self.assertTrue(self.ctx.isValid())
        self.ctx.makeCurrent()

        # Compile the two shaders individually
        s1 = S.compileShader(VERT_1, GL.GL_VERTEX_SHADER)
        s2 = S.compileShader(FRAG_1, GL.GL_FRAGMENT_SHADER)

        # now build the whole program
        self.prog = S.compileProgram(s1, s2)
Example #4
0
 def __init__(self):
     f = QtOpenGL.QGLFormat()
     f.setVersion(3, 3)
     f.setProfile(QtOpenGL.QGLFormat.CoreProfile)
     c = QtOpenGL.QGLContext(f)
     QtOpenGL.QGLWidget.__init__(self, c)
Example #5
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 = QtGui.QApplication.instance()
        if self._native_app is None:
            self._native_app = QtGui.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)