Undo change to client.py

This commit is contained in:
Et0h 2012-12-29 15:10:30 +00:00
parent 61ce659960
commit a2116b0235
1 changed files with 515 additions and 510 deletions

View File

@ -6,7 +6,6 @@ from twisted.internet.protocol import ClientFactory
from twisted.internet import reactor, task
from syncplay.protocols import SyncClientProtocol
from syncplay import utils, constants
from syncplay.messages import getMessage
class SyncClientFactory(ClientFactory):
def __init__(self, client, retry = constants.RECONNECT_RETRIES):
@ -20,22 +19,23 @@ class SyncClientFactory(ClientFactory):
def startedConnecting(self, connector):
destination = connector.getDestination()
message = getMessage("en", "connection-attempt-notification").format(destination.host, destination.port)
self._client.ui.showMessage(message)
self._client.ui.showMessage('Attempting to connect to {}:{}'.format(destination.host, destination.port))
def clientConnectionLost(self, connector, reason):
if self._timesTried < self.retry:
self._timesTried += 1
self._client.ui.showMessage(getMessage("en", "reconnection-attempt-notification"))
message = 'Connection with server lost, attempting to reconnect'
self._client.ui.showMessage(message)
self.reconnecting = True
reactor.callLater(0.1*(2**self._timesTried), connector.connect)
else:
message = getMessage("en", "disconnection-notification")
message = 'Disconnected from server'
self._client.ui.showMessage(message)
def clientConnectionFailed(self, connector, reason):
if not self.reconnecting:
self._client.ui.showMessage(getMessage("en", "connection-failed-notification"))
message = 'Connection with server failed'
self._client.ui.showMessage(message)
self._client.stop(True)
else:
self.clientConnectionLost(connector, reason)
@ -108,7 +108,7 @@ class SyncplayClient(object):
def checkIfConnected(self):
if(self._lastGlobalUpdate and self._protocol and time.time() - self._lastGlobalUpdate > constants.PROTOCOL_TIMEOUT):
self._lastGlobalUpdate = None
self.ui.showErrorMessage(getMessage("en", "server-timeout-error"))
self.ui.showErrorMessage("Connection with server timed out")
self._protocol.drop()
return False
return True
@ -149,14 +149,16 @@ class SyncplayClient(object):
def _rewindPlayerDueToTimeDifference(self, position, setBy):
self.setPosition(position)
self.ui.showMessage(getMessage("en", "rewind-notification").format(setBy))
message = "Rewinded due to time difference with <{}>".format(setBy)
self.ui.showMessage(message)
madeChangeOnPlayer = True
return madeChangeOnPlayer
def _serverUnpaused(self, setBy):
self._player.setPaused(False)
madeChangeOnPlayer = True
self.ui.showMessage(getMessage("en", "unpause-notification").format(setBy))
message = '<{}> unpaused'.format(setBy)
self.ui.showMessage(message)
return madeChangeOnPlayer
def _serverPaused(self, setBy, diff):
@ -164,7 +166,8 @@ class SyncplayClient(object):
self.setPosition(self.getGlobalPosition())
self._player.setPaused(True)
madeChangeOnPlayer = True
self.ui.showMessage(getMessage("en", "pause-notification").format(setBy))
message = '<{}> paused'.format(setBy)
self.ui.showMessage(message)
return madeChangeOnPlayer
def _serverSeeked(self, position, setBy):
@ -174,7 +177,7 @@ class SyncplayClient(object):
madeChangeOnPlayer = True
else:
madeChangeOnPlayer = False
message = getMessage("en", "seek-notification").format(setBy, utils.formatTime(self.playerPositionBeforeLastSeek), utils.formatTime(position))
message = '<{}> jumped from {} to {}'.format(setBy, utils.formatTime(self.playerPositionBeforeLastSeek), utils.formatTime(position))
self.ui.showMessage(message)
return madeChangeOnPlayer
@ -182,11 +185,13 @@ class SyncplayClient(object):
if(constants.SLOWDOWN_KICKIN_BOUNDARY < diff and not self._speedChanged):
self._player.setSpeed(constants.SLOWDOWN_RATE)
self._speedChanged = True
self.ui.showMessage(getMessage("en", "slowdown-notification").format(setBy))
message = "Slowing down due to time difference with <{}>".format(setBy)
self.ui.showMessage(message)
elif(self._speedChanged and diff < constants.SLOWDOWN_RESET_BOUNDARY):
self._player.setSpeed(1.00)
self._speedChanged = False
self.ui.showMessage(getMessage("en", "revert-notification"))
message = "Reverting speed back to normal"
self.ui.showMessage(message)
madeChangeOnPlayer = True
return madeChangeOnPlayer
@ -229,7 +234,7 @@ class SyncplayClient(object):
def setUserOffset(self, time):
self._userOffset = time
message =getMessage("en", "current-offset-notification").format(self._userOffset)
message = "Current offset: {} seconds".format(self._userOffset)
self.setPosition(self.getGlobalPosition())
self.ui.showMessage(message)
@ -336,7 +341,7 @@ class SyncplayClient(object):
self._player.drop()
reactor.callLater(0.1, reactor.stop)
if(promptForAction):
self.ui.promptFor(getMessage("en", "enter-to-exit-prompt"))
self.ui.promptFor("Press enter to exit\n")
class SyncplayUser(object):
def __init__(self, username = None, room = None, file_ = None, position = 0):
@ -373,16 +378,16 @@ class SyncplayUserlist(object):
def __showUserChangeMessage(self, username, room, file_):
if (room and not file_):
message = getMessage("en", "room-join-notification").format(username, room)
message = "<{}> has joined the room: '{}'".format(username, room)
self.ui.showMessage(message)
elif (room and file_ and username != self.currentUser.username):
duration = utils.formatTime(file_['duration'])
message = getMessage("en", "playing-notification").format(username, file_['name'], duration)
message = "<{}> is playing '{}' ({})".format(username, file_['name'], duration)
if(self.currentUser.room <> room or self.currentUser.username == username):
message += getMessage("en", "playing-notification/room-addendum").format(room)
message += " in room: '{}'".format(room)
self.ui.showMessage(message)
if(self.currentUser.file and not self.currentUser.isFileSame(file_) and self.currentUser.room == room):
message = getMessage("en", "file-different-notification").format(username)
message = "File you are playing appears to be different from <{}>'s".format(username)
self.ui.showMessage(message)
differences = []
if(self.currentUser.file['name'] <> file_['name']):
@ -391,7 +396,7 @@ class SyncplayUserlist(object):
differences.append("size")
if(self.currentUser.file['duration'] <> file_['duration']):
differences.append("duration")
message = getMessage("en", "file-differences-notification")+ ", ".join(differences)
message = "Your file differs in the following way(s): " + ", ".join(differences)
self.ui.showMessage(message)
def addUser(self, username, room, file_, position = 0, noMessage = False):
@ -406,7 +411,7 @@ class SyncplayUserlist(object):
def removeUser(self, username):
if(self._users.has_key(username)):
self._users.pop(username)
message = getMessage("en", "left-notification").format(username)
message = "<{}> has left".format(username)
self.ui.showMessage(message)
def __displayModUserMessage(self, username, room, file_, user):
@ -458,12 +463,12 @@ class SyncplayUserlist(object):
if(self.currentUser.file):
fileHasSameSizeAsYour = user.file['size'] == self.currentUser.file['size']
fileHasSameNameYour = user.file['name'] == self.currentUser.file['name']
differentFileMessage = getMessage("en", "different-filesize-notification")
differentFileMessage = " (their file size is different from yours!)"
message += differentFileMessage if not fileHasSameSizeAsYour and fileHasSameNameYour else ""
return message
def __displayFileWatchersInRoomList(self, key, users):
self.ui.showMessage(getMessage("en", "file-played-by-notification").format(key), True, True)
self.ui.showMessage("File: {} is being played by:".format(key), True, True)
for user in sorted(users.itervalues()):
message = "<"+user.username+">"
if(self.currentUser.username == user.username):
@ -473,7 +478,7 @@ class SyncplayUserlist(object):
def __displayPeopleInRoomWithNoFile(self, noFileList):
if (noFileList):
self.ui.showMessage(getMessage("en", "notplaying-notification"), True, True)
self.ui.showMessage("People who are not playing any file:", True, True)
for user in sorted(noFileList.itervalues()):
self.ui.showMessage("\t<" + user.username + ">", True, True)