本文整理汇总了Python中PyQt4.QtCore.QBuffer.size方法的典型用法代码示例。如果您正苦于以下问题:Python QBuffer.size方法的具体用法?Python QBuffer.size怎么用?Python QBuffer.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QBuffer
的用法示例。
在下文中一共展示了QBuffer.size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_to_file
# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import size [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()
示例2: Connection
# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import size [as 别名]
class Connection(QTcpSocket):
"""Abstracts server-client connections.
Whenever data is received, a Connection attempts to parse a Message and arguments from the data, and emits messageReceived for each parsed message. See QTcpSocket documentation for other members."""
messageSent = pyqtSignal(int, list)
"""Emitted whenever a message is sent. Arguments: the message type, list of arguments."""
messageReceived = pyqtSignal(int, list)
"""Emitted whenever a message is recieved. Arguments: the message type, list of arguments."""
messageReceived2 = pyqtSignal()
def __init__(self, id = None, client = False, parent = None):
"""Creates a connection.
id -- Optional socket descriptor.
client -- Whether this connection is opened from the client side or server side.
parent -- Parent object."""
QTcpSocket.__init__(self, parent)
if id:
if not self.setSocketDescriptor(id):
self.done()
return
self.id = id
self.player = None
self.client = client
self.buffer = QBuffer()
self.buffer.open(QBuffer.ReadWrite)
self.readyRead.connect(self._readIncomingData)
def abort(self):
"""Aborts the connection."""
super(Connection, self).abort()
def _readIncomingData(self):
bytesWritten = self.buffer.write(self.readAll())
self.buffer.seek(0)
result = self._parse()
bytesRead = 0
while result:
bytesRead += result[2]
msg, args = result[:2]
if self.client:
log.debug("Received %s %s", msg, args)
elif self.player and self.player.name:
log.debug("Received %s %s from %s", msg, args, self.player)
else:
log.debug("Received %s %s from %s", msg, args, self.peerAddress().toString())
self.messageReceived.emit(msg, args)
self.messageReceived2.emit()
result = self._parse()
#remove the successfully parsed data
size = self.buffer.size()
self.buffer.close()
data = self.buffer.data()
self.buffer.setData(data.right(size - bytesRead))
self.buffer.open(QBuffer.ReadWrite)
self.buffer.seek(self.buffer.size())
def _parse(self):
if self.buffer.bytesAvailable() >= 4:
stream = QDataStream(self.buffer)
msg = Message.fromInt(stream.readInt32())
if msg == None:
return
args = []
bytesRead = 4
for aType in msg.argTypes:
if aType == str:
if self.buffer.bytesAvailable() < 4:
return
length = stream.readInt32()
if self.buffer.bytesAvailable() < length:
return
args.append(stream.readRawData(length))
bytesRead += 4 + length
elif aType == int:
if self.buffer.bytesAvailable() < 4:
return
args.append(stream.readInt32())
bytesRead += 4
elif aType == long:
if self.buffer.bytesAvailable() < 8:
return
args.append(stream.readInt64())
bytesRead += 8
return (msg, args, bytesRead)
def sendMessage(self, msg, args, id = None):
"""Sends a message.
msg -- The message type.
args -- List of message arguments.
id -- An optional socket descriptor. If specified, then the message will only be sent if this connection's socket descriptor matches id."""
if id:
if self.socketDescriptor() != id:
return
msg = Message.fromInt(msg)
if not msg.validateArgs(args):
log.warning("Message %d and args %s have invalid types. Message not sent.", msg, args)
return
if self.client:
#.........这里部分代码省略.........