本文整理汇总了Python中PyQt5.QtCore.QByteArray.size方法的典型用法代码示例。如果您正苦于以下问题:Python QByteArray.size方法的具体用法?Python QByteArray.size怎么用?Python QByteArray.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QByteArray
的用法示例。
在下文中一共展示了QByteArray.size方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __sendGreetingMessage
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import size [as 别名]
def __sendGreetingMessage(self):
"""
Private slot to send a greeting message.
"""
greeting = QByteArray(self.__greetingMessage.encode("utf-8"))
data = QByteArray("{0}{1}{2}{1}".format(
Connection.ProtocolGreeting, SeparatorToken, greeting.size())
.encode("utf-8")) + greeting
if self.write(data) == data.size():
self.__isGreetingMessageSent = True
示例2: sendMessage
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import size [as 别名]
def sendMessage(self, message):
"""
Public method to send a message.
@param message message to be sent (string)
@return flag indicating a successful send (boolean)
"""
if message == "":
return False
msg = QByteArray(message.encode("utf-8"))
data = QByteArray("{0}{1}{2}{1}".format(
Connection.ProtocolMessage, SeparatorToken, msg.size())) + msg
return self.write(data) == data.size()
示例3: sendFortune
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import size [as 别名]
def sendFortune(self):
block = QByteArray()
out = QDataStream(block, QIODevice.WriteOnly)
out.setVersion(QDataStream.Qt_4_0)
out.writeUInt16(0)
out.writeQString(random.choice(self.fortunes))
out.device().seek(0)
out.writeUInt16(block.size() - 2)
clientConnection = self.server.nextPendingConnection()
clientConnection.disconnected.connect(clientConnection.deleteLater)
clientConnection.write(block)
clientConnection.flush()
clientConnection.disconnectFromServer()
示例4: sendEditorCommand
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import size [as 别名]
def sendEditorCommand(self, projectHash, filename, message):
"""
Public method to send an editor command.
@param projectHash hash of the project (string)
@param filename project relative universal file name of
the sending editor (string)
@param message editor command to be sent (string)
"""
msg = QByteArray("{0}{1}{2}{1}{3}".format(
projectHash, SeparatorToken, filename, message).encode("utf-8"))
data = QByteArray("{0}{1}{2}{1}".format(
Connection.ProtocolEditor, SeparatorToken, msg.size())) + msg
self.write(data)
示例5: sendParticipants
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import size [as 别名]
def sendParticipants(self, participants):
"""
Public method to send the list of participants.
@param participants list of participants (list of strings of
"host:port")
"""
if participants:
message = SeparatorToken.join(participants)
else:
message = "<empty>"
msg = QByteArray(message.encode("utf-8"))
data = QByteArray("{0}{1}{2}{1}".format(
Connection.ProtocolParticipants, SeparatorToken, msg.size())) + msg
self.write(data)
示例6: sendFortune
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import size [as 别名]
def sendFortune(self):
fortune = self.FORTUNES[random.randint(0, len(self.FORTUNES) - 1)]
block = QByteArray()
out = QDataStream(block, QIODevice.WriteOnly)
out.setVersion(QDataStream.Qt_4_0)
out.writeUInt16(0)
out.writeQString(fortune)
out.device().seek(0)
out.writeUInt16(block.size() - 2)
clientConnection = self.tcpServer.nextPendingConnection()
clientConnection.disconnected.connect(clientConnection.deleteLater)
clientConnection.write(block)
clientConnection.disconnectFromHost()
示例7: run
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import size [as 别名]
def run(self):
tcpSocket = QTcpSocket()
if not tcpSocket.setSocketDescriptor(self.socketDescriptor):
self.error.emit(tcpSocket.error())
return
block = QByteArray()
outstr = QDataStream(block, QIODevice.WriteOnly)
outstr.setVersion(QDataStream.Qt_4_0)
outstr.writeUInt16(0)
outstr.writeQString(self.text)
outstr.device().seek(0)
outstr.writeUInt16(block.size() - 2)
tcpSocket.write(block)
tcpSocket.disconnectFromHost()
tcpSocket.waitForDisconnected()
示例8: Generator
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import size [as 别名]
class Generator(QIODevice):
def __init__(self, format, durationUs, sampleRate, parent):
super(Generator, self).__init__(parent)
self.m_pos = 0
self.m_buffer = QByteArray()
self.generateData(format, durationUs, sampleRate)
def start(self):
self.open(QIODevice.ReadOnly)
def stop(self):
self.m_pos = 0
self.close()
def generateData(self, format, durationUs, sampleRate):
pack_format = ''
if format.sampleSize() == 8:
if format.sampleType() == QAudioFormat.UnSignedInt:
scaler = lambda x: ((1.0 + x) / 2 * 255)
pack_format = 'B'
elif format.sampleType() == QAudioFormat.SignedInt:
scaler = lambda x: x * 127
pack_format = 'b'
elif format.sampleSize() == 16:
if format.sampleType() == QAudioFormat.UnSignedInt:
scaler = lambda x: (1.0 + x) / 2 * 65535
pack_format = '<H' if format.byteOrder() == QAudioFormat.LittleEndian else '>H'
elif format.sampleType() == QAudioFormat.SignedInt:
scaler = lambda x: x * 32767
pack_format = '<h' if format.byteOrder() == QAudioFormat.LittleEndian else '>h'
assert(pack_format != '')
channelBytes = format.sampleSize() // 8
sampleBytes = format.channelCount() * channelBytes
length = (format.sampleRate() * format.channelCount() * (format.sampleSize() // 8)) * durationUs // 100000
self.m_buffer.clear()
sampleIndex = 0
factor = 2 * pi * sampleRate / format.sampleRate()
while length != 0:
x = sin((sampleIndex % format.sampleRate()) * factor)
packed = pack(pack_format, int(scaler(x)))
for _ in range(format.channelCount()):
self.m_buffer.append(packed)
length -= channelBytes
sampleIndex += 1
def readData(self, maxlen):
data = QByteArray()
total = 0
while maxlen > total:
chunk = min(self.m_buffer.size() - self.m_pos, maxlen - total)
data.append(self.m_buffer.mid(self.m_pos, chunk))
self.m_pos = (self.m_pos + chunk) % self.m_buffer.size()
total += chunk
return data.data()
def writeData(self, data):
return 0
def bytesAvailable(self):
return self.m_buffer.size() + super(Generator, self).bytesAvailable()
示例9: FtpReply
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import size [as 别名]
class FtpReply(QNetworkReply):
"""
Class implementing a network reply for FTP resources.
"""
def __init__(self, url, accessHandler, parent=None):
"""
Constructor
@param url requested FTP URL (QUrl)
@param accessHandler reference to the access handler (FtpAccessHandler)
@param parent reference to the parent object (QObject)
"""
super(FtpReply, self).__init__(parent)
self.__manager = parent
self.__handler = accessHandler
self.__ftp = E5Ftp()
self.__items = []
self.__content = QByteArray()
self.__units = ["Bytes", "KB", "MB", "GB", "TB",
"PB", "EB", "ZB", "YB"]
self.__dirLineParser = FtpDirLineParser()
self.__fileBytesReceived = 0
if url.path() == "":
url.setPath("/")
self.setUrl(url)
# do proxy setup
if not Preferences.getUI("UseProxy"):
proxyType = E5FtpProxyType.NoProxy
else:
proxyType = Preferences.getUI("ProxyType/Ftp")
if proxyType != E5FtpProxyType.NoProxy:
self.__ftp.setProxy(
proxyType,
Preferences.getUI("ProxyHost/Ftp"),
Preferences.getUI("ProxyPort/Ftp"))
if proxyType != E5FtpProxyType.NonAuthorizing:
self.__ftp.setProxyAuthentication(
Preferences.getUI("ProxyUser/Ftp"),
Preferences.getUI("ProxyPassword/Ftp"),
Preferences.getUI("ProxyAccount/Ftp"))
QTimer.singleShot(0, self.__doFtpCommands)
def abort(self):
"""
Public slot to abort the operation.
"""
# do nothing
pass
def bytesAvailable(self):
"""
Public method to determined the bytes available for being read.
@return bytes available (integer)
"""
return self.__content.size()
def isSequential(self):
"""
Public method to check for sequential access.
@return flag indicating sequential access (boolean)
"""
return True
def readData(self, maxlen):
"""
Public method to retrieve data from the reply object.
@param maxlen maximum number of bytes to read (integer)
@return string containing the data (bytes)
"""
if self.__content.size():
len_ = min(maxlen, self.__content.size())
buffer = bytes(self.__content[:len_])
self.__content.remove(0, len_)
return buffer
def __doFtpCommands(self):
"""
Private slot doing the sequence of FTP commands to get the requested
result.
"""
retry = True
try:
username = self.url().userName()
password = self.url().password()
byAuth = False
while retry:
try:
self.__ftp.connect(self.url().host(),
self.url().port(ftplib.FTP_PORT),
timeout=10)
#.........这里部分代码省略.........
示例10: FileReply
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import size [as 别名]
class FileReply(QNetworkReply):
"""
Class implementing a network reply for directory resources.
"""
def __init__(self, url, parent=None):
"""
Constructor
@param url requested FTP URL (QUrl)
@param parent reference to the parent object (QObject)
"""
super(FileReply, self).__init__(parent)
self.__content = QByteArray()
self.__units = ["Bytes", "KB", "MB", "GB", "TB",
"PB", "EB", "ZB", "YB"]
if url.path() == "":
url.setPath("/")
self.setUrl(url)
QTimer.singleShot(0, self.__loadDirectory)
def abort(self):
"""
Public slot to abort the operation.
"""
# do nothing
pass
def bytesAvailable(self):
"""
Public method to determined the bytes available for being read.
@return bytes available (integer)
"""
return self.__content.size()
def isSequential(self):
"""
Public method to check for sequential access.
@return flag indicating sequential access (boolean)
"""
return True
def readData(self, maxlen):
"""
Public method to retrieve data from the reply object.
@param maxlen maximum number of bytes to read (integer)
@return string containing the data (bytes)
"""
if self.__content.size():
len_ = min(maxlen, self.__content.size())
buffer = bytes(self.__content[:len_])
self.__content.remove(0, len_)
return buffer
def __cssLinkClass(self, icon, size=32):
"""
Private method to generate a link class with an icon.
@param icon icon to be included (QIcon)
@param size size of the icon to be generated (integer)
@return CSS class string (string)
"""
cssString = \
"""a.{{0}} {{{{\n"""\
""" padding-left: {0}px;\n"""\
""" background: transparent url(data:image/png;base64,{1})"""\
""" no-repeat center left;\n"""\
""" font-weight: bold;\n"""\
"""}}}}\n"""
pixmap = icon.pixmap(size, size)
imageBuffer = QBuffer()
imageBuffer.open(QIODevice.ReadWrite)
if not pixmap.save(imageBuffer, "PNG"):
# write a blank pixmap on error
pixmap = QPixmap(size, size)
pixmap.fill(Qt.transparent)
imageBuffer.buffer().clear()
pixmap.save(imageBuffer, "PNG")
return cssString.format(
size + 4,
str(imageBuffer.buffer().toBase64(), encoding="ascii"))
def __loadDirectory(self):
"""
Private slot loading the directory and preparing the listing page.
"""
dir = QDir(self.url().toLocalFile())
dirItems = dir.entryInfoList(
QDir.AllEntries | QDir.Hidden | QDir.NoDotAndDotDot,
QDir.Name | QDir.DirsFirst)
u = self.url()
if not u.path().endswith("/"):
u.setPath(u.path() + "/")
#.........这里部分代码省略.........
示例11: Connection
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import size [as 别名]
#.........这里部分代码省略.........
@return server port (integer)
"""
return self.__serverPort
def setClient(self, client):
"""
Public method to set the reference to the cooperation client.
@param client reference to the cooperation client (CooperationClient)
"""
self.__client = client
def setGreetingMessage(self, message, serverPort):
"""
Public method to set the greeting message.
@param message greeting message (string)
@param serverPort port number to include in the message (integer)
"""
self.__greetingMessage = "{0}:{1}".format(message, serverPort)
def sendMessage(self, message):
"""
Public method to send a message.
@param message message to be sent (string)
@return flag indicating a successful send (boolean)
"""
if message == "":
return False
msg = QByteArray(message.encode("utf-8"))
data = QByteArray("{0}{1}{2}{1}".format(
Connection.ProtocolMessage, SeparatorToken, msg.size())
.encode("utf-8")) + msg
return self.write(data) == data.size()
def timerEvent(self, evt):
"""
Protected method to handle timer events.
@param evt reference to the timer event (QTimerEvent)
"""
if evt.timerId() == self.__transferTimerId:
self.abort()
self.killTimer(self.__transferTimerId)
self.__transferTimerId = 0
def __processReadyRead(self):
"""
Private slot to handle the readyRead signal.
"""
if self.__state == Connection.WaitingForGreeting:
if not self.__readProtocolHeader():
return
if self.__currentDataType != Connection.Greeting:
self.abort()
return
self.__state = Connection.ReadingGreeting
if self.__state == Connection.ReadingGreeting:
if not self.__hasEnoughData():
return
self.__buffer = QByteArray(
self.read(self.__numBytesForCurrentDataType))