Pyqt And Websocket Client. Listen Websocket In Background
I have a PyQt Gui application. This application have a main window that should be open after the start. This application should to listen the websocket. I tried solve it so: ...
Solution 1:
Thanks enginefree.
I make this
classWindow(QtGui.QDialog):
def__init__(self, parent=None):
super(Window, self).__init__()
self.thread = ListenWebsocket()
self.thread.start()
...
classListenWebsocket(QtCore.QThread):
def__init__(self, parent=None):
super(ListenWebsocket, self).__init__(parent)
websocket.enableTrace(True)
self.WS = websocket.WebSocketApp("ws://localhost:8080/chatsocket",
on_message = self.on_message,
on_error = self.on_error,
on_close = self.on_close)
defrun(self):
#ws.on_open = on_open
self.WS.run_forever()
defon_message(self, ws, message):
print message
defon_error(self, ws, error):
print error
defon_close(self, ws):
print"### closed ###"if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
QtGui.QApplication.setQuitOnLastWindowClosed(False)
window = Window()
window.show()
sys.exit(app.exec_())
Post a Comment for "Pyqt And Websocket Client. Listen Websocket In Background"