本文整理汇总了Python中PySide.QtOpenGL.QGLWidget类的典型用法代码示例。如果您正苦于以下问题:Python QGLWidget类的具体用法?Python QGLWidget怎么用?Python QGLWidget使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QGLWidget类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testIt
def testIt(self):
w = QGLWidget()
w.makeCurrent()
b = QGLBuffer()
b.setUsagePattern(QGLBuffer.DynamicDraw)
self.assertTrue(b.create())
self.assertTrue(b.bufferId() != 0)
self.assertTrue(b.bind())
data = QByteArray("12345")
b.allocate(data)
self.assertEqual(b.size(), data.size())
m = b.map(QGLBuffer.ReadOnly)
if m:
self.assertEqual(m, py3k.buffer(py3k.b(data.data())))
b.unmap()
m = b.map(QGLBuffer.ReadWrite)
m[3] = py3k.b('A')
b.unmap()
result, rdata = b.read(3, 1)
self.assertTrue(result)
self.assertEqual(py3k.b('A'), rdata.data())
else:
print(" memory mapping is not possible in this OpenGL implementation.")
b.release()
示例2: reload
def reload(self, gl, full_reload):
imgs = self.images
reload_buffers = False
reload_images = False
if full_reload:
reload_buffers =True
reload_images = True
# If this is a full reload, all the textures were automatically deleted,
# so just create new arrays so we won't try to delete the old ones again.
self.textures = [None] * len(imgs)
self.red_textures = [None] * len(imgs)
else:
# Process any queued updates.
reset = self.update_type.Reset in self.updates
reload_buffers = reload_buffers or reset or self.update_type.UpdatePositions in self.updates
reload_images = reload_images or reset or self.update_type.UpdateImages in self.updates
self.updates = set()
if reload_buffers:
self.vertex_buffer.reload()
self.text_coord_buffer.reload()
if reload_images:
for i in range(0, len(self.textures)):
#If the image is already allocated, delete it.
if self.textures[i] != None:
self.textures[i].delete(gl)
self.red_textures[i].delete(gl)
bmp = self.images[i].pixmap
self.textures[i] = TextureManager().create_texture(gl)
self.textures[i].bind(gl)
gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)
'''
IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT
The image has to be mirrored for some reason
'''
q_img = QImage(bmp.toImage()).mirrored()
img = QGLWidget.convertToGLFormat(q_img)
gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGB, img.width(), img.height(), 0, gl.GL_RGBA,
gl.GL_UNSIGNED_BYTE, str(img.bits()))
self.red_textures[i] = TextureManager().create_texture(gl)
self.red_textures[i].bind(gl)
gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)
red_pixels = self.create_red_image(q_img)
red_pixels = QGLWidget.convertToGLFormat(red_pixels)
gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, red_pixels.width(), red_pixels.height(),
0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, str(red_pixels.bits()))
示例3: __init__
def __init__(self, dimension, textureAtlas=None, geometryCache=None, sharedGLWidget=None):
"""
:param dimension:
:type dimension: WorldEditorDimension
:param textureAtlas:
:type textureAtlas: TextureAtlas
:param geometryCache:
:type geometryCache: GeometryCache
:param sharedGLWidget:
:type sharedGLWidget: QGLWidget
:return:
:rtype:
"""
QGLWidget.__init__(self, shareWidget=sharedGLWidget)
self.setSizePolicy(QtGui.QSizePolicy.Policy.Expanding, QtGui.QSizePolicy.Policy.Expanding)
self.setFocusPolicy(Qt.ClickFocus)
self.layerToggleGroup = LayerToggleGroup()
self.layerToggleGroup.layerToggled.connect(self.setLayerVisible)
self.dimension = None
self.worldScene = None
self.loadableChunksNode = None
self.textureAtlas = None
self.mouseRay = Ray(Vector(0, 1, 0), Vector(0, -1, 0))
self.setMouseTracking(True)
self.lastAutoUpdate = time.time()
self.autoUpdateInterval = 0.5 # frequency of screen redraws in response to loaded chunks
self.compassNode = self.createCompass()
self.compassOrthoNode = scenegraph.OrthoNode((1, float(self.height()) / self.width()))
self.compassOrthoNode.addChild(self.compassNode)
self.viewActions = []
self.pressedKeys = set()
self.setTextureAtlas(textureAtlas)
if geometryCache is None and sharedGLWidget is not None:
geometryCache = sharedGLWidget.geometryCache
if geometryCache is None:
geometryCache = GeometryCache()
self.geometryCache = geometryCache
self.matrixNode = None
self.overlayNode = scenegraph.Node()
self.sceneGraph = None
self.renderGraph = None
self.frameSamples = deque(maxlen=500)
self.frameSamples.append(time.time())
self.cursorNode = None
self.setDimension(dimension)
示例4: __init__
def __init__(self, **kwargs):
QGLWidget.__init__(self, **kwargs)
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
self.opengl_resize = kwargs.get('resize', True)
self.opengl_keep_aspect = kwargs.get('keep_aspect', True)
self.opengl_data = None
示例5: __init__
def __init__(self, debug_mode=None):
'''
Constructor
'''
QGLWidget.__init__(self)
self.DEBUG_MODE = debug_mode
self.texture_manager = TextureManager()
self.render_state = RenderState()
self.projection_matrix = None
self.view_matrix = None
self.update_closures = []
self.all_managers = []
self.managers_to_reload = []
self.layers_to_managers = {}
def queue_for_reload(rom, full_reload):
self.managers_to_reload.append(self.ManagerReloadData(rom, full_reload))
self.update_listener = queue_for_reload
# The skybox should go behind everything.
self.sky_box = SkyBox(0x10000000, self.texture_manager)
self.sky_box.enabled = False
self.add_object_manager(self.sky_box)
#The overlays go on top of everything.
self.overlay_manager = OverlayManager(0xEFFFFFFF, self.texture_manager)
self.add_object_manager(self.overlay_manager)
示例6: __init__
def __init__(self, parent=None):
QGLWidget.__init__(self, parent)
self.timer = QTimer(self)
# the timer, which drives the animation
self.timer.timeout.connect(self.update)
# the angle, by which the spiral is rotated
self.angle = 0
self.spiral = self.update_spiral()
示例7: __init__
def __init__(self, parent=None):
QGLWidget.__init__(self, parent)
self.setAutoBufferSwap(False)
self.resize(640, 480)
self.opengl_thread = QThread()
QCoreApplication.instance().aboutToQuit.connect(self.clean_up_before_quit)
self.trackball = Trackball()
self.preferredSize = None
self.setFocusPolicy(Qt.WheelFocus)
示例8: BitPurse
class BitPurse(QApplication):
''' Application class '''
def __init__(self):
QApplication.__init__(self, sys.argv)
self.setOrganizationName("Khertan Software")
self.setOrganizationDomain("khertan.net")
self.setApplicationName("BitPurse")
self.view = QtDeclarative.QDeclarativeView()
# Are we on mer ? So don't use opengl
# As it didn't works on all devices
if os.path.exists('/etc/mer-release'):
fullscreen = True
elif os.path.exists('/etc/aegis'):
fullscreen = True
self.glformat = QGLFormat().defaultFormat()
self.glformat.setSampleBuffers(False)
self.glw = QGLWidget(self.glformat)
self.glw.setAutoFillBackground(False)
self.view.setViewport(self.glw)
else:
fullscreen = False
self.walletController = WalletController()
self.rootContext = self.view.rootContext()
self.rootContext.setContextProperty("argv", sys.argv)
self.rootContext.setContextProperty("__version__", __version__)
self.rootContext.setContextProperty("__upgrade__", __upgrade__
.replace('\n', '<br />'))
self.rootContext.setContextProperty('WalletController',
self.walletController)
self.rootContext.setContextProperty('AddressesModel',
self.walletController
.addressesModel)
self.rootContext.setContextProperty('TransactionsModel',
self.walletController
.transactionsModel)
self.rootContext.setContextProperty('Settings',
self.walletController
.settings)
self.view.setSource(QUrl.fromLocalFile(
os.path.join(os.path.dirname(__file__),
'qml', 'main.qml')))
self.rootObject = self.view.rootObject()
if fullscreen:
self.view.showFullScreen()
else:
self.view.show()
# self.loginPage = self.rootObject.findChild(QObject, "loginPage")
self.sendPage = self.rootObject.findChild(QObject, "sendPage")
self.aboutPage = self.rootObject.findChild(QObject, "aboutPage")
self.walletController.onError.connect(self.rootObject.onError)
# self.walletController.onConnected.connect(self.loginPage.onConnected)
self.walletController.onTxSent.connect(self.sendPage.onTxSent)
示例9: __init__
def __init__(self, parent=None):
QGLWidget.__init__(self, parent)
self.object = 0
self.xRot = 0
self.yRot = 0
self.zRot = 0
self.lastPos = QtCore.QPoint()
self.trolltechGreen = QtGui.QColor.fromCmykF(0.40, 0.0, 1.0, 0.0)
self.trolltechPurple = QtGui.QColor.fromCmykF(0.39, 0.39, 0.0, 0.0)
示例10: KhtNotes
class KhtNotes(QApplication):
''' Application class '''
def __init__(self):
QApplication.__init__(self, sys.argv)
self.setOrganizationName("Khertan Software")
self.setOrganizationDomain("khertan.net")
self.setApplicationName("KhtNotes")
self.settings = Settings()
self.view = FilteredDeclarativeView(settings=self.settings)
if os.path.exists('/etc/mer-release'):
fullscreen = True
elif os.path.exists('/etc/aegis'):
fullscreen = True
self.glformat = QGLFormat().defaultFormat()
self.glformat.setSampleBuffers(False)
self.glw = QGLWidget(self.glformat)
self.glw.setAutoFillBackground(False)
self.view.setViewport(self.glw)
else:
fullscreen = False
self.notesModel = NotesModel()
self.note = Note(settings=self.settings)
self.conboyImporter = TomboyImporter()
self.syncer = Sync()
self.rootContext = self.view.rootContext()
self.rootContext.setContextProperty("argv", sys.argv)
self.rootContext.setContextProperty("__version__", __version__)
self.rootContext.setContextProperty("__upgrade__", __upgrade__
.replace('\n', '<br />'))
self.rootContext.setContextProperty("Settings", self.settings)
self.rootContext.setContextProperty("Sync", self.syncer)
self.rootContext.setContextProperty("Importer", self.conboyImporter)
self.rootContext.setContextProperty('notesModel', self.notesModel)
self.rootContext.setContextProperty('Note', self.note)
try:
self.view.setSource(QUrl.fromLocalFile(
os.path.join(os.path.dirname(__file__),
'qml', 'Harmattan_main.qml')))
except:
self.view.setSource(QUrl.fromLocalFile(
os.path.join(os.path.dirname(__file__),
'qml', 'Desktop_main.qml')))
self.rootObject = self.view.rootObject()
if fullscreen:
self.view.showFullScreen()
else:
self.view.show()
self.note.on_error.connect(self.rootObject.onError)
self.syncer.on_error.connect(self.rootObject.onError)
self.syncer.on_finished.connect(self.rootObject.refresh)
self.conboyImporter.on_finished.connect(self.notesModel.reload)
示例11: __init__
def __init__(self, parent, enableUi,File=""):
f = QGLFormat()
f.setStencil(True)
f.setRgba(True)
f.setDepth(True)
f.setDoubleBuffer(True)
QGLWidget.__init__(self, f, parent=parent)
self.setMinimumSize(500, 500)
self._enableUi=enableUi
self.pymol = pymol2.PyMOL()# _pymolPool.getInstance()
self.pymol.start()
self.cmd = self.pymol.cmd
# self.toPymolName = self.pymol.toPymolName ### Attribute Error
self._pymolProcess()
self.setFocusPolicy(Qt.ClickFocus)
#self.Parser = self.
if not self._enableUi:
self.pymol.cmd.set("internal_gui",0)
self.pymol.cmd.set("internal_feedback",0)
self.pymol.cmd.button("double_left","None","None")
self.pymol.cmd.button("single_right","None","None")
self.pymol.cmd.load(File)
# inFile = "./data/scTIM.pdb"
if(File[-9:-1] == "scTIM.pdb"):
self.cmd.show("cartoon", "chain B")
self.cmd.hide("lines", "chain B")
else:
self.cmd.hide("all")
self.cmd.cartoon("tube")
self.cmd.show("cartoon")
#self.cmd.show("cartoon")
#self.cmd.cartoon("putty")
self.cmd.set("cartoon_highlight_color", 1)
#self.cmd.hide("lines")
#self.cmd.hide("chain ")
self.color_obj(0)
#self.cmd.color("marine")
self.pymol.reshape(self.width(),self.height())
self._timer = QtCore.QTimer()
self._timer.setSingleShot(True)
self._timer.timeout.connect(self._pymolProcess)
self.resizeGL(self.width(),self.height())
#globalSettings.settingsChanged.connect(self._updateGlobalSettings)
self._updateGlobalSettings()
define_color(self.cmd.set_color)
# used for save the color of residues
self._color_cache = {}
self._selected =[]
示例12: keyPressEvent
def keyPressEvent(self, event):
if event.key() == Qt.Key_Left:
r = Rotation().set_from_angle_about_unit_vector(-0.05, [0, 0, -1])
self.trackball.rotation_incremented.emit(r)
elif event.key() == Qt.Key_Right:
r = Rotation().set_from_angle_about_unit_vector( 0.05, [0, 0, -1])
self.trackball.rotation_incremented.emit(r)
elif event.key() == Qt.Key_Up:
self.trackball.pixel_translated.emit(0, 0, 50);
elif event.key() == Qt.Key_Down:
self.trackball.pixel_translated.emit(0, 0, -50);
QGLWidget.keyPressEvent(self, event) # not my event
示例13: __init__
def __init__(self):
QApplication.__init__(self, sys.argv)
self.setOrganizationName("Khertan Software")
self.setOrganizationDomain("khertan.net")
self.setApplicationName("KhtSimpleText")
self.view = QtDeclarative.QDeclarativeView()
#Are we on mer ? So don't use opengl
#As it didn't works on all devices
if not os.path.exists('/etc/mer-release'):
self.glformat = QGLFormat().defaultFormat()
self.glformat.setSampleBuffers(False)
self.glw = QGLWidget(self.glformat)
self.glw.setAutoFillBackground(False)
self.view.setViewport(self.glw)
self.document = Document('~')
self.documentsModel= DocumentsModel(currentDoc=self.document)
self.rootContext = self.view.rootContext()
self.rootContext.setContextProperty("argv", sys.argv)
self.rootContext.setContextProperty("__version__", __version__)
self.rootContext.setContextProperty("__upgrade__", __upgrade__
.replace('\n', '<br>'))
self.rootContext.setContextProperty("Settings", Settings())
self.rootContext.setContextProperty("DocumentsModel",
self.documentsModel)
self.rootContext.setContextProperty("Document",
self.document)
self.view.setSource(QUrl.fromLocalFile(
os.path.join(os.path.dirname(__file__), 'qml', 'main.qml')))
self.rootObject = self.view.rootObject()
self.view.showFullScreen()
示例14: __init__
def __init__(self):
QGLWidget.__init__(self)
self.triangleCount = 0
self.edgeCount = 0
self.pointCount = 0
self.triangleVertexArrayObject = None
self.edgeVertexArrayObject = None
self.pointVertexArrayObject = None
self.drawTriangles = False
self.drawLines = False
self.drawPoints = False
self.lastMouseX = 0
self.lastMouseY = 0
self.camera = Camera([0.0, 0.0, -1.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0])
self.WVPMatrix = None
self.setProperty("class", "AlgorithmVisualizerWidget")
self.UpdateWVPMatrix()
示例15: loadPNGImage
def loadPNGImage(img):
glImg = QGLWidget.convertToGLFormat(img)
if glImg is None:
raise ValueError, "Loading png file %s: Conversion to GL format failed." % img
ndata = numpy.fromstring(glImg.bits(), dtype='uint8')
w = glImg.width()
h = glImg.height()
b = glImg.depth() / 8
assert len(ndata) == w * h * b
return w, h, ndata.reshape((h, w, b))