SF.net SVN: fclient: [42] trunk/fclient/fclient_widgets/peer_widget.py
Status: Pre-Alpha
Brought to you by:
jurner
From: <jU...@us...> - 2007-11-04 17:29:46
|
Revision: 42 http://fclient.svn.sourceforge.net/fclient/?rev=42&view=rev Author: jUrner Date: 2007-11-04 09:29:50 -0800 (Sun, 04 Nov 2007) Log Message: ----------- new: FcPClient manager Modified Paths: -------------- trunk/fclient/fclient_widgets/peer_widget.py Modified: trunk/fclient/fclient_widgets/peer_widget.py =================================================================== --- trunk/fclient/fclient_widgets/peer_widget.py 2007-11-04 17:29:34 UTC (rev 41) +++ trunk/fclient/fclient_widgets/peer_widget.py 2007-11-04 17:29:50 UTC (rev 42) @@ -1,8 +1,4 @@ """Sketch for a widget handling peer nodes - -Note: super slow currently. Have to experiment with multiple clients -to enable playing around with poll timeouts for individual clients - """ import os, sys @@ -54,6 +50,8 @@ #*************************************************************************************************** # #*************************************************************************************************** +#TODO: user should not be alowed to show / hide peers while we are listing them + class PeerWidget(QtGui.QTreeWidget): """ """ @@ -76,6 +74,7 @@ self._fcpEvents = None self._isCreated = False self._peers = {} # identity --> item + self._requestsPending = 0 self._showPeersFlags = self.ShowPeersAll QtGui.QWidget.__init__(self, parent) @@ -113,7 +112,7 @@ """ if not self._isCreated: self._isCreated = True - self._cfg.connectFcpNode(self.handleClientConnected) + self._fcpClient = self._cfg.fcpClientManager.newFcpClient('MeName', self.handleClientConnected) ############################################################# ## @@ -137,18 +136,17 @@ """ """ self._fcpEvents = ( - (self._cfg.fcpClient.events.ClientDisconnected, self.handleClientDisconnected), + (self._fcpClient.events.ClientDisconnected, self.handleClientDisconnected), - (self._cfg.fcpClient.events.Peer, self.handlePeer), - (self._cfg.fcpClient.events.EndListPeers, self.handleEndListPeers), - (self._cfg.fcpClient.events.PeerRemoved, self.handlePeerRemoved), - (self._cfg.fcpClient.events.UnknownNodeIdentifier, self.handleUnknownNodeIdentifier), + (self._fcpClient.events.Peer, self.handlePeer), + (self._fcpClient.events.EndListPeers, self.handleEndListPeers), + (self._fcpClient.events.PeerRemoved, self.handlePeerRemoved), + (self._fcpClient.events.UnknownNodeIdentifier, self.handleUnknownNodeIdentifier), - (self._cfg.fcpClient.events.PeerNote, self.handlePeerNote), - (self._cfg.fcpClient.events.EndListPeerNotes, self.handleEndListPeerNotes), + (self._fcpClient.events.PeerNote, self.handlePeerNote), + (self._fcpClient.events.EndListPeerNotes, self.handleEndListPeerNotes), ) - # take care to not connect twice for event, observer in self._fcpEvents: if not observer in event: @@ -156,8 +154,13 @@ self.clear() self._peers = {} - self._cfg.fcpClient.listPeers() + self._cfg.fcpClientManager.setPriority( + self._fcpClient.connectionName(), + pollPriority=self._cfg.fcpClientManager.priorities['Highest'] + ) + self._fcpClient.listPeers() + def handleClientDisconnected(self, event, params): """ @@ -189,14 +192,20 @@ item.setPeerData(params) # get peer notes if possible - if params['opennet'] == self._cfg.fcpClient.FcpFalse: - self._cfg.fcpClient.listPeerNotes(identity) - - + if params['opennet'] == self._fcpClient.FcpFalse: + self._requestsPending += 1 + self._fcpClient.listPeerNotes(identity) + def handleEndListPeers(self, event, params): """ """ + if self._requestsPending <= 0: + self._cfg.fcpClientManager.setPriority( + self._fcpClient.connectionName(), + pollPriority=self._cfg.fcpClientManager.priorities['Lowest'] + ) + def handlePeerRemoved(self, peer): @@ -218,15 +227,22 @@ #TODO: shouldn' t happen return - if params['PeerNoteType'] == self._cfg.fcpClient.PeerNoteType.Private: + if params['PeerNoteType'] == self._fcpClient.PeerNoteType.Private: item.setText(self.HeaderIndexNotes, params['NoteText']) def handleEndListPeerNotes(self, event, params): """ """ + self._requestsPending -= 1 + if self._requestsPending <= 0: + self._requestsPending = 0 + self._cfg.fcpClientManager.setPriority( + self._fcpClient.connectionName(), + pollPriority=self._cfg.fcpClientManager.priorities['Lowest'] + ) + - ####################################################### ## ## methods @@ -240,6 +256,8 @@ for event, observer in self._fcpEvents: if not observer in event: event -= observer + + self._cfg.fcpClientHandler.closeClient(self._fcpClient.connectionName()) def formatTimeDelta(self, t): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |