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
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()
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
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)
def makeSharedGLWidget(*args, **option): sharedWidget = None fmt = QtOpenGL.QGLFormat.defaultFormat() sharedWidget = getSharedGLWidget() return QtOpenGL.QGLWidget(fmt, None, sharedWidget)