Python PyQt5.QtCore.QBuffer() Examples
The following are 27
code examples of PyQt5.QtCore.QBuffer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PyQt5.QtCore
, or try the search function
.
Example #1
Source File: sorter.py From Lector with GNU General Public License v3.0 | 7 votes |
def resize_image(cover_image_raw): if isinstance(cover_image_raw, QtGui.QImage): cover_image = cover_image_raw else: cover_image = QtGui.QImage() cover_image.loadFromData(cover_image_raw) # Resize image to what literally everyone # agrees is an acceptable cover size cover_image = cover_image.scaled( 420, 600, QtCore.Qt.IgnoreAspectRatio) byte_array = QtCore.QByteArray() buffer = QtCore.QBuffer(byte_array) buffer.open(QtCore.QIODevice.WriteOnly) cover_image.save(buffer, 'jpg', 75) cover_image_final = io.BytesIO(byte_array) cover_image_final.seek(0) return cover_image_final.getvalue()
Example #2
Source File: BlockRequest.py From PyQt with GNU General Public License v3.0 | 6 votes |
def createRequest(self, op, originalReq, outgoingData): """创建请求 :param op: 操作类型见http://doc.qt.io/qt-5/qnetworkaccessmanager.html#Operation-enum :param originalReq: 原始请求 :param outgoingData: 输出数据 """ url = originalReq.url().toString() if url.find('pos.baidu.com') > -1 and url.find('ltu=') > -1: # 拦截百度联盟的广告 print('block:', url) originalReq.setUrl(QUrl()) if op == self.PostOperation and outgoingData: # 拦截或者修改post数据 # 读取后要重新设置,不然网站接收不到请求 data = outgoingData.readAll().data() print('post data:', data) # 修改data后重新设置 outgoingData = QBuffer(self) outgoingData.setData(data) return super(RequestInterceptor, self).createRequest(op, originalReq, outgoingData)
Example #3
Source File: ImageQt.py From teleport with Apache License 2.0 | 6 votes |
def fromqimage(im): """ :param im: A PIL Image object, or a file name (given either as Python string or a PyQt string object) """ buffer = QBuffer() buffer.open(QIODevice.ReadWrite) # preserve alha channel with png # otherwise ppm is more friendly with Image.open if im.hasAlphaChannel(): im.save(buffer, 'png') else: im.save(buffer, 'ppm') b = BytesIO() try: b.write(buffer.data()) except TypeError: # workaround for Python 2 b.write(str(buffer.data())) buffer.close() b.seek(0) return Image.open(b)
Example #4
Source File: ImageQt.py From teleport with Apache License 2.0 | 6 votes |
def fromqimage(im): """ :param im: A PIL Image object, or a file name (given either as Python string or a PyQt string object) """ buffer = QBuffer() buffer.open(QIODevice.ReadWrite) # preserve alpha channel with png # otherwise ppm is more friendly with Image.open if im.hasAlphaChannel(): im.save(buffer, "png") else: im.save(buffer, "ppm") b = BytesIO() b.write(buffer.data()) buffer.close() b.seek(0) return Image.open(b)
Example #5
Source File: ImageQt.py From lambda-text-extractor with Apache License 2.0 | 6 votes |
def fromqimage(im): """ :param im: A PIL Image object, or a file name (given either as Python string or a PyQt string object) """ buffer = QBuffer() buffer.open(QIODevice.ReadWrite) # preserve alha channel with png # otherwise ppm is more friendly with Image.open if im.hasAlphaChannel(): im.save(buffer, 'png') else: im.save(buffer, 'ppm') b = BytesIO() try: b.write(buffer.data()) except TypeError: # workaround for Python 2 b.write(str(buffer.data())) buffer.close() b.seek(0) return Image.open(b)
Example #6
Source File: ImageQt.py From teleport with Apache License 2.0 | 6 votes |
def fromqimage(im): """ :param im: A PIL Image object, or a file name (given either as Python string or a PyQt string object) """ buffer = QBuffer() buffer.open(QIODevice.ReadWrite) # preserve alpha channel with png # otherwise ppm is more friendly with Image.open if im.hasAlphaChannel(): im.save(buffer, "png") else: im.save(buffer, "ppm") b = BytesIO() b.write(buffer.data()) buffer.close() b.seek(0) return Image.open(b)
Example #7
Source File: ImageQt.py From FODI with GNU General Public License v3.0 | 6 votes |
def fromqimage(im): """ :param im: A PIL Image object, or a file name (given either as Python string or a PyQt string object) """ buffer = QBuffer() buffer.open(QIODevice.ReadWrite) # preserve alpha channel with png # otherwise ppm is more friendly with Image.open if im.hasAlphaChannel(): im.save(buffer, "png") else: im.save(buffer, "ppm") b = BytesIO() b.write(buffer.data()) buffer.close() b.seek(0) return Image.open(b)
Example #8
Source File: ImageQt.py From lambda-text-extractor with Apache License 2.0 | 6 votes |
def fromqimage(im): """ :param im: A PIL Image object, or a file name (given either as Python string or a PyQt string object) """ buffer = QBuffer() buffer.open(QIODevice.ReadWrite) # preserve alha channel with png # otherwise ppm is more friendly with Image.open if im.hasAlphaChannel(): im.save(buffer, 'png') else: im.save(buffer, 'ppm') b = BytesIO() try: b.write(buffer.data()) except TypeError: # workaround for Python 2 b.write(str(buffer.data())) buffer.close() b.seek(0) return Image.open(b)
Example #9
Source File: ImageQt.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def fromqimage(im): """ :param im: A PIL Image object, or a file name (given either as Python string or a PyQt string object) """ buffer = QBuffer() buffer.open(QIODevice.ReadWrite) # preserve alpha channel with png # otherwise ppm is more friendly with Image.open if im.hasAlphaChannel(): im.save(buffer, 'png') else: im.save(buffer, 'ppm') b = BytesIO() try: b.write(buffer.data()) except TypeError: # workaround for Python 2 b.write(str(buffer.data())) buffer.close() b.seek(0) return Image.open(b)
Example #10
Source File: items.py From Miyamoto with GNU General Public License v3.0 | 6 votes |
def UpdateListItem(self, updateTooltipPreview=False): """ Updates the list item """ if not hasattr(self, 'listitem'): return if self.listitem is None: return if updateTooltipPreview: # It's just like Qt to make this overly complicated. XP img = self.renderInLevelIcon() byteArray = QtCore.QByteArray() buf = QtCore.QBuffer(byteArray) img.save(buf, 'PNG') byteObj = bytes(byteArray) b64 = base64.b64encode(byteObj).decode('utf-8') self.listitem.setToolTip('<img src="data:image/png;base64,' + b64 + '" />') self.listitem.setText(self.ListString())
Example #11
Source File: qt.py From Sark with MIT License | 6 votes |
def capture_widget(widget, path=None): """Grab an image of a Qt widget Args: widget: The Qt Widget to capture path (optional): The path to save to. If not provided - will return image data. Returns: If a path is provided, the image will be saved to it. If not, the PNG buffer will be returned. """ pixmap = widget.grab() if path: pixmap.save(path) else: image_buffer = QtCore.QBuffer() image_buffer.open(QtCore.QIODevice.ReadWrite) pixmap.save(image_buffer, "PNG") return image_buffer.data().data()
Example #12
Source File: ImageQt.py From lambda-text-extractor with Apache License 2.0 | 5 votes |
def fromqpixmap(im): return fromqimage(im) # buffer = QBuffer() # buffer.open(QIODevice.ReadWrite) # # im.save(buffer) # # What if png doesn't support some image features like animation? # im.save(buffer, 'ppm') # bytes_io = BytesIO() # bytes_io.write(buffer.data()) # buffer.close() # bytes_io.seek(0) # return Image.open(bytes_io)
Example #13
Source File: app.py From strike-with-a-pose with GNU General Public License v3.0 | 5 votes |
def capture_screenshot(self): buffer = QtCore.QBuffer() buffer.open(QtCore.QIODevice.ReadWrite) qimage = self.grabFramebuffer() result = qimage.save("screenshot_{0}.png".format(str(self.screenshot)).zfill(2)) self.screenshot += 1
Example #14
Source File: ImageQt.py From FODI with GNU General Public License v3.0 | 5 votes |
def fromqpixmap(im): return fromqimage(im) # buffer = QBuffer() # buffer.open(QIODevice.ReadWrite) # # im.save(buffer) # # What if png doesn't support some image features like animation? # im.save(buffer, 'ppm') # bytes_io = BytesIO() # bytes_io.write(buffer.data()) # buffer.close() # bytes_io.seek(0) # return Image.open(bytes_io)
Example #15
Source File: mainempresa.py From controleEstoque with MIT License | 5 votes |
def CadEmpresa(self): INSERI = CrudEmpresa() INSERI.id = self.tx_idEmpresa.text() INSERI.nomeFantasia = self.tx_NomeFantasia.text().upper() INSERI.razaoSocial = self.tx_RazaoSocial.text().upper() INSERI.cnpj = self.tx_Cnpj.text() INSERI.inscEstadual = self.tx_IE.text() INSERI.telefone = re.sub( '[^[0-9]', '', (self.tx_TelefoneEmpresa.text())) INSERI.email = self.tx_EmailEmpresa.text() INSERI.site = self.tx_SiteEmpresa.text() INSERI.obs = self.tx_ObsEmpresa.text().upper() INSERI.cep = re.sub('[^[0-9]', '', (self.tx_CepEmpresa.text())) INSERI.endereco = self.tx_Endereco.text().upper() INSERI.numero = self.tx_NumEmpresa.text() INSERI.bairro = self.tx_BairroEmpresa.text().upper() INSERI.cidade = self.tx_CidadeEmpresa.text().upper() INSERI.estado = self.tx_EstadoEmpresa.text().upper() INSERI.titulo = self.tx_Titulo.text() INSERI.subtitulo = self.tx_SubTitulo.text() if self.lb_LogoEmpresa.pixmap(): image = QPixmap(self.lb_LogoEmpresa.pixmap()) data = QByteArray() buf = QBuffer(data) image.save(buf, 'PNG') logo = str(data.toBase64()).encode('utf8')[2:-1] INSERI.logo = logo else: INSERI.logo = False INSERI.inseriEmpresa() self.lb_NomeFantasia.setText(self.tx_Titulo.text()) self.lb_NomeFantasia2.setText(INSERI.subtitulo) self.setWindowTitle(INSERI.titulo + " " + INSERI.subtitulo)
Example #16
Source File: ImageQt.py From lambda-text-extractor with Apache License 2.0 | 5 votes |
def fromqpixmap(im): return fromqimage(im) # buffer = QBuffer() # buffer.open(QIODevice.ReadWrite) # # im.save(buffer) # # What if png doesn't support some image features like animation? # im.save(buffer, 'ppm') # bytes_io = BytesIO() # bytes_io.write(buffer.data()) # buffer.close() # bytes_io.seek(0) # return Image.open(bytes_io)
Example #17
Source File: mainprodutos.py From controleEstoque with MIT License | 5 votes |
def cadProduto(self): INSERI = CrudProduto() INSERI.id = self.tx_idProduto.text() INSERI.produto = self.tx_DescricaoProduto.text().upper() if self.lb_FotoProduto.pixmap(): imagem = QPixmap(self.lb_FotoProduto.pixmap()) data = QByteArray() buf = QBuffer(data) imagem.save(buf, 'PNG') INSERI.imagem = str(data.toBase64()).encode('utf8')[2:-1] else: INSERI.imagem = False INSERI.categoria = self.cb_CategoriaProduto.currentData() INSERI.marca = self.cb_MarcaProduto.currentData() INSERI.estoqueMinimo = self.tx_EstoqueMinimoProduto.text() INSERI.estoqueMaximo = self.tx_EstoqueMaximoProduto.text() INSERI.obsProduto = self.tx_ObsProduto.text() INSERI.valorCompra = self.tx_ValorCompraProduto.text().replace(",", ".") INSERI.valorUnitario = self.tx_ValorUnitarioProduto.text().replace(",", ".") INSERI.valorAtacado = self.tx_ValorAtacadoProduto.text().replace(",", ".") INSERI.qtdeAtacado = self.tx_MinimoAtacado.text() INSERI.inseriProduto() self.janelaProdutos() # Selecionando Produto
Example #18
Source File: app.py From strike-with-a-pose with GNU General Public License v3.0 | 5 votes |
def get_prediction(self): # See: https://stackoverflow.com/questions/1733096/convert-pyqt-to-pil-image. buffer = QtCore.QBuffer() buffer.open(QtCore.QIODevice.ReadWrite) qimage = self.grabFramebuffer() qimage.save(buffer, "PNG") strio = io.BytesIO() strio.write(buffer.data()) buffer.close() strio.seek(0) pil_im = Image.open(strio) pil_im = pil_im.resize(self.scene.WINDOW_SIZE) self.model.predict(pil_im)
Example #19
Source File: tomarFoto.py From PyQt5 with MIT License | 5 votes |
def procesarImagenCapturada(self, requestId, imagen): foto = QPixmap.fromImage(imagen) buffer = QBuffer(self.byteArrayFoto) buffer.open(QIODevice.WriteOnly) buffer.close() foto.save(buffer, "PNG") fotoEscalada = foto.scaled(self.labelFoto.size()) self.labelFoto.setPixmap(fotoEscalada) self.mostrarImagenCapturada()
Example #20
Source File: ImageQt.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def fromqpixmap(im): return fromqimage(im) # buffer = QBuffer() # buffer.open(QIODevice.ReadWrite) # # im.save(buffer) # # What if png doesn't support some image features like animation? # im.save(buffer, 'ppm') # bytes_io = BytesIO() # bytes_io.write(buffer.data()) # buffer.close() # bytes_io.seek(0) # return Image.open(bytes_io)
Example #21
Source File: wrapper.py From scudcloud with MIT License | 5 votes |
def pasted(self, checked): clipboard = QApplication.clipboard() mime = clipboard.mimeData() if mime.hasImage(): pixmap = clipboard.pixmap() byteArray = QByteArray() buffer = QBuffer(byteArray) pixmap.save(buffer, "PNG") self.call("setClipboard", str(byteArray.toBase64(), sys.stdout.encoding))
Example #22
Source File: ImageQt.py From teleport with Apache License 2.0 | 5 votes |
def fromqpixmap(im): return fromqimage(im) # buffer = QBuffer() # buffer.open(QIODevice.ReadWrite) # # im.save(buffer) # # What if png doesn't support some image features like animation? # im.save(buffer, 'ppm') # bytes_io = BytesIO() # bytes_io.write(buffer.data()) # buffer.close() # bytes_io.seek(0) # return Image.open(bytes_io)
Example #23
Source File: ImageQt.py From teleport with Apache License 2.0 | 5 votes |
def fromqpixmap(im): return fromqimage(im) # buffer = QBuffer() # buffer.open(QIODevice.ReadWrite) # # im.save(buffer) # # What if png doesn't support some image features like animation? # im.save(buffer, 'ppm') # bytes_io = BytesIO() # bytes_io.write(buffer.data()) # buffer.close() # bytes_io.seek(0) # return Image.open(bytes_io)
Example #24
Source File: guardarImagen.py From PyQt5 with MIT License | 4 votes |
def Guardar(self): # Obtener el nombre de usuario y la foto nombre = " ".join(self.lineEditNombre.text().split()).title() foto = self.labelImagen.pixmap() if foto: # Convertir la foto al tipo de dato adecuado bArray = QByteArray() bufer = QBuffer(bArray) bufer.open(QIODevice.WriteOnly) bufer.close() foto.save(bufer, "PNG") else: bArray = "" if nombre and bArray: # Establecer conexión con la base de datos conexion = connect("DB_USUARIOS.db") cursor = conexion.cursor() # Crear tabla, si no existe cursor.execute("CREATE TABLE IF NOT EXISTS Usuarios (NOMBRE TEXT, FOTO BLOB)") conexion.commit() # Verificar que el usuario no exista if cursor.execute("SELECT * FROM Usuarios WHERE NOMBRE = ?", (nombre,)).fetchone(): print("El usaurio {} ya existe.".format(nombre)) else: #Guardar en la base de datos, el nombre de usuario y la foto cursor.execute("INSERT INTO Usuarios VALUES (?,?)", (nombre, bArray)) conexion.commit() self.labelImagen.clear() self.lineEditNombre.clear() print("Usuario guardado con éxito.") # Cerrar la conexión con la base de datos conexion.close() self.lineEditNombre.setFocus() else: self.lineEditNombre.setFocus() # ================================================================
Example #25
Source File: displaymod.py From ddt4all with GNU General Public License v3.0 | 4 votes |
def get_zip_graphic(self, name): if os.path.exists("ecu.zip"): zf = zipfile.ZipFile("ecu.zip", "r") zname = "graphics/" + name + ".gif" if not zname in zf.namelist(): zname = "graphics/" + name + ".GIF" if zname in zf.namelist(): ba = core.QByteArray(zf.read(zname)) self.buffer = core.QBuffer() self.buffer.setData(ba) self.buffer.open(core.QIODevice.ReadOnly) self.img = gui.QMovie(self.buffer, 'GIF')
Example #26
Source File: webenginequtescheme.py From qutebrowser with GNU General Public License v3.0 | 4 votes |
def requestStarted(self, job): """Handle a request for a qute: scheme. This method must be reimplemented by all custom URL scheme handlers. The request is asynchronous and does not need to be handled right away. Args: job: QWebEngineUrlRequestJob """ url = job.requestUrl() if url.scheme() in ['chrome-error', 'chrome-extension']: # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-63378 job.fail(QWebEngineUrlRequestJob.UrlInvalid) return if not self._check_initiator(job): return if job.requestMethod() != b'GET': job.fail(QWebEngineUrlRequestJob.RequestDenied) return assert url.scheme() == 'qute' log.network.debug("Got request for {}".format(url.toDisplayString())) try: mimetype, data = qutescheme.data_for_url(url) except qutescheme.Error as e: errors = { qutescheme.NotFoundError: QWebEngineUrlRequestJob.UrlNotFound, qutescheme.UrlInvalidError: QWebEngineUrlRequestJob.UrlInvalid, qutescheme.RequestDeniedError: QWebEngineUrlRequestJob.RequestDenied, qutescheme.SchemeOSError: QWebEngineUrlRequestJob.UrlNotFound, qutescheme.Error: QWebEngineUrlRequestJob.RequestFailed, } exctype = type(e) log.network.error("{} while handling qute://* URL".format( exctype.__name__)) job.fail(errors[exctype]) except qutescheme.Redirect as e: qtutils.ensure_valid(e.url) job.redirect(e.url) else: log.network.debug("Returning {} data".format(mimetype)) # We can't just use the QBuffer constructor taking a QByteArray, # because that somehow segfaults... # https://www.riverbankcomputing.com/pipermail/pyqt/2016-September/038075.html buf = QBuffer(parent=self) buf.open(QIODevice.WriteOnly) buf.write(data) buf.seek(0) buf.close() job.reply(mimetype.encode('ascii'), buf)
Example #27
Source File: test_app.py From qutebrowser with GNU General Public License v3.0 | 4 votes |
def test_on_focus_changed_issue1484(monkeypatch, qapp, caplog): """Check what happens when on_focus_changed is called with wrong args. For some reason, Qt sometimes calls on_focus_changed() with a QBuffer as argument. Let's make sure we handle that gracefully. """ monkeypatch.setattr(app, 'q_app', qapp) buf = QBuffer() app.on_focus_changed(buf, buf) expected = "on_focus_changed called with non-QWidget {!r}".format(buf) assert caplog.messages == [expected]