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()
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()
def testRawData(self): data = QDataStream() self.assertEqual(data.readRawData(4), None) ba = QByteArray() data = QDataStream(ba, QIODevice.WriteOnly) data.writeRawData('AB\x00C') self.assertEqual(ba.data(), py3k.b('AB\x00C')) data = QDataStream(ba) self.assertEqual(data.readRawData(4), py3k.b('AB\x00C'))
def image(self,pixmap): if pixmap == None: self._image_as_pixmap = None self.picture_data = None else: byte_array = QByteArray() qbuffer = QBuffer(byte_array) qbuffer.open(QIODevice.WriteOnly) pixmap.toImage().save(qbuffer, "PNG") self._image_as_pixmap = None self.picture_data = memoryview(byte_array.data()) # memory view to support python 2 and 3
def getIcon(obj, disabled=False, path=None): if not path: path = iconPath if not getattr(obj, '_icon', None): obj._icon = addIconToFCAD(obj._iconName, path) if not disabled: return obj._icon if not getattr(obj, '_iconDisabled', None): name = getattr(obj, '_iconDisabledName', None) if name: obj._iconDisabled = addIconToFCAD(name, path) else: key = os.path.join(path, obj._iconName) + '.disabled' fmt = None try: if FreeCADGui.isIconCached(key): obj._iconDisabled = key return key else: fmt = 'PNG' except Exception: pass pixmap = FreeCADGui.getIcon(obj._icon).pixmap(*iconSize, mode=QIcon.Disabled) icon = QIcon(pixmapDisabled) icon.paint(QPainter(pixmap), 0, 0, iconSize[0], iconSize[1], Qt.AlignCenter) data = QByteArray() buf = QBuffer(data) buf.open(QIODevice.WriteOnly) if fmt: pixmap.save(buf, fmt) FreeCADGui.addIcon(key, data.data(), fmt) else: pixmap.save(buf, 'XPM') key = data.data().decode('latin1') obj._iconDisabled = key return obj._iconDisabled
def sendReply(self, action, *args, **kwargs): try: if hasattr(self, "socket"): reply = QByteArray() stream = QDataStream(reply, QIODevice.WriteOnly) stream.setVersion(QDataStream.Qt_4_2) stream.writeUInt32(0) stream.writeQString(action) for arg in args: if type(arg) is LongType: stream.writeQString(str(arg)) if type(arg) is IntType: stream.writeInt(int(arg)) elif type(arg) is StringType: stream.writeQString(arg) elif isinstance(arg, basestring): stream.writeQString(arg) elif type(arg) is FloatType: stream.writeFloat(arg) elif type(arg) is ListType: stream.writeQString(str(arg)) elif type(arg) is QFile: arg.open(QIODevice.ReadOnly) fileDatas = QByteArray(arg.readAll()) stream.writeInt32(fileDatas.size()) stream.writeRawData(fileDatas.data()) arg.close() # stream << action << options stream.device().seek(0) stream.writeUInt32(reply.size() - 4) self.socket.write(reply) # else : # # no socket !? # self.quit() except: self.log.exception("Something awful happened when sending reply !")
def sendReply(self, action, *args, **kwargs): try: if hasattr(self, "socket"): reply = QByteArray() stream = QDataStream(reply, QIODevice.WriteOnly) stream.setVersion(QDataStream.Qt_4_2) stream.writeUInt32(0) stream.writeQString(action) for arg in args: if type(arg) is LongType: stream.writeQString(str(arg)) if type(arg) is IntType: stream.writeInt(int(arg)) elif type(arg) is StringType: stream.writeQString(arg) elif isinstance(arg, basestring): stream.writeQString(arg) elif type(arg) is FloatType: stream.writeFloat(arg) elif type(arg) is ListType: stream.writeQString(str(arg)) elif type(arg) is QFile: arg.open(QIODevice.ReadOnly) fileDatas = QByteArray(arg.readAll()) stream.writeInt32(fileDatas.size()) stream.writeRawData(fileDatas.data()) arg.close() #stream << action << options stream.device().seek(0) stream.writeUInt32(reply.size() - 4) self.socket.write(reply) # else : # # no socket !? # self.quit() except: self.log.exception("Something awful happened when sending reply !")
def testDataWithZeros(self): s1 = "123\000321" ba = QByteArray(s1) s2 = ba.data() self.assertEqual(py3k.b(s1), s2) self.assertEqual(s1, ba)
def testData(self): url = QByteArray("http://web.openbossa.org/") self.assertEqual(url.data(), py3k.b("http://web.openbossa.org/"))