Execute /commands in chat as if console input
This commit is contained in:
parent
b57e5e28c0
commit
55e5d8f270
@ -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,6 +1308,9 @@ class SyncplayUserlist(object):
|
||||
rooms[self.currentUser.room] = []
|
||||
rooms[self.currentUser.room].append(self.currentUser)
|
||||
rooms = self.sortList(rooms)
|
||||
if altUI:
|
||||
altUI.showUserList(self.currentUser, rooms)
|
||||
else:
|
||||
self.ui.showUserList(self.currentUser, rooms)
|
||||
self._client.autoplayCheck()
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
@ -338,6 +338,15 @@ class MplayerPlayer(BasePlayer):
|
||||
self.__playerController.drop()
|
||||
|
||||
def sendChat(self, 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):
|
||||
|
||||
@ -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')
|
||||
@ -191,3 +191,5 @@ class ConsoleUI(threading.Thread):
|
||||
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()
|
||||
@ -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())
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user