Cooperation/CooperationClient.py

changeset 6115
ac3a98f3ebc2
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
--- a/Cooperation/CooperationClient.py	Sun Feb 04 10:56:30 2018 +0100
+++ b/Cooperation/CooperationClient.py	Mon Feb 05 19:15:47 2018 +0100
@@ -191,9 +191,12 @@
         connection.setGreetingMessage(self.__username,
                                       self.__servers[0].serverPort())
         
-        connection.error.connect(self.__connectionError)
-        connection.disconnected.connect(self.__disconnected)
-        connection.readyForUse.connect(self.__readyForUse)
+        connection.error.connect(
+            lambda err: self.__connectionError(err, connection))
+        connection.disconnected.connect(
+            lambda: self.__disconnected(connection))
+        connection.readyForUse.connect(
+            lambda: self.__readyForUse(connection))
         connection.rejected.connect(self.__connectionRejected)
     
     def __connectionRejected(self, msg):
@@ -204,14 +207,15 @@
         """
         self.connectionError.emit(msg)
     
-    def __connectionError(self, socketError):
+    def __connectionError(self, socketError, connection):
         """
         Private slot to handle a connection error.
         
         @param socketError reference to the error object
-            (QAbstractSocket.SocketError)
+        @type QAbstractSocket.SocketError
+        @param connection connection that caused the error
+        @type Connection
         """
-        connection = self.sender()
         if socketError != QAbstractSocket.RemoteHostClosedError:
             if connection.peerPort() != 0:
                 msg = "* {0}:{1}\n{2}\n".format(
@@ -226,23 +230,28 @@
             self.cannotConnect.emit()
         self.removeConnection(connection)
     
-    def __disconnected(self):
+    def __disconnected(self, connection):
         """
         Private slot to handle the disconnection of a chat client.
+        
+        @param connection connection that was disconnected
+        @type Connection
         """
-        connection = self.sender()
         self.removeConnection(connection)
     
-    def __readyForUse(self):
+    def __readyForUse(self, connection):
         """
         Private slot to handle a connection getting ready for use.
+        
+        @param connection connection that got ready for use
+        @type Connection
         """
-        connection = self.sender()
         if self.hasConnection(connection.peerAddress(), connection.peerPort()):
             return
         
         connection.newMessage.connect(self.newMessage)
-        connection.getParticipants.connect(self.__getParticipants)
+        connection.getParticipants.connect(
+            lambda: self.__getParticipants(connection))
         connection.editorCommand.connect(self.editorCommand)
         
         self.__peers[connection.peerAddress()].append(connection)
@@ -267,11 +276,14 @@
             self.__processParticipants)
         self.__initialConnection.connectToHost(host, port)
     
-    def __getParticipants(self):
+    def __getParticipants(self, reqConnection):
         """
         Private slot to handle the request for a list of participants.
+        
+        @param reqConnection reference to the connection to get
+            participants for
+        @type Connection
         """
-        reqConnection = self.sender()
         participants = []
         for connectionList in self.__peers.values():
             for connection in connectionList:

eric ide

mercurial