本文整理汇总了Python中PyQt5.QtCore.QBuffer.close方法的典型用法代码示例。如果您正苦于以下问题:Python QBuffer.close方法的具体用法?Python QBuffer.close怎么用?Python QBuffer.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QBuffer
的用法示例。
在下文中一共展示了QBuffer.close方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mouseMoveEvent
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import close [as 别名]
def mouseMoveEvent(self, event):
""" If the mouse moves far enough when the left mouse button is held
down, start a drag and drop operation.
"""
if not event.buttons() & Qt.LeftButton:
return
if (event.pos() - self.dragStartPosition).manhattanLength() \
< QApplication.startDragDistance():
return
if not self.hasImage:
return
drag = QDrag(self)
mimeData = QMimeData()
output = QByteArray()
outputBuffer = QBuffer(output)
outputBuffer.open(QIODevice.WriteOnly)
self.imageLabel.pixmap().toImage().save(outputBuffer, 'PNG')
outputBuffer.close()
mimeData.setData('image/png', output)
drag.setMimeData(mimeData)
drag.setPixmap(self.imageLabel.pixmap().scaled(64, 64, Qt.KeepAspectRatio))
drag.setHotSpot(QPoint(drag.pixmap().width() / 2,
drag.pixmap().height()))
drag.start()
示例2: requestStarted
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import close [as 别名]
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.misc.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.misc.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.misc.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)
示例3: scale
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import close [as 别名]
def scale(image, width, height):
edited = QImage.fromData(image.data, format_for(image.mime))
if edited.isNull():
return image
scaled = edited.scaled(width, height, Qt.KeepAspectRatio, Qt.SmoothTransformation)
buffer = QBuffer()
buffer.open(QIODevice.WriteOnly)
scaled.save(buffer, format_for(image.mime))
buffer.close()
return Image(mime=image.mime, data=buffer.data(), desc=image.desc, type_=image.type)
示例4: sendDeleteRequest
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import close [as 别名]
def sendDeleteRequest(self, endpoint, data={}, params={}, headers={}):
buff = QBuffer()
buff.open(QBuffer.ReadWrite)
d = json.dumps(data).encode('utf-8')
buff.write(d)
buff.seek(0)
headers.update({"Content-Type":"application/json"})
content = self.sendRequest( endpoint, params,
'delete',
buff,
headers=headers
)
buff.close()
return content
示例5: fromqimage
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import close [as 别名]
def fromqimage(im):
buffer = QBuffer()
buffer.open(QIODevice.ReadWrite)
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 PIL.Image.open(b)
示例6: createData
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import close [as 别名]
def createData(self, mimeType):
if mimeType != 'image/png':
return
image = QImage(self.imageLabel.size(), QImage.Format_RGB32)
painter = QPainter()
painter.begin(image)
self.imageLabel.renderer().render(painter)
painter.end()
data = QByteArray()
buffer = QBuffer(data)
buffer.open(QIODevice.WriteOnly)
image.save(buffer, 'PNG')
buffer.close()
self.mimeData.setData('image/png', data)
示例7: requestStarted
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import close [as 别名]
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()
assert job.requestMethod() == b'GET'
assert url.scheme() == 'qute'
log.misc.debug("Got request for {}".format(url.toDisplayString()))
try:
mimetype, data = qutescheme.data_for_url(url)
except qutescheme.NoHandlerFound:
log.misc.debug("No handler found for {}".format(
url.toDisplayString()))
job.fail(QWebEngineUrlRequestJob.UrlNotFound)
except qutescheme.QuteSchemeOSError:
# FIXME:qtwebengine how do we show a better error here?
log.misc.exception("OSError while handling qute://* URL")
job.fail(QWebEngineUrlRequestJob.UrlNotFound)
except qutescheme.QuteSchemeError:
# FIXME:qtwebengine how do we show a better error here?
log.misc.exception("Error while handling qute://* URL")
job.fail(QWebEngineUrlRequestJob.RequestFailed)
except qutescheme.Redirect as e:
qtutils.ensure_valid(e.url)
job.redirect(e.url)
else:
log.misc.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)
示例8: fromqimage
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import close [as 别名]
def fromqimage(im):
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)
示例9: fromqimage
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import close [as 别名]
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)
示例10: HexEditChunks
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import close [as 别名]
class HexEditChunks(object):
"""
Class implementing the storage backend for the hex editor.
When HexEditWidget loads data, HexEditChunks access them using a QIODevice
interface. When the app uses a QByteArray or Python bytearray interface,
QBuffer is used to provide again a QIODevice like interface. No data will
be changed, therefore HexEditChunks opens the QIODevice in
QIODevice.ReadOnly mode. After every access HexEditChunks closes the
QIODevice. That's why external applications can overwrite files while
HexEditWidget shows them.
When the the user starts to edit the data, HexEditChunks creates a local
copy of a chunk of data (4 kilobytes) and notes all changes there. Parallel
to that chunk, there is a second chunk, which keeps track of which bytes
are changed and which are not.
"""
BUFFER_SIZE = 0x10000
CHUNK_SIZE = 0x1000
READ_CHUNK_MASK = 0xfffffffffffff000
def __init__(self, ioDevice=None):
"""
Constructor
@param ioDevice io device to get the data from
@type QIODevice
"""
self.__ioDevice = None
self.__pos = 0
self.__size = 0
self.__chunks = []
if ioDevice is None:
buf = QBuffer()
self.setIODevice(buf)
else:
self.setIODevice(ioDevice)
def setIODevice(self, ioDevice):
"""
Public method to set an io device to read the binary data from.
@param ioDevice io device to get the data from
@type QIODevice
@return flag indicating successful operation
@rtype bool
"""
self.__ioDevice = ioDevice
ok = self.__ioDevice.open(QIODevice.ReadOnly)
if ok:
# open successfully
self.__size = self.__ioDevice.size()
self.__ioDevice.close()
else:
# fallback is an empty buffer
self.__ioDevice = QBuffer()
self.__size = 0
self.__chunks = []
self.__pos = 0
return ok
def data(self, pos=0, maxSize=-1, highlighted=None):
"""
Public method to get data out of the chunks.
@param pos position to get bytes from
@type int
@param maxSize maximum amount of bytes to get
@type int
@param highlighted reference to a byte array storing highlighting info
@type bytearray
@return retrieved data
@rtype bytearray
"""
ioDelta = 0
chunkIdx = 0
chunk = HexEditChunk()
buffer = bytearray()
if highlighted is not None:
del highlighted[:]
if pos >= self.__size:
return buffer
if maxSize < 0:
maxSize = self.__size
elif (pos + maxSize) > self.__size:
maxSize = self.__size - pos
self.__ioDevice.open(QIODevice.ReadOnly)
while maxSize > 0:
chunk.absPos = sys.maxsize
chunksLoopOngoing = True
while chunkIdx < len(self.__chunks) and chunksLoopOngoing:
#.........这里部分代码省略.........