本文整理汇总了Python中PyQt5.QtCore.QByteArray方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QByteArray方法的具体用法?Python QtCore.QByteArray怎么用?Python QtCore.QByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore
的用法示例。
在下文中一共展示了QtCore.QByteArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: capture
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def capture(self, fullScreen = False, filename = ''):
if fullScreen:
image = QApplication.primaryScreen().grabWindow(0)
else:
image = QImage(self.webView.mainFrame.contentsSize(), QImage.Format_ARGB32)
painter = QPainter(image)
self.webView.mainFrame.render(painter)
painter.end()
if filename:
return image.save(filename)
else:
data = QByteArray()
buffer = QBuffer(data)
buffer.open(QBuffer.WriteOnly)
image.save(buffer, 'PNG')
return bytes(data.toBase64()).decode()
# 打开开发者工具
示例2: resize_image
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
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()
示例3: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self._stream_buffer = QByteArray()
self._stream_buffer_start_index = -1
self._network_manager = None # type: QNetworkAccessManager
self._image_request = None # type: QNetworkRequest
self._image_reply = None # type: QNetworkReply
self._image = QImage()
self._image_rect = QRect()
self._source_url = QUrl()
self._started = False
self._mirror = False
self.setAntialiasing(True)
示例4: stop
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def stop(self) -> None:
self._stream_buffer = QByteArray()
self._stream_buffer_start_index = -1
if self._image_reply:
try:
try:
self._image_reply.downloadProgress.disconnect(self._onStreamDownloadProgress)
except Exception:
pass
if not self._image_reply.isFinished():
self._image_reply.close()
except Exception: # RuntimeError
pass # It can happen that the wrapped c++ object is already deleted.
self._image_reply = None
self._image_request = None
self._network_manager = None
self._started = False
示例5: _receive
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def _receive(self):
"""
Called by the sockets readyRead signal. Not intended for outside use.
While there are messages available read them and process them.
Reading is reading of a QByteArray from the TCPSocket, un-compressing and de-serializing.
"""
while self.socket.bytesAvailable() > 0:
logger.info('socket will receive')
# read a QByteArray using a data stream
reader = QtCore.QDataStream(self.socket)
bytearray = QtCore.QByteArray()
reader >> bytearray
# uncompress bytes from bytearray
uncompressed = zlib.decompress(bytearray.data())
# security validator (check for everything that we do not like (!!python)
# TODO implement this
# decode from utf-8 bytes to unicode and deserialize from yaml
value = yaml.load(uncompressed.decode())
logger.debug('socket received: %s', value)
self.received.emit(value)
示例6: send
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def send(self, value):
"""
Sends a message by serializing, compressing and wrapping to a QByteArray, then streaming over the TCP socket.
:param value: The message to send.
"""
if not self.is_connected():
raise RuntimeError('Try to send on unconnected socket.')
logger.debug('socket send: %s', value)
# serialize value to yaml
stream = StringIO()
yaml.dump(value, stream)
serialized = stream.getvalue()
# encode to utf-8 bytes and compress
compressed = zlib.compress(serialized.encode())
# wrap in QByteArray
bytearray = QtCore.QByteArray(compressed)
# write using a data stream
writer = QtCore.QDataStream(self.socket)
writer.setVersion(QtCore.QDataStream.Qt_5_5)
writer << bytearray
示例7: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def __init__(self, parent=None):
super(DragButton, self).__init__(parent)
# def mouseMoveEvent(self, event):
# self.startDrag()
# QtWidgets.QToolButton.mouseMoveEvent(self, event)
# def startDrag(self):
# if self.icon().isNull():
# return
# data = QtCore.QByteArray()
# stream = QtCore.QDataStream(data, QtCore.QIODevice.WriteOnly)
# stream << self.icon()
# mimeData = QtCore.QMimeData()
# mimeData.setData("application/x-equipment", data)
# drag = QtGui.QDrag(self)
# drag.setMimeData(mimeData)
# pixmap = self.icon().pixmap(24, 24)
# drag.setHotSpot(QtCore.QPoint(12, 12))
# drag.setPixmap(pixmap)
# drag.exec_(QtCore.Qt.CopyAction)
示例8: UpdateListItem
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
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())
示例9: loadResource
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def loadResource(self, rtype, url):
ret = super(TextBrowser, self).loadResource(rtype, url)
# 加载图片资源
if rtype == QTextDocument.ImageResource:
if ret:
return ret
if url.toString().startswith('irony'): # 自定义的协议头
print('加载本地', '../Donate/zhifubao.png', url)
return QImage('../Donate/zhifubao.png') # 或者 QByteArray(open('../Donate/zhifubao.png', 'rb').read())
elif url.toString().startswith('http'): # 加载网络图片
img, status = self.NetImages.get(url, [None, None])
if url not in self.NetImages or status is None:
# 子线程下载
self.NetImages[url] = [None, 1]
print('download ', url)
Thread(target=self.downloadImage, args=(url,), daemon=True).start()
elif img:
return img
return ret
示例10: stop
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def stop(self) -> None:
Logger.log("w", "MJPEG stopping stream...")
self._stream_buffer = QByteArray()
self._stream_buffer_start_index = -1
if self._image_reply:
try:
try:
self._image_reply.downloadProgress.disconnect(self._onStreamDownloadProgress)
except Exception:
pass
if not self._image_reply.isFinished():
self._image_reply.close()
except Exception as e: # RuntimeError
pass # It can happen that the wrapped c++ object is already deleted.
self._image_reply = None
self._image_request = None
self._network_manager = None
self._started = False
示例11: data
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def data(self, index, role=QtCore.Qt.DisplayRole):
if index.isValid():
if(role==QtCore.Qt.DisplayRole):
return self._data.values[index.row()][index.column()]
else:
# self._roleName 은 QHash(int, QByteArray)
columnName = self._roleNames[role].data().decode('utf8')
print('row {} col {} role {} columnName {} '.format(index.row(), index.column(), role, columnName))
print(self._data.at[index.row(), columnName])
return self._data.at[index.row(), columnName]
return QVariant()
示例12: headerData
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def headerData(self, col, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
return self._data.columns[col]
return None
# return 값은 QHash(int, QByteArray)
示例13: roleNames
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def roleNames(self):
for index, name in enumerate(self._data.columns):
self._roleNames[ QtCore.Qt.UserRole + index + 1] = QtCore.QByteArray(name.encode())
return self._roleNames
示例14: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def __init__(self, geometry, win_id, parent=None):
super().__init__(parent)
self._geometry = QByteArray(geometry)
self.win_id = win_id
示例15: retrieve_geometry
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QByteArray [as 别名]
def retrieve_geometry(self, name):
if name not in self._geometries:
return None
return QByteArray(bytes(self._geometries[name]))