本文整理汇总了Python中PyQt4.Qt.QBuffer.close方法的典型用法代码示例。如果您正苦于以下问题:Python QBuffer.close方法的具体用法?Python QBuffer.close怎么用?Python QBuffer.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QBuffer
的用法示例。
在下文中一共展示了QBuffer.close方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_screen_by_qt
# 需要导入模块: from PyQt4.Qt import QBuffer [as 别名]
# 或者: from PyQt4.Qt.QBuffer import close [as 别名]
def get_screen_by_qt(self, x1=None, y1=None, x2=None, y2=None):
from PyQt4.QtGui import QPixmap, QApplication
from PyQt4.Qt import QBuffer, QIODevice
import StringIO
app = QApplication(sys.argv)
_buffer = QBuffer()
_buffer.open(QIODevice.ReadWrite)
desktop = QApplication.desktop()
#width = desktop.screenGeometry().width()
#height = desktop.screenGeometry().height()
if x1 is None:
x1 = 0
if y1 is None:
y1 = 0
if x2 is None:
x2 = -1
else:
x2 -= x1
if y2 is None:
y2 = -1
else:
y2 -= y1
QPixmap.grabWindow(desktop.winId(), x1, y1, x2, y2) \
.save(_buffer, 'png')
strio = StringIO.StringIO()
strio.write(_buffer.data())
_buffer.close()
del app
strio.seek(0)
return Image.open(strio)
示例2: OpenGazer
# 需要导入模块: from PyQt4.Qt import QBuffer [as 别名]
# 或者: from PyQt4.Qt.QBuffer import close [as 别名]
class OpenGazer(object):
def __init__(self, dir_pub, socket_opengazer_c):
self.ctx_zmq = zmq.Context()
self.socket = self.ctx_zmq.socket(zmq.PUB)
self.socket.bind(dir_pub)
self.socket_opengazer_c = socket_opengazer_c
self.app = QApplication(sys.argv)
self.buffer = QBuffer()
def get_screen(self):
self.buffer.open(QIODevice.ReadWrite)
QPixmap.grabWindow(QApplication.desktop().winId()).scaled(480, 240).save(self.buffer, 'jpeg', quality=50)
self.strio = StringIO()
self.strio.write(self.buffer.data())
self.buffer.close()
self.strio.seek(0)
def send_data(self):
my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
my_socket.bind(("", self.socket_opengazer_c))
print("socket creado")
while True:
data, addr = my_socket.recvfrom(self.socket_opengazer_c)
self.get_screen()
image_data = base64.b64encode(self.strio.getvalue())
data_to_send = {'screen': image_data, 'x': int(data.split(' ')[0]),
'y': int(data.split(' ')[1]), 'target': int(data.split(' ')[2])}
message = json.dumps(data_to_send)
self.socket.send(message)
#self.app.processEvents()
my_socket.close() # todo poner en finally
示例3: grab_to_buffer
# 需要导入模块: from PyQt4.Qt import QBuffer [as 别名]
# 或者: from PyQt4.Qt.QBuffer import close [as 别名]
def grab_to_buffer(self, buffer, file_type='png'):
if not self.app:
self.app = QApplication([])
qbuffer = QBuffer()
qbuffer.open(QIODevice.ReadWrite)
QPixmap.grabWindow(QApplication.desktop().winId()).save(qbuffer, file_type)
buffer.write(qbuffer.data())
qbuffer.close()
示例4: image_to_data
# 需要导入模块: from PyQt4.Qt import QBuffer [as 别名]
# 或者: from PyQt4.Qt.QBuffer import close [as 别名]
def image_to_data(image): # {{{
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QBuffer.WriteOnly)
if not image.save(buf, CACHE_FORMAT):
raise EncodeError('Failed to encode thumbnail')
ret = bytes(ba.data())
buf.close()
return ret
示例5: getScreenByQt
# 需要导入模块: from PyQt4.Qt import QBuffer [as 别名]
# 或者: from PyQt4.Qt.QBuffer import close [as 别名]
def getScreenByQt(self):
from PyQt4.QtGui import QPixmap, QApplication
from PyQt4.Qt import QBuffer, QIODevice
import StringIO
app = QApplication(sys.argv)
buffer = QBuffer()
buffer.open(QIODevice.ReadWrite)
QPixmap.grabWindow(QApplication.desktop().winId()).save(buffer, 'png')
strio = StringIO.StringIO()
strio.write(buffer.data())
buffer.close()
del app
strio.seek(0)
return Image.open(strio)
示例6: _repr_png_
# 需要导入模块: from PyQt4.Qt import QBuffer [as 别名]
# 或者: from PyQt4.Qt.QBuffer import close [as 别名]
def _repr_png_(self):
self.show()
self.hide()
if not self.btn.visible:
display(self.btn)
self.btn.visible = True
mainExp = ImageExporter(self.plotItem)
self.image = mainExp.export(toBytes=True)
byte_array = QByteArray()
buffer = QBuffer(byte_array)
buffer.open(QIODevice.ReadWrite)
self.image.save(buffer, 'PNG')
buffer.close()
return bytes(byte_array)
示例7: peek_qt
# 需要导入模块: from PyQt4.Qt import QBuffer [as 别名]
# 或者: from PyQt4.Qt.QBuffer import close [as 别名]
def peek_qt(fmt="png"):
"""Takes a screenshot using QT."""
import sys
from PyQt4.QtGui import QPixmap, QApplication
from PyQt4.Qt import QBuffer, QIODevice
app = QApplication(sys.argv)
buff = QBuffer()
buff.open(QIODevice.ReadWrite)
QPixmap.grabWindow(QApplication.desktop().winId()).save(buff, fmt)
screenshot = Screenshot()
screenshot.addvalue(buff.data())
buff.close()
del app
screenshot.fmt = fmt
return screenshot
示例8: _repr_png_
# 需要导入模块: from PyQt4.Qt import QBuffer [as 别名]
# 或者: from PyQt4.Qt.QBuffer import close [as 别名]
def _repr_png_(self):
self._widget.hide()
QtGui.QApplication.processEvents()
try:
self.image = QImage(self._widget.viewRect().size().toSize(),
QImage.Format_RGB32)
except AttributeError:
self._widget.updateGL()
self.image = self._widget.grabFrameBuffer()
painter = QPainter(self.image)
self._widget.render(painter)
byte_array = QByteArray()
buffer = QBuffer(byte_array)
buffer.open(QIODevice.ReadWrite)
self.image.save(buffer, 'PNG')
buffer.close()
return bytes(byte_array)