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 disconnected(gui): gui.socketStatus = "disconnected" ConnectionUtils.disconnect(gui) if gui.configList["reconnectMode"] == 'auto': TabUtils.writeMessage(gui,"Lost the connection, trying to reconnect automaticly") ConnectionUtils.connect(gui) else: TabUtils.writeMessage(gui,"Lost the connection. Use /connect IP to connect manually")
def whois(gui,arguments): whoisInfo = arguments.split(",") TabUtils.writeMessage(gui,"") TabUtils.writeMessage(gui,"------------------------") for element in whoisInfo: TabUtils.writeMessage(gui,element) TabUtils.writeMessage(gui,"------------------------") TabUtils.writeMessage(gui,"")
def leave(argument,gui): if argument[1] == "global": TabUtils.writeMessage("You cannot leave global!") gui.message.delete(0,END) else: if(not MiscUtils.noDuplicate(gui.windowList,argument[1])): TabUtils.deleteTab(gui,argument[1]) gui.windowList.pop(argument[1],None) gui.menues.updateRoomList(gui.windowList) msg_temp ="global" + " " + argument[0] + " " +argument[1] +'\n' sendToServer(gui,msg_temp) else: gui.writeMessage("You are not a member of the room " + argument[1] +"!") gui.message.delete(0,END)
def connect(argument,gui): if(gui.socketStatus == "disconnected"): if gui.configList["ipAdress"] != argument[1]: TabUtils.deleteAllTabs(gui) TabUtils.clearWindowList(gui.windowList) gui.configList["ipAdress"] = argument[1] ConnectionUtils.connect(gui) else: if argument[1] == gui.configList["ipAdress"]: TabUtils.writeMessage(gui,"You are already connected to " +argument[1]) else: ConnectionUtils.disconnect(gui) TabUtils.deleteAllTabs(gui) TabUtils.clearWindowList(gui.windowList) gui.configList["ipAdress"] = argument[1] if gui.configList["reconnectMode"] != "auto": gui.master.after(100,ConnectionUtils.connect,gui) gui.message.delete(0,END)
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 checkConnectQueue(gui,thread): """ Parses the result from a connection attempt. Keyword arguments: thread - The thread attempting to connect. """ result = thread.returnQueue() if (result == "empty"): gui.master.after(500,checkConnectQueue,gui,thread) elif (result == "Connected"): gui.message.config(state=NORMAL) gui.socketStatus = "ok" TabUtils.writeMessage(gui,"You are now connected to " + gui.configList["ipAdress"] + "!") gui.Start() gui.menues = Menues(gui) ConnectionUtils.sendUserName(gui) ConnectionUtils.timeout_update(gui) gui.message.delete(0,END) if gui.configList["restoreTabs"] == "auto" and len(gui.windowList) > 1: TabUtils.restoreTabs(gui) else: TabUtils.deleteAllTabs(gui) TabUtils.clearWindowList(gui.windowList) elif (result == "Failed"): TabUtils.writeMessage(gui,"Connection failed, use /connect IP to try again") gui.message.config(state=NORMAL) gui.message.delete(0,END) else: TabUtils.writeMessage(gui,"No response from server. New attempt in " + gui.configList["delay"] + " seconds. " + str(result) + " attempts left") gui.master.after(2000,checkConnectQueue,gui,thread)
def track(gui,arguments): trackList = arguments.split(",") TabUtils.writeMessage(gui,"") TabUtils.writeMessage(gui,"-------------------------------------") TabUtils.writeMessage(gui,"The user is a member of:") for element in trackList: TabUtils.writeMessage(gui,element) TabUtils.writeMessage(gui,"-------------------------------------") TabUtils.writeMessage(gui,"")
def error(gui,arguments): TabUtils.writeMessage(gui,"The room is private, you need an invitation")
self.configList[element] = message ####################################################################################### def initiateConnection(self): ConnectionUtils.connect(self) ####################################################################################### if __name__ == "__main__": """ The main function. """ root=Tk() root.geometry("810x408") root.configure(background="#121A16") root.title("Nuntii IRC") gui=GUI(root) gui.windowList["global"].config(state=NORMAL) gui.windowList["global"].insert(END,"Welcome "+gui.configList["userName"] +"!\n") gui.windowList["global"].insert(END,"----------------------------------------\n") gui.windowList["global"].config(state=DISABLED) if gui.configList["reconnectMode"] == 'auto': gui.initiateConnection() else: TabUtils.writeMessage(gui,"You are not connected to a server, use /connect IP") root.mainloop()