本文整理汇总了Python中PyQt5.QtCore.QBuffer.size方法的典型用法代码示例。如果您正苦于以下问题:Python QBuffer.size方法的具体用法?Python QBuffer.size怎么用?Python QBuffer.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QBuffer
的用法示例。
在下文中一共展示了QBuffer.size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendMessage
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import size [as 别名]
def sendMessage(self):
textbuf = QBuffer()
textbuf.open(QBuffer.ReadWrite)
messageText = QDataStream(textbuf)
messageText << self.ui.messageBox.text
size = textbuf.size()
if not self.shareMemory.create(size):
return
size = min(self.shareMemory.size(), size)
self.sharedMemory.lock()
示例2: loadFromFile
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import size [as 别名]
def loadFromFile(self):
""" This slot function is called when the "Load Image From File..."
button is pressed on the firs Dialog process. First, it tests whether
the process is already connected to a shared memory segment and, if so,
detaches from that segment. This ensures that we always start the
example from the beginning if we run it multiple times with the same
two Dialog processes. After detaching from an existing shared memory
segment, the user is prompted to select an image file. The selected
file is loaded into a QImage. The QImage is displayed in the Dialog
and streamed into a QBuffer with a QDataStream. Next, it gets a new
shared memory segment from the system big enough to hold the image data
in the QBuffer, and it locks the segment to prevent the second Dialog
process from accessing it. Then it copies the image from the QBuffer
into the shared memory segment. Finally, it unlocks the shared memory
segment so the second Dialog process can access it. After self
function runs, the user is expected to press the "Load Image from
Shared Memory" button on the second Dialog process.
"""
if self.sharedMemory.isAttached():
self.detach()
self.ui.label.setText("Select an image file")
fileName, _ = QFileDialog.getOpenFileName(self, None, None,
"Images (*.png *.xpm *.jpg)")
image = QImage()
if not image.load(fileName):
self.ui.label.setText(
"Selected file is not an image, please select another.")
return
self.ui.label.setPixmap(QPixmap.fromImage(image))
# Load into shared memory.
buf = QBuffer()
buf.open(QBuffer.ReadWrite)
out = QDataStream(buf)
out << image
size = buf.size()
if not self.sharedMemory.create(size):
self.ui.label.setText("Unable to create shared memory segment.")
return
size = min(self.sharedMemory.size(), size)
self.sharedMemory.lock()
# Copy image data from buf into shared memory area.
self.sharedMemory.data()[:] = buf.data().data()
self.sharedMemory.unlock()