本文整理汇总了Python中PyQt5.QtCore.QIODevice.WriteOnly方法的典型用法代码示例。如果您正苦于以下问题:Python QIODevice.WriteOnly方法的具体用法?Python QIODevice.WriteOnly怎么用?Python QIODevice.WriteOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QIODevice
的用法示例。
在下文中一共展示了QIODevice.WriteOnly方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendFortune
# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import WriteOnly [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()
示例2: capture
# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import WriteOnly [as 别名]
def capture(self, url):
print('--load')
self.load(QUrl(url))
self.wait_load()
self.show()
size = self.page().contentsSize()
self.page().view().resize(*[int(s) for s in [size.width(), size.height()]])
print('--take image')
image = QImage(800, 800, QImage.Format_ARGB32)
painter = QPainter(image)
print('--render')
self.page().view().render(painter)
painter.end()
print('Saving QImage')
img_bytes = QByteArray()
bio = QBuffer(img_bytes)
bio.open(QIODevice.WriteOnly)
image.save(bio, 'PNG')
return img_bytes
示例3: send_message
# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import WriteOnly [as 别名]
def send_message(self, message):
if not self.is_running:
raise Exception("Client cannot connect to IPC server. Not running.")
socket = QLocalSocket(self)
socket.connectToServer(self.socket_filename, QIODevice.WriteOnly)
if not socket.waitForConnected(self.timeout):
raise Exception(str(socket.errorString()))
socket.write(pickle.dumps(message))
if not socket.waitForBytesWritten(self.timeout):
raise Exception(str(socket.errorString()))
socket.disconnectFromServer()
示例4: save
# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import WriteOnly [as 别名]
def save(self):
content = self.centralWidget.plainTextEdit.toPlainText()
fileName, _ = QFileDialog.getSaveFileName(self)
if fileName:
fd = QFile(fileName)
if not fd.open(QIODevice.WriteOnly):
QMessageBox.information(self, "Unable to open file",
fd.errorString())
return
QTextStream(fd) << content
示例5: downloadFile
# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import WriteOnly [as 别名]
def downloadFile(self):
self.url = QUrl(self.urlLineEdit.text())
fileInfo = QFileInfo(self.url.path())
fileName = fileInfo.fileName()
if not fileName:
fileName = 'index.html'
if QFile.exists(fileName):
ret = QMessageBox.question(self, "HTTP",
"There already exists a file called %s in the current "
"directory. Overwrite?" % fileName,
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if ret == QMessageBox.No:
return
QFile.remove(fileName)
self.outFile = QFile(fileName)
if not self.outFile.open(QIODevice.WriteOnly):
QMessageBox.information(self, "HTTP",
"Unable to save the file %s: %s." % (fileName, self.outFile.errorString()))
self.outFile = None
return
self.progressDialog.setWindowTitle("HTTP")
self.progressDialog.setLabelText("Downloading %s." % fileName)
self.downloadButton.setEnabled(False)
self.httpRequestAborted = False
self.startRequest(self.url)
示例6: sendFortune
# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import WriteOnly [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()
示例7: httpFinished
# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import WriteOnly [as 别名]
def httpFinished(self):
if self.httpRequestAborted:
if self.outFile is not None:
self.outFile.close()
self.outFile.remove()
self.outFile = None
self.reply.deleteLater()
self.reply = None
self.progressDialog.hide()
return
self.progressDialog.hide()
self.outFile.flush()
self.outFile.close()
redirectionTarget = self.reply.attribute(QNetworkRequest.RedirectionTargetAttribute)
if self.reply.error():
self.outFile.remove()
QMessageBox.information(self, "HTTP",
"Download failed: %s." % self.reply.errorString())
self.downloadButton.setEnabled(True)
elif redirectionTarget is not None:
newUrl = self.url.resolved(redirectionTarget)
ret = QMessageBox.question(self, "HTTP",
"Redirect to %s?" % newUrl.toString(),
QMessageBox.Yes | QMessageBox.No)
if ret == QMessageBox.Yes:
self.url = newUrl
self.reply.deleteLater()
self.reply = None
self.outFile.open(QIODevice.WriteOnly)
self.outFile.resize(0)
self.startRequest(self.url)
return
else:
fileName = QFileInfo(QUrl(self.urlLineEdit.text()).path()).fileName()
self.statusLabel.setText("Downloaded %s to %s." % (fileName, QDir.currentPath()))
self.downloadButton.setEnabled(True)
self.reply.deleteLater()
self.reply = None
self.outFile = None