本文整理汇总了Python中PyQt4.QtCore.QBuffer.buffer方法的典型用法代码示例。如果您正苦于以下问题:Python QBuffer.buffer方法的具体用法?Python QBuffer.buffer怎么用?Python QBuffer.buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QBuffer
的用法示例。
在下文中一共展示了QBuffer.buffer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_to_bytes
# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import buffer [as 别名]
def render_to_bytes(self, url):
"""Renders the image into an object of type 'str'"""
format = self.format # this may not be constant due to processEvents()
image = self.render(url)
qBuffer = QBuffer()
image.save(qBuffer, format)
return qBuffer.buffer().data()
示例2: render_to_file
# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import buffer [as 别名]
def render_to_file(self, url, file_object):
"""Renders the image into a File resource.
Returns the size of the data that has been written.
"""
format = self.format # this may not be constant due to processEvents()
image = self.render(url)
qBuffer = QBuffer()
image.save(qBuffer, format, quality=self.quality)
file_object.write(qBuffer.buffer().data())
return qBuffer.size()
示例3: grab_svg
# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import buffer [as 别名]
def grab_svg(scene):
"""
Return a SVG rendering of the scene contents.
Parameters
----------
scene : :class:`CanvasScene`
"""
from PyQt4.QtSvg import QSvgGenerator
svg_buffer = QBuffer()
gen = QSvgGenerator()
gen.setOutputDevice(svg_buffer)
items_rect = scene.itemsBoundingRect().adjusted(-10, -10, 10, 10)
if items_rect.isNull():
items_rect = QRectF(0, 0, 10, 10)
width, height = items_rect.width(), items_rect.height()
rect_ratio = float(width) / height
# Keep a fixed aspect ratio.
aspect_ratio = 1.618
if rect_ratio > aspect_ratio:
height = int(height * rect_ratio / aspect_ratio)
else:
width = int(width * aspect_ratio / rect_ratio)
target_rect = QRectF(0, 0, width, height)
source_rect = QRectF(0, 0, width, height)
source_rect.moveCenter(items_rect.center())
gen.setSize(target_rect.size().toSize())
gen.setViewBox(target_rect)
painter = QPainter(gen)
# Draw background.
painter.setBrush(QBrush(Qt.white))
painter.drawRect(target_rect)
# Render the scene
scene.render(painter, target_rect, source_rect)
painter.end()
buffer_str = str(svg_buffer.buffer())
return unicode(buffer_str.decode("utf-8"))
示例4: capture_to_buf
# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import buffer [as 别名]
def capture_to_buf(self, selector=None):
"""capture the images of selector to StringIO
@param selector: Css selector.
@return: The StringIO list.
"""
images = self.capture(selector)
result = []
for image in images:
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QIODevice.ReadWrite)
image.save(buf, 'jpg')
stream = StringIO(str(buf.buffer()))
result.append(stream)
return result
示例5: createRequest
# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import buffer [as 别名]
def createRequest(self, op, request, outgoingData = None):
"""
Protected method to create a request.
@param op the operation to be performed (QNetworkAccessManager.Operation)
@param request reference to the request object (QNetworkRequest)
@param outgoingData reference to an IODevice containing data to be sent
(QIODevice)
@return reference to the created reply object (QNetworkReply)
"""
if request.url().toString() == "pyrc:home":
html = startPage_html
pixmap = UI.PixmapCache.getPixmap("ericWeb32.png")
imageBuffer = QBuffer()
imageBuffer.open(QIODevice.ReadWrite)
if pixmap.save(imageBuffer, "PNG"):
html.replace("IMAGE_BINARY_DATA_HERE",
QString(imageBuffer.buffer().toBase64()))
return NetworkReply(request, html.toUtf8(), "text/html", self.parent())
return NetworkProtocolUnknownErrorReply("pyrc", self.parent())
示例6: embed
# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import buffer [as 别名]
def embed(im):
"""Converts a QImage or QPicture object into an ipython Image object for
embedding into an ipython notebook.
"""
if isinstance(im, QPicture):
pic = im
im = QImage(im.width(), im.height(), QImage.Format_ARGB32_Premultiplied)
p = QPainter()
p.begin(im)
p.drawPicture(0, 0, pic)
p.end()
w = QImageWriter()
buf = QBuffer()
buf.open(buf.WriteOnly)
w.setFormat("png")
w.setDevice(buf)
w.write(im)
return Image(data=str(buf.buffer()), format="png", embed=True)