diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-03-22 15:41:48 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-03-22 19:41:03 +0000 |
commit | 570cc14c50782ed46393a0a6a8d9d491fbb3785a (patch) | |
tree | 9b123ff862fb83b2c70db4791792919ecc59bd47 /examples/network | |
parent | 80aec29aca246f1f67a4f8c453b49f1eadfee6fd (diff) |
Replace % formatting in examples by f-strings
As drive-by, Fix fortune server, addressbook and dombookmarks examples to work.
Task-number: PYSIDE-1112
Change-Id: I8ef7759ed56aeb7157cf2222bee9b6481973112a
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'examples/network')
4 files changed, 14 insertions, 10 deletions
diff --git a/examples/network/blockingfortuneclient/blockingfortuneclient.py b/examples/network/blockingfortuneclient/blockingfortuneclient.py index 4ee0ce622..536110d4e 100644 --- a/examples/network/blockingfortuneclient/blockingfortuneclient.py +++ b/examples/network/blockingfortuneclient/blockingfortuneclient.py @@ -205,7 +205,7 @@ class BlockingClient(QWidget): "and port settings are correct.") else: QMessageBox.information(self, "Blocking Fortune Client", - "The following error occurred: %s." % message) + f"The following error occurred: {message}.") self.getFortuneButton.setEnabled(True) diff --git a/examples/network/fortuneclient/fortuneclient.py b/examples/network/fortuneclient/fortuneclient.py index 99ca41b0e..2e6d6d559 100644 --- a/examples/network/fortuneclient/fortuneclient.py +++ b/examples/network/fortuneclient/fortuneclient.py @@ -118,7 +118,6 @@ class Client(QtWidgets.QDialog): return nextFortune = instr.readString() - nextFortune = str(nextFortune, encoding='ascii') if nextFortune == self.currentFortune: QtCore.QTimer.singleShot(0, self.requestNewFortune) @@ -141,8 +140,9 @@ class Client(QtWidgets.QDialog): "fortune server is running, and check that the host name " "and port settings are correct.") else: + reason = self.tcpSocket.errorString() QtWidgets.QMessageBox.information(self, "Fortune Client", - "The following error occurred: %s." % self.tcpSocket.errorString()) + f"The following error occurred: {reason}.") self.getFortuneButton.setEnabled(True) diff --git a/examples/network/fortuneserver/fortuneserver.py b/examples/network/fortuneserver/fortuneserver.py index 7b8f05a32..e3087f1c1 100644 --- a/examples/network/fortuneserver/fortuneserver.py +++ b/examples/network/fortuneserver/fortuneserver.py @@ -52,18 +52,20 @@ class Server(QtWidgets.QDialog): super(Server, self).__init__(parent) statusLabel = QtWidgets.QLabel() + statusLabel.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction) quitButton = QtWidgets.QPushButton("Quit") quitButton.setAutoDefault(False) self.tcpServer = QtNetwork.QTcpServer(self) if not self.tcpServer.listen(): + reason = self.tcpServer.errorString() QtWidgets.QMessageBox.critical(self, "Fortune Server", - "Unable to start the server: %s." % self.tcpServer.errorString()) + f"Unable to start the server: {reason}.") self.close() return - - statusLabel.setText("The server is running on port %d.\nRun the " - "Fortune Client example now." % self.tcpServer.serverPort()) + port = self.tcpServer.serverPort() + statusLabel.setText(f"The server is running on port {port}.\nRun the " + "Fortune Client example now.") self.fortunes = ( "You've been leading a dog's life. Stay off the furniture.", diff --git a/examples/network/threadedfortuneserver/threadedfortuneserver.py b/examples/network/threadedfortuneserver/threadedfortuneserver.py index 839a2a57e..deb993b71 100644 --- a/examples/network/threadedfortuneserver/threadedfortuneserver.py +++ b/examples/network/threadedfortuneserver/threadedfortuneserver.py @@ -111,8 +111,9 @@ class Dialog(QDialog): quitButton.setAutoDefault(False) if not self.server.listen(): + reason = self.server.errorString() QMessageBox.critical(self, "Threaded Fortune Server", - "Unable to start the server: %s." % self.server.errorString()) + f"Unable to start the server: {reason}.") self.close() return @@ -123,9 +124,10 @@ class Dialog(QDialog): ipAddress = QHostAddress(QHostAddress.LocalHost) ipAddress = ipAddress.toString() + port = self.server.serverPort() - statusLabel.setText("The server is running on\n\nIP: %s\nport: %d\n\n" - "Run the Fortune Client example now." % (ipAddress, self.server.serverPort())) + statusLabel.setText(f"The server is running on\n\nIP: {ipAddress}\nport: {port}\n\n" + "Run the Fortune Client example now.") quitButton.clicked.connect(self.close) |