Пример #1
0
 def makeGLWidget(*args, **option):
     fmt = QtOpenGL.QGLFormat()
     fmt.setRgba(True)
     fmt.setDepth(False)
     fmt.setDoubleBuffer(True)
     fmt.setSwapInterval(0)
     fmt.setSampleBuffers(True)
     viewport = QtOpenGL.QGLWidget(fmt)
     return viewport
Пример #2
0
    def __init__(self, parent=None, init_channel=None):
        super(NTImage, self).__init__(parent=parent, init_channel=init_channel)

        self.setLayout(QtWidgets.QVBoxLayout())
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.layout().setSpacing(0)
        self.scene = QtWidgets.QGraphicsScene(self)
        self.scene.setBackgroundBrush(QtGui.QColor("black"))

        self.pixmap_image = QtWidgets.QGraphicsPixmapItem()
        self.scene.addItem(self.pixmap_image)

        self.view = QtWidgets.QGraphicsView(self)
        self.view.setViewport(QtOpenGL.QGLWidget(QtOpenGL.QGLFormat()))
        self.view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.view.viewport().setContentsMargins(0, 0, 0, 0)
        self.view.setContentsMargins(0, 0, 0, 0)
        size_policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                            QtWidgets.QSizePolicy.Preferred)
        size_policy.setHeightForWidth(True)
        self.view.setSizePolicy(size_policy)

        self.view.setScene(self.scene)

        self.layout().addWidget(self.view)

        # Make a right-click menu for changing the color map.
        self.cm_group = QtWidgets.QActionGroup(self)
        self.cmap_for_action = {}
        for cm in self.color_maps:
            action = self.cm_group.addAction(cmap_names[cm])
            action.setCheckable(True)
            self.cmap_for_action[action] = cm

        self.thread = None
        self._colormap = None
        self._data = None
        self._image = None

        # Setup the redraw timer.
        self._needs_redraw = False
        self._make_colormap(cmaps[PyDMColorMap.Monochrome])
        self._redraw_timer = QtCore.QTimer()
        self._redraw_timer.timeout.connect(self._redraw)
        self._redraw_rate = 30
        self.maxRedrawRate = self._redraw_rate
        self._redraw_timer.start()
Пример #3
0
    def __init__(self,shared=None, rendering_parameters=None, *args, **kwargs):
        f = QtOpenGL.QGLFormat()
        f.setVersion(3,2)
        f.setSamples(8)
        # f.setProfile(QtOpenGL.QGLFormat.CompatibilityProfile)
        f.setProfile(QtOpenGL.QGLFormat.CoreProfile)
        if _debug:
            f.setOption(QtGui.QSurfaceFormat.DebugContext)
        QtOpenGL.QGLFormat.setDefaultFormat(f)
        super().__init__(shareWidget=shared, *args, **kwargs)
        if shared is None:
            self.context().setFormat(f)
            self.context().create()
        self.scenes = []
        self._rotation_enabled = True
        self.do_rotate = False
        self.do_translate = False
        self.do_zoom = False
        self.do_move_clippingplane = False
        self.do_rotate_clippingplane = False
        self.old_time = time.time()

        self.redraw_update_done = QtCore.QWaitCondition()
        self.redraw_mutex = QtCore.QMutex()

        self._settings = scenes.RenderingSettings(name="Global settings") 
        self._settings.interpolationChanged.connect(self.updateScenes)

        self.lastPos = QtCore.QPoint()
        self.lastFastmode = self._settings.fastmode
Пример #4
0
    def __init__(self, parent: Optional[QtWidgets.QWidget] = None) -> None:
        super(BaseViewWidget, self).__init__(parent)
        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.__gl_initialized = False

        self.viewState = ViewPort(self.width(), self.height())
        self.viewState.changed.connect(self.update)

        self.lastPoint = QtCore.QPoint(0, 0)
        # Nav Handling
        self.active_drag = None

        self.mouse_wheel_emu = None

        self.action_log_cb: 'Optional[Callable[[VarArg(Any)], None]]' = None
        self.interactionDelegate = None
        self.setMouseTracking(True)

        # TODO refine type
        self.selectionList: Set[Any] = set()

        self.open_time = time.time()

        # OpenGL shared resources object. Initialized during initializeGL
        self.gls = GLShared()

        #
        self.local_actions_map = {
            (EventID.Mouse_B2_DragStart, Modifier(0)): EVT_START_FIELD_DRAG,
            (EventID.Mouse_B2, Modifier(0)): EVT_STOP_FIELD_DRAG,
        }

        self.id_actions_map = {}
        self.notify_changed_actions = []
Пример #5
0
    def setUp(self):
        # Ensure we have a qapplication - another testcase might have created it though
        try:
            app = QtWidgets.QApplication([])
        except RuntimeError:
            pass

        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)
Пример #6
0
def probe() -> Union[Tuple[int, int], None]:
    w = QtOpenGL.QGLWidget()
    w.makeCurrent()

    vers = GL.glGetString(GL.GL_VERSION).decode("ascii")
    v_match = re.match(r"^(\d+(\.\d+)+)\s", vers)

    # If we can't parse the vers string, who knows what version we have
    if not v_match:
        return None

    g = v_match.group(1).split(".")
    v1 = int(g[0])
    v2 = int(g[1])

    return v1, v2
Пример #7
0
 def __init__(self) -> None:
     f = QtOpenGL.QGLFormat()
     f.setVersion(3, 3)
     f.setProfile(QtOpenGL.QGLFormat.CoreProfile)
     c = QtOpenGL.QGLContext(f)
     QtOpenGL.QGLWidget.__init__(self, c)
Пример #8
0
 def makeSharedGLWidget(*args, **option):
     sharedWidget = None
     fmt = QtOpenGL.QGLFormat.defaultFormat()
     sharedWidget = getSharedGLWidget()
     return QtOpenGL.QGLWidget(fmt, None, sharedWidget)