From 270a10de1bdf1c0514ec316571b43dae62a1833b Mon Sep 17 00:00:00 2001 From: DonRenando Date: Fri, 3 Apr 2015 14:51:22 +0200 Subject: [PATCH] c'est une turie git add .! --- client/view/mainWindow.py | 32 ++++++++++++++-- client/view/mainWindow.ui | 57 ++++++++++++++++++++++++++--- client/view/start.py | 77 +++++++++++++++++++++++++++++++++++---- 3 files changed, 150 insertions(+), 16 deletions(-) diff --git a/client/view/mainWindow.py b/client/view/mainWindow.py index ca1fe1b..ef3a5df 100755 --- a/client/view/mainWindow.py +++ b/client/view/mainWindow.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'mainWindow.ui' # -# Created: Tue Mar 31 12:14:51 2015 +# Created: Fri Apr 3 14:33:44 2015 # by: PyQt4 UI code generator 4.11.3 # # WARNING! All changes made in this file will be lost! @@ -73,14 +73,33 @@ class Ui_Dialog(object): self.pushButton.setObjectName(_fromUtf8("pushButton")) self.horizontalLayout.addWidget(self.pushButton) self.horizontalLayoutWidget_2 = QtGui.QWidget(Dialog) - self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(470, 20, 291, 51)) + self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(20, 40, 741, 51)) self.horizontalLayoutWidget_2.setObjectName(_fromUtf8("horizontalLayoutWidget_2")) self.horizontalLayout_2 = QtGui.QHBoxLayout(self.horizontalLayoutWidget_2) self.horizontalLayout_2.setMargin(0) self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2")) + self.label_3 = QtGui.QLabel(self.horizontalLayoutWidget_2) + self.label_3.setObjectName(_fromUtf8("label_3")) + self.horizontalLayout_2.addWidget(self.label_3) + self.lineEdit_4 = QtGui.QLineEdit(self.horizontalLayoutWidget_2) + self.lineEdit_4.setInputMask(_fromUtf8("")) + self.lineEdit_4.setObjectName(_fromUtf8("lineEdit_4")) + self.horizontalLayout_2.addWidget(self.lineEdit_4) + self.label_4 = QtGui.QLabel(self.horizontalLayoutWidget_2) + self.label_4.setObjectName(_fromUtf8("label_4")) + self.horizontalLayout_2.addWidget(self.label_4) + self.lineEdit_3 = QtGui.QLineEdit(self.horizontalLayoutWidget_2) + self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3")) + self.horizontalLayout_2.addWidget(self.lineEdit_3) + self.label_5 = QtGui.QLabel(self.horizontalLayoutWidget_2) + self.label_5.setObjectName(_fromUtf8("label_5")) + self.horizontalLayout_2.addWidget(self.label_5) self.lineEdit_2 = QtGui.QLineEdit(self.horizontalLayoutWidget_2) self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2")) self.horizontalLayout_2.addWidget(self.lineEdit_2) + self.pushButton_6 = QtGui.QPushButton(self.horizontalLayoutWidget_2) + self.pushButton_6.setObjectName(_fromUtf8("pushButton_6")) + self.horizontalLayout_2.addWidget(self.pushButton_6) self.pushButton_3 = QtGui.QPushButton(self.horizontalLayoutWidget_2) self.pushButton_3.setObjectName(_fromUtf8("pushButton_3")) self.horizontalLayout_2.addWidget(self.pushButton_3) @@ -114,7 +133,7 @@ class Ui_Dialog(object): self.txtOutput.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction) self.txtOutput.setObjectName(_fromUtf8("txtOutput")) self.label_2 = QtGui.QLabel(Dialog) - self.label_2.setGeometry(QtCore.QRect(30, 30, 421, 31)) + self.label_2.setGeometry(QtCore.QRect(20, 10, 171, 31)) font = QtGui.QFont() font.setPointSize(16) font.setBold(True) @@ -130,6 +149,13 @@ class Ui_Dialog(object): self.label.setText(_translate("Dialog", "Nick list", None)) self.listNames.setSortingEnabled(True) self.pushButton.setText(_translate("Dialog", "Send message", None)) + self.label_3.setText(_translate("Dialog", "IP : ", None)) + self.lineEdit_4.setText(_translate("Dialog", "127.0.0.1", None)) + self.label_4.setText(_translate("Dialog", "Port :", None)) + self.lineEdit_3.setText(_translate("Dialog", "2222", None)) + self.label_5.setText(_translate("Dialog", "Pseudo :", None)) + self.lineEdit_2.setText(_translate("Dialog", "anonymous", None)) + self.pushButton_6.setText(_translate("Dialog", "Change pseudo", None)) self.pushButton_3.setText(_translate("Dialog", "Disconnect", None)) self.pushButton_2.setText(_translate("Dialog", "Connect", None)) self.pushButton_5.setText(_translate("Dialog", "Disable", None)) diff --git a/client/view/mainWindow.ui b/client/view/mainWindow.ui index 4911368..76477b7 100755 --- a/client/view/mainWindow.ui +++ b/client/view/mainWindow.ui @@ -118,13 +118,51 @@ - 470 - 20 - 291 + 20 + 40 + 741 51 + + + + IP : + + + + + + + + + + 127.0.0.1 + + + + + + + Port : + + + + + + + 2222 + + + + + + + Pseudo : + + + @@ -132,6 +170,13 @@ + + + + Change pseudo + + + @@ -222,9 +267,9 @@ p, li { white-space: pre-wrap; } - 30 - 30 - 421 + 20 + 10 + 171 31 diff --git a/client/view/start.py b/client/view/start.py index fb10d9b..855faca 100755 --- a/client/view/start.py +++ b/client/view/start.py @@ -2,12 +2,12 @@ from mainWindow import Ui_Dialog from PyQt4 import QtGui, QtCore from PySide.QtCore import * from PySide.QtGui import * -import time, threading, datetime, time +import time, threading, datetime, time, random from socket import * Host = "127.0.0.1" Port = 2222 -Addr = (Host, Port) + class MySignal(QObject): @@ -75,22 +75,34 @@ class start(QtGui.QDialog): def ShowMessageErreur(self, txt): self.message_buffer += '
'+ self.htmlToText(txt) +' ' + + def ShowMessageOK(self, txt): + self.message_buffer += '
'+ self.htmlToText(txt) +' ' def ShowMessageAsText(self, txt): - self.message_buffer += '
'+ txt +' ' + self.message_buffer += '
'+ txt.split(" ")[0] +' ' + + if txt.split(" ")[0] == "SUCCESSFUL_LOGOUT" : + self.ShowMessageOK("Sucessful logout !") + + if txt.split(" ")[0] == "SUCC_VALID_NICKNAME" : + self.ShowMessageOK("Sucessful nickname change !") + + + if txt.split(" ")[0] == "NAME_CHANGED" : self.ShowMessageNameChange(txt.split(" ")[1], txt.split(" ")[2]) if txt.split(" ")[0] == "HAS_JOIN" : self.ShowMessageHasJoin(txt.split(" ")[1]) - if txt.split(" ")[0] == "SUCC_CHANNEL_JOINED" : + if txt.split(" ")[0] == "SUCC_CHANNEL_JOINED" or txt.split(" ")[0] == "SUCC_CHANNEL_JOINEDUSERLIST" : self.ShowMessageHasJoin(self.pseudo) - + if txt.split(" ")[0] == "NEW_MSG" : self.message_buffer += '
' + self.getTimeStamp() + ' < '+txt.split(" ")[1] +' > ' + self.htmlToText(' '.join(txt.split(" ")[2:])) + '' @@ -121,9 +133,34 @@ class start(QtGui.QDialog): self.ui.pushButton_2.clicked.connect(self.connecter) self.ui.pushButton_3.clicked.connect(self.deco) self.ui.pushButton.clicked.connect(self.client) + self.ui.pushButton_6.clicked.connect(self.changeN) + def changeN(self): + changePseudo = self.ui.lineEdit_2.text() + cmdChange = "/name "+changePseudo + try: + self.s.send(cmdChange.encode()) + self.pseudo = changePseudo + + + except timeout: + self.ShowMessageErreur("Erreur : Timeout. Le serveur ne repond pas") + self.ui.txtOutput.setText(self.message_buffer) + sb = self.ui.txtOutput.verticalScrollBar() + sb.setValue(sb.maximum()) + + + def connecter(self): - #lineEdit_2 + + ip= self.ui.lineEdit_4.text() + port = int(self.ui.lineEdit_3.text()) + if ip is None or port is None : + Addr = (Host, Port) + else : + Addr = (ip,port) + + self.s = socket(AF_INET, SOCK_STREAM) self.s.connect(Addr) self.thread.setConfig(self.s,self) @@ -132,13 +169,34 @@ class start(QtGui.QDialog): self.ui.pushButton_2.setDisabled(True) self.ui.pushButton_3.setDisabled(False) self.thread.start() + + + cmd2 = self.ui.lineEdit_2.text() + if cmd2 != "": + self.s.settimeout(5.0) + cmdPseudo = "/newname "+cmd2 + try: + self.s.send(cmdPseudo.encode()) + self.pseudo = cmd2 + self.ui.pushButton_6.setDisabled(False) + + + except timeout: + self.ShowMessageErreur("Erreur : Timeout. Le serveur ne repond pas") + self.ui.txtOutput.setText(self.message_buffer) + sb = self.ui.txtOutput.verticalScrollBar() + sb.setValue(sb.maximum()) def deco(self): - self.s.close() + quitter = "/quit" + self.s.send(quitter.encode()) + #self.s.close() self.ui.lineEdit.setDisabled(True) self.ui.pushButton.setDisabled(True) self.ui.pushButton_2.setDisabled(False) + self.ui.pushButton_3.setDisabled(True) + self.ui.pushButton_6.setDisabled(True) def ecoute(self): while 1 : @@ -159,10 +217,15 @@ class start(QtGui.QDialog): self.ui = Ui_Dialog() self.ui.setupUi(self) + ano = "anonymous" + ''.join(str(random.randint(1,9)) for _ in range(2)) + self.ui.lineEdit_2.setText(ano) + self.ui.lineEdit.setDisabled(True) self.ui.pushButton.setDisabled(True) self.ui.pushButton_3.setDisabled(True) + self.ui.pushButton_6.setDisabled(True) self.message_buffer = "" + self.connectActions()