Fixed code formatting

This commit is contained in:
Uriziel 2012-10-15 20:33:24 +02:00
parent d39bde520f
commit 0a0f249b07
9 changed files with 61 additions and 61 deletions

View File

@ -7,19 +7,19 @@ from setuptools import find_packages
import syncplay import syncplay
common_info = dict( common_info = dict(
name = 'Syncplay', name='Syncplay',
version = syncplay.version, version=syncplay.version,
author = 'Tomasz Kowalczyk, Uriziel', author='Tomasz Kowalczyk, Uriziel',
author_email = 'code@fluxid.pl, urizieli@gmail.com', author_email='code@fluxid.pl, urizieli@gmail.com',
description = 'Syncplay', description='Syncplay',
packages = find_packages(exclude=['venv']), packages=find_packages(exclude=['venv']),
install_requires = ['Twisted>=11.1'], install_requires=['Twisted>=11.1'],
) )
info = dict( info = dict(
common_info, common_info,
console = [{"script":"syncplayClient.py","icon_resources":[(1,"resources\\icon.ico")]}, 'syncplayServer.py'], console=[{"script":"syncplayClient.py", "icon_resources":[(1, "resources\\icon.ico")]}, 'syncplayServer.py'],
options = {'py2exe': { options={'py2exe': {
'includes': 'cairo, pango, pangocairo, atk, gobject', 'includes': 'cairo, pango, pangocairo, atk, gobject',
'optimize': 2, 'optimize': 2,
'compressed': 1 'compressed': 1

View File

@ -15,7 +15,7 @@ except ImportError:
class SyncplayClientManager(object): class SyncplayClientManager(object):
def __init__(self): def __init__(self):
self._prepareArguments() self._prepareArguments()
self.interface = ui.getUi(graphical = not self.args.no_gui) self.interface = ui.getUi(graphical=not self.args.no_gui)
self._checkAndSaveConfiguration() self._checkAndSaveConfiguration()
syncplayClient = None syncplayClient = None
if(self.argsGetter.playerType == "mpc"): if(self.argsGetter.playerType == "mpc"):
@ -49,11 +49,11 @@ class SyncplayClientManager(object):
def _promptForMissingArguments(self): def _promptForMissingArguments(self):
if(self.args.no_gui): if(self.args.no_gui):
if (self.args.host == None): if (self.args.host == None):
self.args.host = self.interface.promptFor(prompt = "Hostname: ", message = "You must supply hostname on the first run, it's easier through command line arguments.") self.args.host = self.interface.promptFor(prompt="Hostname: ", message="You must supply hostname on the first run, it's easier through command line arguments.")
if (self.args.name == None): if (self.args.name == None):
self.args.name = self.interface.promptFor(prompt = "Username: ", message = "You must supply username on the first run, it's easier through command line arguments.") self.args.name = self.interface.promptFor(prompt="Username: ", message="You must supply username on the first run, it's easier through command line arguments.")
if (self.args.player_path == None): if (self.args.player_path == None):
self.args.player_path = self.interface.promptFor(prompt = "Player executable: ", message = "You must supply path to your player on the first run, it's easier through command line arguments.") self.args.player_path = self.interface.promptFor(prompt="Player executable: ", message="You must supply path to your player on the first run, it's easier through command line arguments.")
else: else:
self._guiPromptForMissingArguments() self._guiPromptForMissingArguments()

View File

@ -122,9 +122,9 @@ class MPCHCAPIPlayer(BasePlayer):
self.__client.updatePlayerStatus(self.__client.getGlobalPaused(), self.__client.getGlobalPosition()) self.__client.updatePlayerStatus(self.__client.getGlobalPaused(), self.__client.getGlobalPosition())
def __forcePause(self, paused): def __forcePause(self, paused):
i = 0 i = 0
while(paused <> self._mpcApi.isPaused() and i < 15): while(paused <> self._mpcApi.isPaused() and i < 15):
i+=1 i += 1
self.setPaused(paused) self.setPaused(paused)
time.sleep(0.1) time.sleep(0.1)
time.sleep(0.1) time.sleep(0.1)
@ -161,7 +161,7 @@ class MpcHcApi:
self.version = None self.version = None
self.__playpause_warden = False self.__playpause_warden = False
self.__locks = self.__Locks() self.__locks = self.__Locks()
self.__mpcExistenceChecking = threading.Thread(target = self.__mpcReadyInSlaveMode, name ="Check MPC window") self.__mpcExistenceChecking = threading.Thread(target=self.__mpcReadyInSlaveMode, name="Check MPC window")
self.__mpcExistenceChecking.setDaemon(True) self.__mpcExistenceChecking.setDaemon(True)
self.__listener = self.__Listener(self, self.__locks) self.__listener = self.__Listener(self, self.__locks)
self.__listener.setDaemon(True) self.__listener.setDaemon(True)
@ -176,7 +176,7 @@ class MpcHcApi:
return f(self, *args, **kwds) return f(self, *args, **kwds)
return wrapper return wrapper
def startMpc(self, path, args = ()): def startMpc(self, path, args=()):
args = "%s /slave %s" % (" ".join(args), str(self.__listener.hwnd)) args = "%s /slave %s" % (" ".join(args), str(self.__listener.hwnd))
win32api.ShellExecute(0, "open", path, args, None, 1) win32api.ShellExecute(0, "open", path, args, None, 1)
if(not self.__locks.mpcStart.wait(10)): if(not self.__locks.mpcStart.wait(10)):
@ -208,12 +208,12 @@ class MpcHcApi:
def seek(self, position): def seek(self, position):
self.__listener.SendCommand(self.CMD_SETPOSITION, unicode(position)) self.__listener.SendCommand(self.CMD_SETPOSITION, unicode(position))
def sendOsd(self, message, MsgPos = 2, DurationMs = 3000): def sendOsd(self, message, MsgPos=2, DurationMs=3000):
class __OSDDATASTRUCT(ctypes.Structure): class __OSDDATASTRUCT(ctypes.Structure):
_fields_ = [ _fields_ = [
('nMsgPos', ctypes.c_int32), ('nMsgPos', ctypes.c_int32),
('nDurationMS', ctypes.c_int32), ('nDurationMS', ctypes.c_int32),
('strMsg', ctypes.c_wchar * (len(message)+1)) ('strMsg', ctypes.c_wchar * (len(message) + 1))
] ]
cmessage = __OSDDATASTRUCT() cmessage = __OSDDATASTRUCT()
cmessage.nMsgPos = MsgPos cmessage.nMsgPos = MsgPos
@ -224,7 +224,7 @@ class MpcHcApi:
def sendRawCommand(self, cmd, value): def sendRawCommand(self, cmd, value):
self.__listener.SendCommand(cmd, value) self.__listener.SendCommand(cmd, value)
def handleCommand(self,cmd, value): def handleCommand(self, cmd, value):
if (cmd == self.CMD_CONNECT): if (cmd == self.CMD_CONNECT):
self.__listener.mpcHandle = int(value) self.__listener.mpcHandle = int(value)
self.__locks.mpcStart.set() self.__locks.mpcStart.set()
@ -245,39 +245,39 @@ class MpcHcApi:
elif(cmd == self.CMD_PLAYMODE): elif(cmd == self.CMD_PLAYMODE):
self.playState = int(value) self.playState = int(value)
if(self.callbacks.onUpdatePlaystate): if(self.callbacks.onUpdatePlaystate):
thread.start_new_thread(self.callbacks.onUpdatePlaystate,(self.playState,)) thread.start_new_thread(self.callbacks.onUpdatePlaystate, (self.playState,))
elif(cmd == self.CMD_NOWPLAYING): elif(cmd == self.CMD_NOWPLAYING):
value = value.split('|') value = value.split('|')
self.filePath = value[3] self.filePath = value[3]
self.filePlaying = value[3].split('\\').pop() self.filePlaying = value[3].split('\\').pop()
self.fileDuration = float(value[4]) self.fileDuration = float(value[4])
if(self.callbacks.onUpdatePath): if(self.callbacks.onUpdatePath):
thread.start_new_thread(self.callbacks.onUpdatePath,(self.onUpdatePath,)) thread.start_new_thread(self.callbacks.onUpdatePath, (self.onUpdatePath,))
if(self.callbacks.onUpdateFilename): if(self.callbacks.onUpdateFilename):
thread.start_new_thread(self.callbacks.onUpdateFilename,(self.filePlaying,)) thread.start_new_thread(self.callbacks.onUpdateFilename, (self.filePlaying,))
if(self.callbacks.onUpdateFileDuration): if(self.callbacks.onUpdateFileDuration):
thread.start_new_thread(self.callbacks.onUpdateFileDuration,(self.fileDuration,)) thread.start_new_thread(self.callbacks.onUpdateFileDuration, (self.fileDuration,))
elif(cmd == self.CMD_CURRENTPOSITION): elif(cmd == self.CMD_CURRENTPOSITION):
self.lastFilePosition = float(value) self.lastFilePosition = float(value)
if(self.callbacks.onGetCurrentPosition): if(self.callbacks.onGetCurrentPosition):
thread.start_new_thread(self.callbacks.onGetCurrentPosition,(self.lastFilePosition,)) thread.start_new_thread(self.callbacks.onGetCurrentPosition, (self.lastFilePosition,))
elif(cmd == self.CMD_NOTIFYSEEK): elif(cmd == self.CMD_NOTIFYSEEK):
if(self.lastFilePosition <> float(value)): #Notify seek is sometimes sent twice if(self.lastFilePosition <> float(value)): #Notify seek is sometimes sent twice
self.lastFilePosition = float(value) self.lastFilePosition = float(value)
if(self.callbacks.onSeek): if(self.callbacks.onSeek):
thread.start_new_thread(self.callbacks.onSeek,(self.lastFilePosition,)) thread.start_new_thread(self.callbacks.onSeek, (self.lastFilePosition,))
elif(cmd == self.CMD_DISCONNECT): elif(cmd == self.CMD_DISCONNECT):
if(self.callbacks.onMpcClosed): if(self.callbacks.onMpcClosed):
thread.start_new_thread(self.callbacks.onMpcClosed,(None,)) thread.start_new_thread(self.callbacks.onMpcClosed, (None,))
elif(cmd == self.CMD_VERSION): elif(cmd == self.CMD_VERSION):
if(self.callbacks.onVersion): if(self.callbacks.onVersion):
self.version = value self.version = value
thread.start_new_thread(self.callbacks.onVersion,(value,)) thread.start_new_thread(self.callbacks.onVersion, (value,))
class PlayerNotReadyException(Exception): class PlayerNotReadyException(Exception):
pass pass
@ -360,9 +360,9 @@ class MpcHcApi:
MLS_CLOSING = 3 MLS_CLOSING = 3
class __MPC_PLAYSTATE: class __MPC_PLAYSTATE:
PS_PLAY = 0 PS_PLAY = 0
PS_PAUSE = 1 PS_PAUSE = 1
PS_STOP = 2 PS_STOP = 2
PS_UNUSED = 3 PS_UNUSED = 3
class __Listener(threading.Thread): class __Listener(threading.Thread):
@ -405,7 +405,7 @@ class MpcHcApi:
#print "API:\tin>\t 0x%X\t" % int(pCDS.contents.dwData), ctypes.wstring_at(pCDS.contents.lpData) #print "API:\tin>\t 0x%X\t" % int(pCDS.contents.dwData), ctypes.wstring_at(pCDS.contents.lpData)
self.__mpcApi.handleCommand(pCDS.contents.dwData, ctypes.wstring_at(pCDS.contents.lpData)) self.__mpcApi.handleCommand(pCDS.contents.dwData, ctypes.wstring_at(pCDS.contents.lpData))
def SendCommand(self, cmd, message = u''): def SendCommand(self, cmd, message=u''):
#print "API:\t<out\t 0x%X\t" % int(cmd), message #print "API:\t<out\t 0x%X\t" % int(cmd), message
if not win32gui.IsWindow(self.mpcHandle): if not win32gui.IsWindow(self.mpcHandle):
if(self.__mpcApi.callbacks.onMpcClosed): if(self.__mpcApi.callbacks.onMpcClosed):
@ -414,14 +414,14 @@ class MpcHcApi:
cs.dwData = cmd; cs.dwData = cmd;
if(isinstance(message, (unicode, str))): if(isinstance(message, (unicode, str))):
message = ctypes.create_unicode_buffer(message, len(message)+1) message = ctypes.create_unicode_buffer(message, len(message) + 1)
elif(isinstance(message, ctypes.Structure)): elif(isinstance(message, ctypes.Structure)):
pass pass
else: else:
raise TypeError raise TypeError
cs.lpData = ctypes.addressof(message) cs.lpData = ctypes.addressof(message)
cs.cbData = ctypes.sizeof(message) cs.cbData = ctypes.sizeof(message)
ptr= ctypes.addressof(cs) ptr = ctypes.addressof(cs)
win32api.SendMessage(self.mpcHandle, win32con.WM_COPYDATA, self.hwnd, ptr) win32api.SendMessage(self.mpcHandle, win32con.WM_COPYDATA, self.hwnd, ptr)
class __COPYDATASTRUCT(ctypes.Structure): class __COPYDATASTRUCT(ctypes.Structure):

View File

@ -46,8 +46,8 @@ class ConfigurationGetter(object):
self._parser.add_argument('--no-gui', action='store_true', help='show no GUI') self._parser.add_argument('--no-gui', action='store_true', help='show no GUI')
self._parser.add_argument('-a', '--host', metavar='hostname', type=str, help='server\'s address') self._parser.add_argument('-a', '--host', metavar='hostname', type=str, help='server\'s address')
self._parser.add_argument('-n', '--name', metavar='username', type=str, help='desired username') self._parser.add_argument('-n', '--name', metavar='username', type=str, help='desired username')
self._parser.add_argument('-d','--debug', action='store_true', help='debug mode') self._parser.add_argument('-d', '--debug', action='store_true', help='debug mode')
self._parser.add_argument('-g','--force-gui-prompt', action='store_true', help='make configuration prompt appear') self._parser.add_argument('-g', '--force-gui-prompt', action='store_true', help='make configuration prompt appear')
self._parser.add_argument('--no-store', action='store_true', help='don\'t store values in syncplay.ini') self._parser.add_argument('--no-store', action='store_true', help='don\'t store values in syncplay.ini')
self._parser.add_argument('-r', '--room', metavar='room', type=str, nargs='?', help='default room') self._parser.add_argument('-r', '--room', metavar='room', type=str, nargs='?', help='default room')
self._parser.add_argument('-p', '--password', metavar='password', type=str, nargs='?', help='server password') self._parser.add_argument('-p', '--password', metavar='password', type=str, nargs='?', help='server password')

View File

@ -6,7 +6,7 @@ gtk.set_interactive(False)
import cairo, gio, pango, atk, pangocairo, gobject #@UnusedImport import cairo, gio, pango, atk, pangocairo, gobject #@UnusedImport
class GuiConfiguration: class GuiConfiguration:
def __init__(self, args, force = False): def __init__(self, args, force=False):
self.args = args self.args = args
self.closedAndNotSaved = False self.closedAndNotSaved = False
if(args.player_path == None or args.host == None or args.name == None or force): if(args.player_path == None or args.host == None or args.name == None or force):

View File

@ -1,7 +1,7 @@
from syncplay.ui.gui import GraphicalUI from syncplay.ui.gui import GraphicalUI
from syncplay.ui.consoleUI import ConsoleUI from syncplay.ui.consoleUI import ConsoleUI
def getUi(graphical = True): def getUi(graphical=True):
if(False): #graphical): #TODO: Add graphical ui if(False): #graphical): #TODO: Add graphical ui
ui = GraphicalUI() ui = GraphicalUI()
else: else:

View File

@ -26,7 +26,7 @@ class ConsoleUI(threading.Thread):
elif(self._syncplayClient): elif(self._syncplayClient):
self._executeCommand(data) self._executeCommand(data)
def promptFor(self, prompt = ">", message = ""): def promptFor(self, prompt=">", message=""):
if message <> "": if message <> "":
print(message) print(message)
self.promptMode.clear() self.promptMode.clear()
@ -34,9 +34,9 @@ class ConsoleUI(threading.Thread):
self.promptMode.wait() self.promptMode.wait()
return self.PromptResult return self.PromptResult
def showMessage(self, message, noTimestamp = False): def showMessage(self, message, noTimestamp=False):
if(os.name == "nt"): if(os.name == "nt"):
message = message.encode('ascii','replace') message = message.encode('ascii', 'replace')
if(noTimestamp): if(noTimestamp):
print(message) print(message)
else: else:
@ -50,7 +50,7 @@ class ConsoleUI(threading.Thread):
def __doSeek(self, m): def __doSeek(self, m):
if (m.group(4)): if (m.group(4)):
t = int(m.group(5))*60 + int(m.group(6)) t = int(m.group(5)) * 60 + int(m.group(6))
else: else:
t = int(m.group(2)) t = int(m.group(2))
if(m.group(1)): if(m.group(1)):
@ -58,7 +58,7 @@ class ConsoleUI(threading.Thread):
sign = -1 sign = -1
else: else:
sign = 1 sign = 1
t = self._syncplayClient.getGlobalPosition() + sign*t t = self._syncplayClient.getGlobalPosition() + sign * t
self._syncplayClient.setPosition(t) self._syncplayClient.setPosition(t)
def _executeCommand(self, data): def _executeCommand(self, data):
@ -81,13 +81,13 @@ class ConsoleUI(threading.Thread):
elif data == "p": elif data == "p":
self._syncplayClient.setPaused(not self._syncplayClient.getPlayerPaused()) self._syncplayClient.setPaused(not self._syncplayClient.getPlayerPaused())
elif data == 'help': elif data == 'help':
self.showMessage( "Available commands:", True) self.showMessage("Available commands:", True)
self.showMessage( "\thelp - this help", True ) self.showMessage("\thelp - this help", True)
self.showMessage( "\tr - revert last seek", True ) self.showMessage("\tr - revert last seek", True)
self.showMessage( "\tp - toggle pause", True ) self.showMessage("\tp - toggle pause", True)
self.showMessage( "\troom [name] - change room", True ) self.showMessage("\troom [name] - change room", True)
self.showMessage( "\t[s][+-][time] - seek to the given value of time, if + or - is not specified it's absolute time in seconds or min:sec", True ) self.showMessage("\t[s][+-][time] - seek to the given value of time, if + or - is not specified it's absolute time in seconds or min:sec", True)
self.showMessage("Syncplay version: {}".format(syncplay.version), True) self.showMessage("Syncplay version: {}".format(syncplay.version), True)
self.showMessage("More info available at: {}".format(syncplay.projectURL), True) self.showMessage("More info available at: {}".format(syncplay.projectURL), True)
else: else:
self.showMessage( "Unrecognized command, type 'help' for list of available commands" ) self.showMessage("Unrecognized command, type 'help' for list of available commands")