本文整理汇总了Python中PyQt4.QtCore.QDataStream.writeRawData方法的典型用法代码示例。如果您正苦于以下问题:Python QDataStream.writeRawData方法的具体用法?Python QDataStream.writeRawData怎么用?Python QDataStream.writeRawData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QDataStream
的用法示例。
在下文中一共展示了QDataStream.writeRawData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendMessage
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import writeRawData [as 别名]
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:
log.debug("Sending %s %s", msg, args)
elif self.player and self.player.name:
log.debug("Sending %s %s to %s", msg, args, self.player)
else:
log.debug("Sending %s %s to %s", msg, args, self.peerAddress().toString())
data = QByteArray()
stream = QDataStream(data, self.WriteOnly)
stream.writeInt32(int(msg))
for arg in args:
if type(arg) == str:
stream.writeInt32(len(arg))
stream.writeRawData(arg)
elif type(arg) == int:
stream.writeInt32(arg)
elif type(arg) == long:
stream.writeInt64(arg)
self.write(data)
self.messageSent.emit(msg, args)
示例2: send
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import writeRawData [as 别名]
def send(self, command, *args):
self._logger.info("GC<<: {}:{}".format(command, args))
ds = QDataStream(self._socket)
ds.setByteOrder(QDataStream.LittleEndian)
# Header
ds.writeUInt32(len(command))
ds.writeRawData(command.encode())
# Chunks
ds.writeUInt32(len(args))
for chunk in args:
ds.writeRawData(self._packLuaVal(chunk))
示例3: MainWindow
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import writeRawData [as 别名]
#.........这里部分代码省略.........
for color in images:
colors+=color
self.imgwidth = width
self.imgheight = height
self.bytesPerLine = int((self.gsLevel*self.imgwidth+31)/32)*4
self.writeNewHeader(colors)
pd = QProgressDialog('Writing file ...', 'Cancel', 0, self.imgheight-1, self)
pd.setWindowTitle('Creating file...')
pd.open()
tmp = 0
# Записывать данные будем построчно
for row in range(self.imgheight):
# обходим по порядку цветов, как расположены в файле
for color in colors:
# Добиваем строку до длины, кратной 32м байтам
for column in range (int(self.bytesPerLine/self.gsLevel*8)):
shift = 7-column+int(column/8)*8
pixel = 0
# Упорядочиваем уровни (на всякий)
levels = sorted(list(images[color].keys()))
# Если изображение меньше длины строки, то
if column < self.imgwidth:
for level in levels:
# Выбираем максимальный уровень из тех, что указаны в данном пикселе на всех слоях
if images[color][level].pixel(column, row) == self.black:
pixel = level
tmp |= (pixel<<shift*self.gsLevel)
# Как только сдвиг обнулится, то записываем в файл
if not shift:
self.out.writeRawData(tmp.to_bytes(self.gsLevel, 'big'))
tmp=0
pd.setValue(row)
if pd.wasCanceled():
pd.close()
file.close()
return
pd.close()
file.close()
self.status.showMessage("File created successful", 7000)
def writeNewHeader(self, colors):
xdpi = int(self.xdpiCmbBox.currentText())
ydpi = int(self.ydpiCmbBox.currentText())
self.paperWidth = 0
colorOrder = colors.encode()
while len(colorOrder) < 16:
colorOrder += bytes.fromhex('00')
self.out.writeInt32(self.NEW_RIP_FILE)
self.out.writeInt32(xdpi)
self.out.writeInt32(ydpi)
self.out.writeInt32(self.bytesPerLine)
self.out.writeInt32(self.imgheight)
self.out.writeInt32(self.imgwidth)
self.out.writeInt32(self.paperWidth)
self.out.writeInt32(len(colors))
self.out.writeInt32(self.gsLevel)