aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-05-19 13:46:56 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-05-19 14:12:36 +0200
commitaf83219d8a6e7ac1c0c8776f61b99ee37f30ef04 (patch)
tree51fa216a02cefef75aef77313a048bf879c91a32 /examples
parent8cd50636102be2e1178c8c602a3e374891398e3e (diff)
Polish the QtWebChannel example
- Rename according to snake case conventions - Connect sending to QLineEdit.returnPressed Task-number: PYSIDE-1112 Change-Id: Ia0e1b81309985219688739a4cead8a252acd8dcc Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/webchannel/standalone/core.py6
-rw-r--r--examples/webchannel/standalone/dialog.py11
-rw-r--r--examples/webchannel/standalone/main.py17
-rw-r--r--examples/webchannel/standalone/websocketclientwrapper.py10
-rw-r--r--examples/webchannel/standalone/websockettransport.py6
5 files changed, 26 insertions, 24 deletions
diff --git a/examples/webchannel/standalone/core.py b/examples/webchannel/standalone/core.py
index ff62bdde1..d9b4bd20b 100644
--- a/examples/webchannel/standalone/core.py
+++ b/examples/webchannel/standalone/core.py
@@ -1,7 +1,7 @@
#############################################################################
##
## Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-## Copyright (C) 2020 The Qt Company Ltd.
+## Copyright (C) 2021 The Qt Company Ltd.
## Contact: http://www.qt.io/licensing/
##
## This file is part of the Qt for Python examples of the Qt Toolkit.
@@ -51,7 +51,7 @@ class Core(QObject):
def __init__(self, dialog, parent=None):
super().__init__(parent)
self._dialog = dialog
- self._dialog.sendText.connect(self._emit_send_text)
+ self._dialog.send_text.connect(self._emit_send_text)
@Slot(str)
def _emit_send_text(self, text):
@@ -59,4 +59,4 @@ class Core(QObject):
@Slot(str)
def receiveText(self, text):
- self._dialog.displayMessage(f"Received message: {text}")
+ self._dialog.display_message(f"Received message: {text}")
diff --git a/examples/webchannel/standalone/dialog.py b/examples/webchannel/standalone/dialog.py
index 886a323f8..6f7cc842e 100644
--- a/examples/webchannel/standalone/dialog.py
+++ b/examples/webchannel/standalone/dialog.py
@@ -1,7 +1,7 @@
#############################################################################
##
## Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-## Copyright (C) 2020 The Qt Company Ltd.
+## Copyright (C) 2021 The Qt Company Ltd.
## Contact: http://www.qt.io/licensing/
##
## This file is part of the Qt for Python examples of the Qt Toolkit.
@@ -46,16 +46,17 @@ from ui_dialog import Ui_Dialog
class Dialog(QDialog):
- sendText = Signal(str)
+ send_text = Signal(str)
def __init__(self, parent=None):
super().__init__(parent)
self._ui = Ui_Dialog()
self._ui.setupUi(self)
self._ui.send.clicked.connect(self.clicked)
+ self._ui.input.returnPressed.connect(self._ui.send.animateClick)
@Slot(str)
- def displayMessage(self, message):
+ def display_message(self, message):
self._ui.output.appendPlainText(message)
@Slot()
@@ -63,6 +64,6 @@ class Dialog(QDialog):
text = self._ui.input.text()
if not text:
return
- self.sendText.emit(text)
- self.displayMessage(f"Sent message: {text}")
+ self.send_text.emit(text)
+ self.display_message(f"Sent message: {text}")
self._ui.input.clear()
diff --git a/examples/webchannel/standalone/main.py b/examples/webchannel/standalone/main.py
index 68f199336..cd55a3814 100644
--- a/examples/webchannel/standalone/main.py
+++ b/examples/webchannel/standalone/main.py
@@ -1,7 +1,7 @@
#############################################################################
##
## Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-## Copyright (C) 2020 The Qt Company Ltd.
+## Copyright (C) 2021 The Qt Company Ltd.
## Contact: http://www.qt.io/licensing/
##
## This file is part of the Qt for Python examples of the Qt Toolkit.
@@ -61,10 +61,10 @@ if __name__ == '__main__':
print('The example requires SSL support.')
sys.exit(-1)
cur_dir = os.path.dirname(os.path.abspath(__file__))
- jsFileInfo = QFileInfo(f"{cur_dir}/qwebchannel.js")
- if not jsFileInfo.exists():
+ js_file_info = QFileInfo(f"{cur_dir}/qwebchannel.js")
+ if not js_file_info.exists():
QFile.copy(":/qtwebchannel/qwebchannel.js",
- jsFileInfo.absoluteFilePath())
+ js_file_info.absoluteFilePath())
# setup the QWebSocketServer
server = QWebSocketServer("QWebChannel Standalone Example Server",
@@ -74,11 +74,11 @@ if __name__ == '__main__':
sys.exit(-1)
# wrap WebSocket clients in QWebChannelAbstractTransport objects
- clientWrapper = WebSocketClientWrapper(server)
+ client_wrapper = WebSocketClientWrapper(server)
# setup the channel
channel = QWebChannel()
- clientWrapper.clientConnected.connect(channel.connectTo)
+ client_wrapper.client_connected.connect(channel.connectTo)
# setup the UI
dialog = Dialog()
@@ -91,8 +91,9 @@ if __name__ == '__main__':
url = QUrl.fromLocalFile(f"{cur_dir}/index.html")
QDesktopServices.openUrl(url)
- message = f"Initialization complete, opening browser at {url.toDisplayString()}."
- dialog.displayMessage(message)
+ display_url = url.toDisplayString()
+ message = f"Initialization complete, opening browser at {display_url}."
+ dialog.display_message(message)
dialog.show()
sys.exit(app.exec())
diff --git a/examples/webchannel/standalone/websocketclientwrapper.py b/examples/webchannel/standalone/websocketclientwrapper.py
index 96aa79a08..f8a196b49 100644
--- a/examples/webchannel/standalone/websocketclientwrapper.py
+++ b/examples/webchannel/standalone/websocketclientwrapper.py
@@ -1,7 +1,7 @@
#############################################################################
##
## Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-## Copyright (C) 2020 The Qt Company Ltd.
+## Copyright (C) 2021 The Qt Company Ltd.
## Contact: http://www.qt.io/licensing/
##
## This file is part of the Qt for Python examples of the Qt Toolkit.
@@ -51,7 +51,7 @@ class WebSocketClientWrapper(QObject):
the WebChannel. Any kind of remote JavaScript client that supports
WebSockets can thus receive messages and access the published objects.
"""
- clientConnected = Signal(WebSocketTransport)
+ client_connected = Signal(WebSocketTransport)
def __init__(self, server, parent=None):
"""Construct the client wrapper with the given parent. All clients
@@ -59,14 +59,14 @@ class WebSocketClientWrapper(QObject):
in WebSocketTransport objects."""
super().__init__(parent)
self._server = server
- self._server.newConnection.connect(self.handleNewConnection)
+ self._server.newConnection.connect(self.handle_new_connection)
self._transports = []
@Slot()
- def handleNewConnection(self):
+ def handle_new_connection(self):
"""Wrap an incoming WebSocket connection in a WebSocketTransport
object."""
socket = self._server.nextPendingConnection()
transport = WebSocketTransport(socket)
self._transports.append(transport)
- self.clientConnected.emit(transport)
+ self.client_connected.emit(transport)
diff --git a/examples/webchannel/standalone/websockettransport.py b/examples/webchannel/standalone/websockettransport.py
index 570c7e518..e006ba1ca 100644
--- a/examples/webchannel/standalone/websockettransport.py
+++ b/examples/webchannel/standalone/websockettransport.py
@@ -1,7 +1,7 @@
#############################################################################
##
## Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-## Copyright (C) 2020 The Qt Company Ltd.
+## Copyright (C) 2021 The Qt Company Ltd.
## Contact: http://www.qt.io/licensing/
##
## This file is part of the Qt for Python examples of the Qt Toolkit.
@@ -56,7 +56,7 @@ class WebSocketTransport(QWebChannelAbstractTransport):
The socket is also set as the parent of the transport object."""
super().__init__(socket)
self._socket = socket
- self._socket.textMessageReceived.connect(self.textMessageReceived)
+ self._socket.textMessageReceived.connect(self.text_message_received)
self._socket.disconnected.connect(self._disconnected)
def __del__(self):
@@ -74,7 +74,7 @@ class WebSocketTransport(QWebChannelAbstractTransport):
self._socket.sendTextMessage(json_message)
@Slot(str)
- def textMessageReceived(self, message_data_in):
+ def text_message_received(self, message_data_in):
"""Deserialize the stringified JSON messageData and emit
messageReceived."""
message_data = QByteArray(bytes(message_data_in, encoding='utf8'))