diff --git a/syncplay/ui/__init__.py b/syncplay/ui/__init__.py new file mode 100644 index 0000000..3762faa --- /dev/null +++ b/syncplay/ui/__init__.py @@ -0,0 +1,10 @@ +from syncplay.ui.gui import GraphicalUI +from syncplay.ui.consoleUI import ConsoleUI +def getUi(graphical = True): + if(graphical): + return GraphicalUI() + else: + ui = ConsoleUI() + ui.setDaemon(True) + ui.start() + return ui \ No newline at end of file diff --git a/syncplay/ui/consoleUI.py b/syncplay/ui/consoleUI.py new file mode 100644 index 0000000..bf46362 --- /dev/null +++ b/syncplay/ui/consoleUI.py @@ -0,0 +1,45 @@ +''' +Created on 05-07-2012 + +@author: Uriziel +''' +from __future__ import print_function +import threading + + +class ConsoleUI(threading.Thread): + def __init__(self): + self.promptMode = threading.Event() + self.PromptResult = "" + self.promptMode.set() + self._syncplayClient = None + threading.Thread.__init__(self, name="ConsoleUI") + + def addManager(self, manager): + self._syncplayClient = manager + + def run(self): + try: + while True: + data = raw_input() + if not data: + break + data = data.rstrip('\n\r') + if(not self.promptMode.isSet()): + self.PromptResult = data + self.promptMode.set() + elif(self._syncplayClient): + self._syncplayClient.execute_command(data) + except: + raise + + def promptFor(self, promptName = ">", message = ""): + print(message) + self.promptMode.clear() + print(promptName+": ", end='') + self.promptMode.wait() + return self.PromptResult + + def showMessage(self, message): + print(message) + diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py new file mode 100644 index 0000000..661c2f7 --- /dev/null +++ b/syncplay/ui/gui.py @@ -0,0 +1,9 @@ +''' +Created on 05-07-2012 + +@author: Uriziel +''' + +class GraphicalUI(object): + def __init__(self): + pass \ No newline at end of file diff --git a/syncplay_mpc.py b/syncplay_mpc.py new file mode 100644 index 0000000..9983ea4 --- /dev/null +++ b/syncplay_mpc.py @@ -0,0 +1,21 @@ +#coding:utf8 +from syncplay import client +from syncplay.players import mpc + +from syncplay import utils + + +def prepareArguments(): + args = utils.MPCConfigurationGetter() + args.prepareClientConfiguration() + return args.getClientConfiguration() + +if __name__ == '__main__': + manager = None + try: + args = prepareArguments() + manager = client.Manager(args.host, args.port, args.name, lambda m: mpc.run_mpc(m, args.mpc_path, args.file, args._args)) + manager.start() + finally: + if(manager): manager.stop() + diff --git a/syncplay_mplayer.py b/syncplay_mplayer.py new file mode 100644 index 0000000..221adb0 --- /dev/null +++ b/syncplay_mplayer.py @@ -0,0 +1,18 @@ +#coding:utf8 +from syncplay import client +from syncplay.players import mplayer + +from syncplay import utils + +def prepareArguments(): + args = utils.ConfigurationGetter() + args.prepareClientConfiguration() + return args.getClientConfiguration() + +if __name__ == '__main__': + args = prepareArguments() + args.args.extend(('-slave', '-msglevel', 'all=1:global=4')) + if(args.file): args.args.extend((args.file,)) + manager = client.Manager(args.host, args.port, args.name, lambda m: mplayer.run_mplayer(m, 'mplayer', args.args)) + manager.start() +