Formatted the client.py
This commit is contained in:
parent
d4f4342642
commit
496635848f
@ -1,4 +1,3 @@
|
||||
#coding:utf8
|
||||
import hashlib
|
||||
import os.path
|
||||
import time
|
||||
@ -9,7 +8,7 @@ from syncplay.protocols import SyncClientProtocol
|
||||
from syncplay import utils, constants
|
||||
from syncplay.messages import getMessage
|
||||
import threading
|
||||
from syncplay.constants import PRIVACY_SENDHASHED_MODE, PRIVACY_DONTSEND_MODE,\
|
||||
from syncplay.constants import PRIVACY_SENDHASHED_MODE, PRIVACY_DONTSEND_MODE, \
|
||||
PRIVACY_HIDDENFILENAME, FILENAME_STRIP_REGEX
|
||||
# <MAL DISABLE>
|
||||
libMal = None
|
||||
@ -19,8 +18,9 @@ except ImportError:
|
||||
libMal = None
|
||||
'''
|
||||
# </MAL DISABLE>
|
||||
|
||||
class SyncClientFactory(ClientFactory):
|
||||
def __init__(self, client, retry = constants.RECONNECT_RETRIES):
|
||||
def __init__(self, client, retry=constants.RECONNECT_RETRIES):
|
||||
self._client = client
|
||||
self.retry = retry
|
||||
self._timesTried = 0
|
||||
@ -42,7 +42,7 @@ class SyncClientFactory(ClientFactory):
|
||||
self._timesTried += 1
|
||||
self._client.ui.showMessage(getMessage("en", "reconnection-attempt-notification"))
|
||||
self.reconnecting = True
|
||||
reactor.callLater(0.1*(2**self._timesTried), connector.connect)
|
||||
reactor.callLater(0.1 * (2 ** self._timesTried), connector.connect)
|
||||
else:
|
||||
message = getMessage("en", "disconnection-notification")
|
||||
self._client.ui.showErrorMessage(message)
|
||||
@ -68,7 +68,7 @@ class SyncplayClient(object):
|
||||
self._player = None
|
||||
self.givenmalprivacywarning = False
|
||||
if(config['room'] == None or config['room'] == ''):
|
||||
config['room'] = config['name'] # ticket #58
|
||||
config['room'] = config['name'] # ticket #58
|
||||
self.defaultRoom = config['room']
|
||||
self.playerPositionBeforeLastSeek = 0.0
|
||||
self.setUsername(config['name'])
|
||||
@ -302,7 +302,7 @@ class SyncplayClient(object):
|
||||
return
|
||||
try:
|
||||
size = os.path.getsize(path)
|
||||
except OSError: #file not accessible (stream?)
|
||||
except OSError: # file not accessible (stream?)
|
||||
size = 0
|
||||
rawfilename = filename
|
||||
filename, size = self.__executePrivacySettings(filename, size)
|
||||
@ -382,7 +382,7 @@ class SyncplayClient(object):
|
||||
reactor.connectTCP(host, port, self.protocolFactory)
|
||||
reactor.run()
|
||||
|
||||
def stop(self, promptForAction = False):
|
||||
def stop(self, promptForAction=False):
|
||||
if not self._running:
|
||||
return
|
||||
self._running = False
|
||||
@ -434,7 +434,7 @@ class SyncplayClient(object):
|
||||
|
||||
def __displayMessageOnOSD(self, warningName):
|
||||
if (constants.OSD_WARNING_MESSAGE_DURATION > self._warnings[warningName]["displayedFor"]):
|
||||
self._ui.showOSDMessage(getMessage("en", warningName ), constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL)
|
||||
self._ui.showOSDMessage(getMessage("en", warningName), constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL)
|
||||
self._warnings[warningName]["displayedFor"] += constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL
|
||||
else:
|
||||
self._warnings[warningName]["displayedFor"] = 0
|
||||
@ -443,7 +443,7 @@ class SyncplayClient(object):
|
||||
|
||||
|
||||
class SyncplayUser(object):
|
||||
def __init__(self, username = None, room = None, file_ = None, position = 0):
|
||||
def __init__(self, username=None, room=None, file_=None, position=0):
|
||||
self.username = username
|
||||
self.room = room
|
||||
self.file = file_
|
||||
@ -509,7 +509,7 @@ class MalUpdater(object):
|
||||
if(len(results) > 0):
|
||||
result = results[0]
|
||||
message = "Updating MAL with: \"{}\", episode: {}".format(result.mainTitle, result.episodeBeingWatched)
|
||||
reactor.callFromThread(self._ui.showMessage,(message),)
|
||||
reactor.callFromThread(self._ui.showMessage, (message),)
|
||||
options = {"tags": ["syncplay"]}
|
||||
manager.updateEntryOnMal(result, options)
|
||||
self._filename = "" # Make sure no updates will be performed until switch
|
||||
@ -550,7 +550,7 @@ class SyncplayUserlist(object):
|
||||
message = getMessage("en", "file-differences-notification") + ", ".join(differences)
|
||||
self.ui.showMessage(message)
|
||||
|
||||
def addUser(self, username, room, file_, position = 0, noMessage = False):
|
||||
def addUser(self, username, room, file_, position=0, noMessage=False):
|
||||
if(username == self.currentUser.username):
|
||||
self.currentUser.lastPosition = position
|
||||
return
|
||||
@ -629,23 +629,26 @@ class SyncplayUserlist(object):
|
||||
def clearList(self):
|
||||
self._users = {}
|
||||
|
||||
def sortList(self):
|
||||
pass
|
||||
|
||||
class UiManager(object):
|
||||
def __init__(self, client, ui):
|
||||
self._client = client
|
||||
self.__ui = ui
|
||||
|
||||
def showMessage(self, message, noPlayer = False, noTimestamp = False):
|
||||
def showMessage(self, message, noPlayer=False, noTimestamp=False):
|
||||
if(not noPlayer): self.showOSDMessage(message)
|
||||
self.__ui.showMessage(message, noTimestamp)
|
||||
|
||||
def showUserList(self, currentUser, rooms):
|
||||
self.__ui.showUserList(currentUser, rooms)
|
||||
|
||||
def showOSDMessage(self, message, duration = constants.OSD_DURATION):
|
||||
def showOSDMessage(self, message, duration=constants.OSD_DURATION):
|
||||
if(self._client._player):
|
||||
self._client._player.displayMessage(message, duration * 1000)
|
||||
|
||||
def showErrorMessage(self, message, criticalerror = False):
|
||||
def showErrorMessage(self, message, criticalerror=False):
|
||||
self.__ui.showErrorMessage(message, criticalerror)
|
||||
|
||||
def promptFor(self, prompt):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user