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()
def __init__(self, *args, **kwargs): super(DisplayWidget, self).__init__(*args, **kwargs) # We draw to an OpenGL scene, so instantiate # the QGLWidget. gl_format = QtOpenGL.QGLFormat() gl_format.setSampleBuffers(True) gl_format.setDepth(False) self.gl_widget = QtOpenGL.QGLWidget(gl_format) # Set up the view self.view = GraphicsView() self.view.setParent(self) self.view.setViewport(self.gl_widget) self.view.setViewportUpdateMode(QGraphicsView.FullViewportUpdate) # Set up the scene self.scene = OpenGLScene() self.scene.setParent(self) self.overlay_widget = OverlayWidget() self.scene.addWidget(self.overlay_widget) self.overlay_widget.move(QtCore.QPoint(0, 0)) # Assign in the scene to the view. self.view.setScene(self.scene)
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"))
def __init__(self, parent=None): """Initializes widgets of scene graph editor""" QtGui.QWidget.__init__(self, parent) self._root = iv.Separator() self._filePath = "" self.inspectorWidget = QInspectorWidget() self.previewWidget = QIVWidget( format=QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers)) self.previewWidget.sceneManager.background = ((0.7, 0.7, 0.8), (0.0, 0.1, 0.3)) mainLayout = QtGui.QVBoxLayout() mainLayout.setContentsMargins(2, 2, 0, 0) mainLayout.setSpacing(0) self._horiSplitter = QtGui.QSplitter(QtCore.Qt.Horizontal) self._horiSplitter.addWidget(self.inspectorWidget) self._horiSplitter.addWidget(self.previewWidget) self._vertSplitter = QtGui.QSplitter(QtCore.Qt.Vertical) self._vertSplitter.addWidget(self._horiSplitter) mainLayout.addWidget(self._vertSplitter) self.setLayout(mainLayout) self.setWindowTitle(self.applicationTitle()) self.inspectorWidget.attach(self.previewWidget.sceneManager.scene) # timer for inventor queue processing (delay, timer and idle queues) self.idleTimer = QtCore.QTimer() self.idleTimer.timeout.connect(iv.process_queues) self.idleTimer.start()
def __init__(self, path, parent): QtOpenGL.QGLWidget.__init__( self, QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers)) self.doc = QtSvg.QSvgRenderer(path, self) self.connect(self.doc, QtCore.SIGNAL("repaintNeeded()"), self, QtCore.SLOT("update()"))
def main(argv): app = QApplication(argv) gl_format = QtOpenGL.QGLFormat() gl_format.setSampleBuffers(True) gl_widget = QtOpenGL.QGLWidget(gl_format) view = GraphicsView() view.setViewport(gl_widget) view.setViewportUpdateMode(QGraphicsView.FullViewportUpdate) scene = OpenGLScene(gl_widget.context()) overlay_widget = OverlayWidget() scene.addWidget(overlay_widget) overlay_widget.change_signal.connect(scene.sliders_changed) scene.rotation_changed.connect(overlay_widget.rotation_changed) overlay_widget.move(QtCore.QPoint(0, 0)) overlay_widget.setAttribute(QtCore.Qt.WA_TranslucentBackground) view.setScene(scene) print view.children() view.show() view.resize(1024, 768) scene.model.setXRotation(45 * 16) sys.exit(app.exec_())
def __init__(self, figure, parent, *args): # Create opengl format glFormat = QtOpenGL.QGLFormat() #glFormat.setSampleBuffers(True) #glFormat.setSamples(4) # QtOpenGL.QGLWidget.__init__(self, glFormat, parent, *args) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) # keep cleaned up self.figure = figure # Note that the default QGLFormat has double buffering enabled. # Set icon try: iconFile = os.path.join(getResourceDir(), 'visvis_icon_%s.png' % qtlib) icon = QtGui.QIcon() icon.addFile(iconFile, QtCore.QSize(16, 16)) self.setWindowIcon(icon) except Exception: pass # enable mouse tracking so mousemove events are always fired. self.setMouseTracking(True) # enable getting keyboard focus self.setFocusPolicy(QtCore.Qt.StrongFocus) self.setFocus() # make the widget have focus...
def __init__(self, parent=None): resizable.GraphicsView.__init__(self, parent) cegui.GLContextProvider.__init__(self) # mainly to tone down potential antialiasing self.glFormat = QtOpenGL.QGLFormat() self.glFormat.setSampleBuffers(True) self.glFormat.setSamples(2) self.setViewport(QtOpenGL.QGLWidget(self.glFormat)) # OpenGL doesn't do partial redraws (it isn't practical anyways) self.setViewportUpdateMode(QtGui.QGraphicsView.FullViewportUpdate) # make things slightly faster self.setOptimizationFlags( QtGui.QGraphicsView.DontClipPainter | QtGui.QGraphicsView.DontAdjustForAntialiasing) self.injectInput = False # we might want mouse events self.setMouseTracking(True) # we might want key events self.setFocusPolicy(QtCore.Qt.ClickFocus) # if True, we render always (possibly capped to some FPS) - suitable for live preview # if False, we render only when update() is called - suitable for visual editing self.continuousRendering = True # only applies when we are rendering continuously, it's the max FPS that we will try to achieve self.continuousRenderingTargetFPS = 60
def _initGL(self): """Initializes the Open GL viewport widget.""" glFormat = QtOpenGL.QGLFormat() glFormat.setDoubleBuffer(True) glFormat.setDepth(True) glFormat.setAlpha(True) glFormat.setSampleBuffers(True) glFormat.setSamples(4) self.viewport = Viewports.GLViewportWidget( self.client, self.config.defaultWindowColor, glFormat, self, self.settings) self.setCentralWidget(self.viewport) self.viewport.portManipulationRequested.connect( self.onPortManipulationRequested) self.renderingOptionsWidget = FabricUI.Viewports.ViewportOptionsEditor( self.client, self.qUndoStack) # When the rendering options of the viewport have changed, redraw self.renderingOptionsWidget.valueChanged.connect(self.viewport.redraw) # Once the Viewport has been setup (and filled its option values), update the options menu self.viewport.initComplete.connect( self.renderingOptionsWidget.updateOptions) self.renderingOptionsDockWidget = QtGui.QDockWidget( "Rendering Options", self) self.renderingOptionsDockWidget.setObjectName("Rendering Options") self.renderingOptionsDockWidget.setWidget(self.renderingOptionsWidget) self.renderingOptionsDockWidget.setFeatures(self.dockFeatures) self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.renderingOptionsDockWidget, QtCore.Qt.Vertical) self.renderingOptionsDockWidget.hide()
def __init__(self, parent=None): super(GLPlotWidget, self).__init__(QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers), parent) self.width = 400 self.height = 150 self.setFixedSize(self.width, self.height) self.setAutoFillBackground(False)
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
def __init__(self, parent, app): self.app = app self.blockRedraw = False format = QtOpenGL.QGLFormat() format.setAlpha(True) format.setDepthBufferSize(24) format.setSampleBuffers(True) format.setSamples(4) super(Canvas, self).__init__(format, parent) self.create()
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()
def __init__(self, parent=None, mesh=None): # Initialise QGLWidget with multisampling enabled and OpenGL 3 core only super(QtOpenGLWidget, self).__init__( qtgl.QGLFormat(qtgl.QGL.SampleBuffers | qtgl.QGL.NoDeprecatedFunctions), parent) # Track mouse events self.setMouseTracking(True) # Change the widget position and size self.setGeometry(100, 100, 1024, 768) # Mesh loaded at the initialisation self.mesh = mesh
def __init__(self, parent=None, shareWidget=None, format=QtOpenGL.QGLFormat()): super().__init__(format, parent, shareWidget) self.sizeHintValue = QtCore.QSize(512, 512) self.sceneManager = inventor.SceneManager() self.sceneManager.redisplay = self.updateGL self.resizeGLWidth = 512 self.resizeGLHeight = 512 # timer must be started from QThread self.idleTimer.start()
def __init__(self, parent=None, **option): fmt = QtOpenGL.QGLFormat() fmt.setRgba(True) fmt.setAlpha(True) fmt.setDepth(True) fmt.setDoubleBuffer(False) if option.get('vsync', False): fmt.setSwapInterval(1) else: fmt.setSwapInterval(0) QtOpenGL.QGLWidget.__init__(self, fmt, parent, GLWidget.getSharedWidget()) self.setFocusPolicy(QtCore.Qt.WheelFocus)
def _initGL(self): """Initializes the Open GL viewport widget.""" glFormat = QtOpenGL.QGLFormat() glFormat.setDoubleBuffer(True) glFormat.setDepth(True) glFormat.setAlpha(True) glFormat.setSampleBuffers(True) glFormat.setSamples(4) self.viewport = Viewports.GLViewportWidget(self.client, self.config.defaultWindowColor, glFormat, self, self.settings) self.setCentralWidget(self.viewport) self.viewport.portManipulationRequested.connect(self.onPortManipulationRequested)
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) widget = QMyPickWidget( format=QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers)) widget.sceneManager.background = (0.3, 0.3, 0.3) widget.sceneManager.scene = makeRandomScene(150) widget.sceneManager.interaction(1) mainLayout = QtGui.QHBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.addWidget(widget) self.setLayout(mainLayout) self.setWindowTitle(self.tr("Random Discs"))
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) widget = QtInventor.QIVWidget( format=QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers)) widget.sceneManager.background = (0.3, 0.3, 0.3) widget.sceneManager.scene = makeTexturedCubeScene() widget.sceneManager.view_all() mainLayout = QtGui.QHBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.addWidget(widget) self.setLayout(mainLayout) self.setWindowTitle(self.tr("Scene Texture"))
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__.setSwapInterval(0) __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)
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
def __init__(self, antialias=False, aspect_locked=False, grid_color=(0, 0, 0, 128), grid_line_width=1.0, use_opengl=False): QtWidgets.QGraphicsView.__init__(self) self.aspect_locked = aspect_locked self.grid_color = grid_color self.grid_line_width = grid_line_width self.setCacheMode(QtWidgets.QGraphicsView.CacheBackground) #self.setFocusPolicy(QtCore.Qt.StrongFocus) #self.setFrameShape(QtGui.QFrame.NoFrame) self.setFrameShape(QtWidgets.QFrame.Box) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.setTransformationAnchor(QtWidgets.QGraphicsView.NoAnchor) #self.setTransformationAnchor(QtGui.QGraphicsView.AnchorViewCenter) self.setResizeAnchor(QtWidgets.QGraphicsView.AnchorViewCenter) self.thaw() if antialias: self.setRenderHints(QtGui.QPainter.Antialiasing) self.setOptimizationFlag(self.DontAdjustForAntialiasing, True) self.setInteractive(False) self.scene = QtWidgets.QGraphicsScene(self) self.setScene(self.scene) #self.aspect_locked = True self.view_rect = QtCore.QRectF(0, 0, 1, 1) self.scene.setSceneRect(self.view_rect) if self.aspect_locked: self.fitInView(self.view_rect, QtCore.Qt.KeepAspectRatio) else: self.fitInView(self.view_rect, QtCore.Qt.IgnoreAspectRatio) if OPENGL_AVAILABLE and use_opengl: if antialias: qglf = QtOpenGL.QGLFormat() qglf.setSampleBuffers(True) qglw = QtOpenGL.QGLWidget(qglf) self.setViewport(qglw) else: self.setViewport(QtOpenGL.QGLWidget()) # dictionary of plot objects such as lines, points, etc. self.plot_items = dict()
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) widget = QtInventor.QIVWidget( format=QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers)) widget.sceneManager.background = (0.3, 0.3, 0.3) widget.sceneManager.scene = makeRandomScene(150) mainLayout = QtGui.QHBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.addWidget(widget) self.setLayout(mainLayout) self.setWindowTitle(self.tr("Render Offline")) # render scene to buffer and use as texture for cube img = widget.toImage(512, 512) widget.sceneManager.scene = makeTexturedCubeScene(img) widget.sceneManager.view_all()
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)
def initializeSceneGraph(self, graph, ui, **kwargs): """ Instantiate the GraphicsScene. Optionally set the current view widget to a :py:class:`~QtOpenGL.QGLWidget` widget. :param Graph graph: graph instance. :param :py:class:`~QMainWindow` ui: parent window. """ use_gl = kwargs.get('use_gl', ui.use_gl) if use_gl: from PySide import QtOpenGL self.setViewport( QtOpenGL.QGLWidget( QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers))) log.info('initializing OpenGL renderer.') # pass the Graph instance to the GraphicsScene scene = GraphicsScene(self, graph=graph, ui=ui) scene.setSceneRect(-5000, -5000, 10000, 10000) self.setScene(scene)
def set_configuration(config): global __glformat__ __glformat__ = QtOpenGL.QGLFormat() __glformat__.setSwapInterval(0) __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)
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 PySide 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)
def __init__(self, parent=None): # Initialise QGLWidget with multisampling enabled and OpenGL 3 core only super(PointCloudViewer, self).__init__( QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers | QtOpenGL.QGL.NoDeprecatedFunctions), parent) # Set the window title self.setWindowTitle('Point Cloud') # Track mouse events self.setMouseTracking(True) # Change the widget position and size self.setGeometry(100, 100, 1024, 768) # Button pressed self.button = 0 # Mouse position self.previous_mouse_position = [0, 0] # Tranformation matrix self.transformation = np.identity(4, dtype=np.float32) # Set the Escape key to close the application QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Escape), self).activated.connect(self.close) # Set the R key to reset the view QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_R), self).activated.connect(self.Reset)
def __init__(self, *args, **kwargs): super(DisplayWidget, self).__init__(*args, **kwargs) # We draw to an OpenGL scene, so instantiate # the QGLWidget. gl_format = QtOpenGL.QGLFormat() gl_format.setSampleBuffers(True) self.gl_widget = QtOpenGL.QGLWidget(gl_format) # Set up the view self.view = GraphicsView() self.view.setViewport(self.gl_widget) self.view.setViewportUpdateMode(QGraphicsView.FullViewportUpdate) # Set up the scene self.scene = OpenGLScene() # Add the controls to it self.overlay_widget = OverlayWidget() self.scene.addWidget(self.overlay_widget) self.overlay_widget.move(QtCore.QPoint(0,0)) self.overlay_widget.setAttribute(QtCore.Qt.WA_TranslucentBackground) # Assign in the scene to the view. self.view.setScene(self.scene) #self.view.show() #self.view.resize(800,600) # Set the scene and view to be a child of this class self.view.setParent(self) self.scene.setParent(self)
def __init__(self, parent=None, **option): fmt = QtOpenGL.QGLFormat() if option.get('vsync', True): fmt.setSwapInterval(1) else: fmt.setSwapInterval(0) fmt.setSampleBuffers(option.get('sample_buffer', True)) QtOpenGL.QGLWidget.__init__(self, fmt, parent, GLWidget.getSharedWidget()) self.setAttribute(Qt.WA_NoSystemBackground, True) self.setAttribute(Qt.WA_OpaquePaintEvent, True) self.setSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Ignored) self.setFocusPolicy(QtCore.Qt.ClickFocus) self.setMouseTracking(True) self.allowRefresh = False self.pendingRefresh = False self.refreshTimer = QtCore.QTimer(self) self.refreshTimer.setSingleShot(True) self.refreshTimer.timeout.connect(self.onRefreshTimer)