def sendParser(gui,message): """ Retrieves the text from the entry field, parses it and sends it to the server in a bytearray form. Keyword arguments: event - The return-key was pressent Side-effects: Checks if the command is valid. If so, sends it to the server """ options = initiateSwitch() argumentString = MiscUtils.messageSplit(message) if (argumentString[0] == "/connect"): connect(argumentString,gui) elif (gui.socketStatus != "ok"): TabUtils.writeMessage(gui,"You are not connected to a server, use /connect IP") gui.message.delete(0,END) else: if argumentString[0] in options: options[argumentString[0]](argumentString,gui) else: msg_temp = gui.currentTab + " " + message+'\n' sendToServer(gui,msg_temp)
def checkQueue(gui): """ Parses the answer from the server and performes the corresponding command. Side effects: Can be one of the following: A new tab is created, the username is changed, a message is printed in the current window. """ stopSign = 1 respons = gui.thread.returnQueue() if(respons[0][0] == "{"): options = initDictionary() temp = respons[1:len(respons)-2] if " " in temp: commandString = MiscUtils.messageSplit(temp) if commandString[0] == 'disconnected': stopSign = 0 disconnected(gui) else: if commandString[0] in options: options[commandString[0]](gui,commandString[1]) else: fillUserList(gui,commandString) else: fillRoomList(gui,temp) else: printMessage(gui,respons) if stopSign == 1: gui.master.after(50,checkQueue,gui)
def join(argument,gui): success = 0 if (" " in argument[1]): argumentString2 = MiscUtils.messageSplit(argument[1]) if MiscUtils.noDuplicate(gui.windowList,argumentString2[0]): success = 1 arguments = 2 else: if MiscUtils.noDuplicate(gui.windowList,argument[1]): success = 1 arguments = 1 if success == 1: if (arguments == 2): msg_temp = argument[0] + " " + argument[0]+ " " + argument[1]+'\n' else: msg_temp = argument[1] + " " + argument[0]+ " " + argument[1]+'\n' sendToServer(gui,msg_temp) else: TabUtils.writeMessage(gui,"You are already a member of that room!") gui.message.delete(0,END)
def success(gui,arguments): command = MiscUtils.messageSplit(arguments) gui.rooms[command[0]] = [command[0],command[1]] TabUtils.addTab(gui,command[0])
def printMessage(gui,message): argumentString = MiscUtils.messageSplit(message) gui.windowList[argumentString[0]].config(state=NORMAL) gui.windowList[argumentString[0]].insert(END,MiscUtils.GetTime() + argumentString[1]) gui.windowList[argumentString[0]].yview(END) gui.windowList[argumentString[0]].config(state=DISABLED)