diff --git a/syncplay/client.py b/syncplay/client.py index 342e095..6feab5b 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -625,8 +625,8 @@ class SyncplayClient(object): if self._protocol and self._protocol.logged: self._protocol.sendList() - def showUserList(self): - self.userlist.showUserList() + def showUserList(self, altUI=None): + self.userlist.showUserList(altUI) def getPassword(self): return self._serverPassword @@ -1298,7 +1298,7 @@ class SyncplayUserlist(object): def hasRoomStateChanged(self): return self._roomUsersChanged - def showUserList(self): + def showUserList(self, altUI=None): rooms = {} for user in self._users.itervalues(): if user.room not in rooms: @@ -1308,7 +1308,10 @@ class SyncplayUserlist(object): rooms[self.currentUser.room] = [] rooms[self.currentUser.room].append(self.currentUser) rooms = self.sortList(rooms) - self.ui.showUserList(self.currentUser, rooms) + if altUI: + altUI.showUserList(self.currentUser, rooms) + else: + self.ui.showUserList(self.currentUser, rooms) self._client.autoplayCheck() def clearList(self): @@ -1407,6 +1410,9 @@ class UiManager(object): def updateRoomName(self, room=""): self.__ui.updateRoomName(room) + def executeCommand(self, command): + self.__ui.executeCommand(command) + def drop(self): self.__ui.drop() diff --git a/syncplay/players/mplayer.py b/syncplay/players/mplayer.py index 2d0289a..99bf7f4 100644 --- a/syncplay/players/mplayer.py +++ b/syncplay/players/mplayer.py @@ -338,7 +338,16 @@ class MplayerPlayer(BasePlayer): self.__playerController.drop() def sendChat(self, message): - self.__playerController.reactor.callFromThread(self.__playerController._client.sendChat, message) + if message: + if message[:1] == "/" and message <> "/": + command = message[1:] + if command and command[:1] == "/": + message = message[1:] + else: + self.__playerController.reactor.callFromThread(self.__playerController._client.ui.executeCommand, + command) + return + self.__playerController.reactor.callFromThread(self.__playerController._client.sendChat, message) def isReadyForSend(self): self.checkForReadinessOverride() diff --git a/syncplay/ui/consoleUI.py b/syncplay/ui/consoleUI.py index 868a43a..332a0ca 100644 --- a/syncplay/ui/consoleUI.py +++ b/syncplay/ui/consoleUI.py @@ -38,7 +38,7 @@ class ConsoleUI(threading.Thread): self.PromptResult = data self.promptMode.set() elif self._syncplayClient: - self._executeCommand(data) + self.executeCommand(data) except EOFError: pass @@ -136,7 +136,7 @@ class ConsoleUI(threading.Thread): return True return False - def _executeCommand(self, data): + def executeCommand(self, data): command = re.match(constants.UI_COMMAND_REGEX, data) if not command: return @@ -145,7 +145,7 @@ class ConsoleUI(threading.Thread): self._syncplayClient.setPosition(self._syncplayClient.playerPositionBeforeLastSeek) self._syncplayClient.playerPositionBeforeLastSeek = tmp_pos elif command.group('command') in constants.COMMANDS_LIST: - self._syncplayClient.getUserList() + self.getUserlist() elif command.group('command') in constants.COMMANDS_CHAT: message= command.group('parameter') self._syncplayClient.sendChat(message) @@ -158,8 +158,8 @@ class ConsoleUI(threading.Thread): room = self._syncplayClient.userlist.currentUser.file["name"] else: room = self._syncplayClient.defaultRoom - self._syncplayClient.setRoom(room, resetAutoplay=True) + self._syncplayClient.ui.updateRoomName(room) self._syncplayClient.sendRoom() elif command.group('command') in constants.COMMANDS_CREATE: roombasename = command.group('parameter') @@ -190,4 +190,6 @@ class ConsoleUI(threading.Thread): self.showMessage(getMessage("commandlist-notification/chat"), True) self.showMessage(getMessage("syncplay-version-notification").format(syncplay.version), True) self.showMessage(getMessage("more-info-notification").format(syncplay.projectURL), True) - + + def getUserlist(self): + self._syncplayClient.getUserList() \ No newline at end of file diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index 4250d6f..c4b1fcd 100644 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -11,8 +11,25 @@ import os from syncplay.utils import formatTime, sameFilename, sameFilesize, sameFileduration, RoomPasswordProvider, formatSize, isURL from functools import wraps from twisted.internet import task +from syncplay.ui.consoleUI import ConsoleUI lastCheckedForUpdates = None +class ConsoleInGUI(ConsoleUI): + def showMessage(self, message, noTimestamp=False): + self._syncplayClient.ui.showMessage(message, True) + + def showDebugMessage(self, message): + self._syncplayClient.ui.showDebugMessage(message) + + def showErrorMessage(self, message, criticalerror=False): + self._syncplayClient.ui.showErrorMessage(message, criticalerror) + + def updateRoomName(self, room=""): + self._syncplayClient.ui.updateRoomName(room) + + def getUserlist(self): + self._syncplayClient.showUserList(self) + class UserlistItemDelegate(QtGui.QStyledItemDelegate): def __init__(self): QtGui.QStyledItemDelegate.__init__(self) @@ -297,6 +314,8 @@ class MainWindow(QtGui.QMainWindow): def addClient(self, client): self._syncplayClient = client + if self.console: + self.console.addClient(client) self.roomInput.setText(self._syncplayClient.getRoom()) self.config = self._syncplayClient.getConfig() try: @@ -330,8 +349,6 @@ class MainWindow(QtGui.QMainWindow): def setFeatures(self, featureList): if not featureList["readiness"]: self.readyPushButton.setEnabled(False) - if not featureList["chat"]: - self.chatFrame.setEnabled(False) if not featureList["sharedPlaylists"]: self.playlistGroup.setEnabled(False) @@ -1046,10 +1063,22 @@ class MainWindow(QtGui.QMainWindow): self._syncplayClient.playlist.changePlaylist(newPlaylist) self._syncplayClient.fileSwitch.updateInfo() + def executeCommand(self, command): + self.showMessage(u"/{}".format(command)) + self.console.executeCommand(command) + def sendChatMessage(self): - if self.chatInput.text() <> "": - self._syncplayClient.sendChat(self.chatInput.text()) - self.chatInput.setText("") + chatText = self.chatInput.text() + self.chatInput.setText("") + if chatText <> "": + if chatText[:1] == "/" and chatText <> "/": + command = chatText[1:] + if command and command[:1] == "/": + chatText = chatText[1:] + else: + self.executeCommand(command) + return + self._syncplayClient.sendChat(chatText) def addTopLayout(self, window): window.topSplit = self.topSplitter(Qt.Horizontal, self) @@ -1608,6 +1637,8 @@ class MainWindow(QtGui.QMainWindow): def __init__(self): super(MainWindow, self).__init__() + self.console = ConsoleInGUI() + self.console.setDaemon(True) self.newWatchlist = [] self.publicServerList = [] self.lastCheckedForUpdates = None