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 __init__(self,master): self.master = master Gstyle = ttk.Style() Gstyle.configure("TNotebook", background="#121A16", borderwidth=0) Gstyle.configure("TNotebook.Tab", background='#545854',foreground="black",borderwidth=1) self.nb = ttk.Notebook(master,style='TNotebook') self.nb.place(x=122, y=0) self.userWindow = Listbox(master, width=15,height=24) self.userWindow.config(background="#121A16",foreground="#00EB00",highlightthickness=0) self.userWindow.place(x=0,y=23) self.roomWindow = Listbox(master, width=15,height=24) self.roomWindow.config(background="#121A16",foreground="#00EB00",highlightthickness=0) self.roomWindow.place(x=689,y=23) self.roomLabel = Label(master,text="Available Rooms",font=("Helvetica",10)) self.roomLabel.config(background="#121A16",foreground="#00EB00") self.roomLabel.place(x=695,y=0) self.userLabel = Label(master,text="Users",font=("Helvetica",10)) self.userLabel.config(background="#121A16",foreground="#00EB00") self.userLabel.place(x=30,y=0) self.temp = StringVar() self.message = Entry(master,width=70,textvariable = self.temp) self.message.config(background = "#121A16",foreground="#00EB00",insertbackground="#00EB00") self.message.place(x=123,y=388) self.message.bind('<Return>',self.sendMessage) self.windowList = {} self.userList = {} self.rooms = {} self.configList = {} self.userList["global"] = [''] self.socketStatus = "disconnected" self.initiateConfig() self.currentTab = "global" self.nb.bind_all("<<NotebookTabChanged>>", lambda e: TabUtils.tabChangedEvent(e,gui)) self.serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.master.protocol('WM_DELETE_WINDOW', lambda: ConnectionUtils.closeClient(self)) self.menues = Menues(self) TabUtils.addTab(self,"global")
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 clear(argument,gui): TabUtils.clearWindow(gui.windowList[gui.currentTab]) gui.message.delete(0,END)
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 invited(gui,arguments): if(MiscUtils.noDuplicate(gui.windowList,arguments)): TabUtils.addTab(gui,arguments)
def success(gui,arguments): command = MiscUtils.messageSplit(arguments) gui.rooms[command[0]] = [command[0],command[1]] TabUtils.addTab(gui,command[0])
def error(gui,arguments): TabUtils.writeMessage(gui,"The room is private, you need an invitation")
def fillUserList(gui,arguments): gui.userList[arguments[0]] = arguments[1].split(",") if (arguments[0] == gui.currentTab): TabUtils.fillUserList(gui)
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)
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()