diff --git a/syncplay/client.py b/syncplay/client.py index 92ab1c5..871cd8a 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -2,11 +2,9 @@ from .network_utils import argumentCount, CommandProtocol from .utils import ArgumentParser, format_time -from syncplay import utils from twisted.internet import reactor from twisted.internet.protocol import ClientFactory import re -import threading import time class SyncClientProtocol(CommandProtocol): @@ -163,7 +161,6 @@ class SyncClientProtocol(CommandProtocol): def send_playing(self, filename): self._protocol.sendMessage('playing', filename) - class SyncClientFactory(ClientFactory): def __init__(self, manager): self._syncplayClient = manager @@ -195,11 +192,8 @@ class SyncClientFactory(ClientFactory): def stop_retrying(self): self.retry = False - -class Manager(object): - def __init__(self, host, port, name, make_player, ui, debug): - self.host = host - self.port = port +class SyncplayClientManager(object): + def __init__(self, name, make_player, ui, debug): self.name = name self.ui = self.UiManager(ui, debug) @@ -230,15 +224,12 @@ class Manager(object): self.make_player = make_player self.running = False - command_handler = threading.Thread(target = utils.stdin_thread, args = (self,), name = "Command handler") - command_handler.setDaemon(True) - command_handler.start() - def start(self): + def start(self, host, port): if self.running: return self.protocol_factory = SyncClientFactory(self) - reactor.connectTCP(self.host, self.port, self.protocol_factory) + reactor.connectTCP(host, port, self.protocol_factory) self.running = True reactor.run() diff --git a/syncplay/ui/consoleUI.py b/syncplay/ui/consoleUI.py index be7aaff..826eac1 100644 --- a/syncplay/ui/consoleUI.py +++ b/syncplay/ui/consoleUI.py @@ -15,8 +15,8 @@ class ConsoleUI(threading.Thread): self._syncplayClient = None threading.Thread.__init__(self, name="ConsoleUI") - def addManager(self, manager): - self._syncplayClient = manager + def addClient(self, client): + self._syncplayClient = client def run(self): try: diff --git a/syncplay/utils.py b/syncplay/utils.py index 1ec3bc3..44be4f3 100644 --- a/syncplay/utils.py +++ b/syncplay/utils.py @@ -90,7 +90,7 @@ class ConfigurationGetter(object): def _findWorkingDirectory(self): frozen = getattr(sys, 'frozen', '') if not frozen: - self._workingDir = os.path.dirname(__file__) + self._workingDir = os.path.dirname(os.path.dirname(__file__)) elif frozen in ('dll', 'console_exe', 'windows_exe'): self._workingDir = os.path.dirname(sys.executable) else: @@ -115,7 +115,7 @@ class ConfigurationGetter(object): def _getSectionName(self): return 'sync' if not self._args.debug else 'debug' - def _saveValuesIntoConfigFile(self): + def saveValuesIntoConfigFile(self): self._openConfigFile() section_name = self._getSectionName() if(not self._args.no_store): @@ -157,6 +157,7 @@ class ConfigurationGetter(object): self._prepareArgParser() self._args = self._parser.parse_args() self._readMissingValuesFromConfigFile() + self.saveValuesIntoConfigFile() self._splitPortAndHost() def getClientConfiguration(self): diff --git a/syncplay_mpc.py b/syncplay_mpc.py index bbbd0ca..52fbcd2 100644 --- a/syncplay_mpc.py +++ b/syncplay_mpc.py @@ -7,14 +7,15 @@ from syncplay import utils class SyncplayMPC: def runClient(self): self._prepareArguments() - interface = ui.getUi(graphical = not self.args.no_gui) + self.interface = ui.getUi(graphical = not self.args.no_gui) self._promptForMissingArguments() - manager = client.Manager(self.args.host, self.args.port, self.args.name, lambda m: mpc.run_mpc(m, self.args.mpc_path, self.args.file, self.args._args), interface, self.args.debug) - manager.start() + syncplayClient = client.SyncplayClientManager(self.args.name, lambda m: mpc.run_mpc(m, self.args.mpc_path, self.args.file, self.args._args), self.interface, self.args.debug) + self.interface.addClient(syncplayClient) + syncplayClient.start(self.args.host, self.args.port) def _prepareArguments(self): - args = utils.MPCConfigurationGetter() - args.prepareClientConfiguration() - self.args = args.getClientConfiguration() + self.argsGetter = utils.MPCConfigurationGetter() + self.argsGetter.prepareClientConfiguration() + self.args = self.argsGetter.getClientConfiguration() def _promptForMissingArguments(self): if (self.args.host == None): @@ -23,7 +24,7 @@ class SyncplayMPC: self.args.name = self.interface.promptFor(promptName = "Username", message = "You must supply username on the first run, it's easier trough command line arguments.") if (self.args.mpc_path == None): self.args.mpc_path = self.interface.promptFor(promptName = "Path to mpc-hc.exe", message = "You must supply path to mpc on the first run, it's easier trough command line arguments.") - + self.argsGetter.saveValuesIntoConfigFile() if __name__ == '__main__': SyncplayMPC().runClient() diff --git a/syncplay_mplayer.py b/syncplay_mplayer.py index 221adb0..db2cf3f 100644 --- a/syncplay_mplayer.py +++ b/syncplay_mplayer.py @@ -13,6 +13,6 @@ 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() + manager = client.SyncplayClientManager(args.name, lambda m: mplayer.run_mplayer(m, 'mplayer', args.args)) + manager.start(args.host, args.port)