This repository has been archived on 2021-09-15. You can view files and clone it, but cannot push or open issues or pull requests.
L3DNC/client/view/start.py

547 lines
20 KiB
Python
Raw Normal View History

2015-03-30 21:39:02 +02:00
from mainWindow import Ui_Dialog
2015-03-30 14:21:11 +02:00
from PyQt4 import QtGui, QtCore
from PySide.QtCore import *
from PySide.QtGui import *
2015-04-03 20:07:29 +02:00
import time, threading, datetime, time, random,re
2015-03-31 11:52:01 +02:00
from socket import *
2015-04-06 17:11:47 +02:00
from pmWindow import Ui_Dialog2
2015-04-08 15:23:48 +02:00
import configparser
2015-04-03 14:51:22 +02:00
2015-03-30 14:21:11 +02:00
class MySignal(QObject):
sig = Signal(str)
class MyLongThread(QThread):
def __init__(self, parent = None):
QThread.__init__(self, parent)
self.exiting = False
self.signal = MySignal()
def run(self):
end = time.time()+10
while self.exiting==False:
sys.stdout.write('*')
sys.stdout.flush()
time.sleep(1)
now = time.time()
if now>=end:
self.exiting=True
self.signal.sig.emit('OK')
class MyThread(QThread):
def __init__(self, parent = None):
QThread.__init__(self, parent)
self.exiting = False
def run(self):
self.s.settimeout(None)
data = self.s.recv(4096)
messgServeur = (data.decode())
self.gui.setNewMsg(messgServeur)
def setConfig(self,s,gui):
self.s = s
self.gui = gui
2015-04-04 23:56:10 +02:00
class privateMessage () :
2015-04-07 19:27:33 +02:00
def __init__(self,main,s, pmPerson, pmPerso):
2015-04-05 13:44:36 +02:00
2015-04-04 23:56:10 +02:00
self.main = main
2015-04-05 13:44:36 +02:00
self.s = s
2015-04-07 19:27:33 +02:00
self.pmPerso = pmPerso
2015-04-06 17:11:47 +02:00
self.pmPerson = pmPerson
2015-04-04 23:56:10 +02:00
self.g = QtGui.QWidget()
2015-04-06 17:11:47 +02:00
self.ui = Ui_Dialog2()
2015-04-04 23:56:10 +02:00
self.ui.setupUi(self.g)
self.g.show()
2015-04-05 13:44:36 +02:00
old = start()
2015-04-06 17:11:47 +02:00
self.message_buffer2 = ""
2015-04-05 13:44:36 +02:00
2015-04-06 17:11:47 +02:00
self.queueMsg2= []
2015-04-05 13:44:36 +02:00
self.thread = MyThread()
2015-04-06 17:11:47 +02:00
self.thread.finished.connect(self.UpdateChatP)
2015-04-05 13:44:36 +02:00
self.ui.pushButton.clicked.connect(self.send)
2015-04-07 19:27:33 +02:00
self.ui.pushButton_3.clicked.connect(self.accept)
2015-04-05 13:44:36 +02:00
self.ui.pushButton_2.clicked.connect(self.selectFile)
2015-04-06 17:11:47 +02:00
self.ui.label_2.setText(pmPerson)
2015-04-05 13:44:36 +02:00
2015-04-07 19:27:33 +02:00
def accept(self):
self.cmAcc = "/acceptpm "+self.pmPerson
try:
self.s.send(self.cmAcc.encode())
except timeout:
self.ShowMessageErreur("Erreur : Timeout. Le serveur ne repond pas")
self.ui.txtOutput.setText(self.message_buffer2)
sb = self.ui.txtOutput.verticalScrollBar()
sb.setValue(sb.maximum())
2015-04-04 23:56:10 +02:00
2015-04-05 13:44:36 +02:00
def selectFile(self):
2015-04-06 17:11:47 +02:00
self.ui.lineEdit.setText('/pmfile '+self.pmPerson+ ' '.join(QFileDialog.getOpenFileName()))
2015-04-05 13:44:36 +02:00
2015-04-07 19:27:33 +02:00
def htmlToText( self, html ):
html = html.replace('<', '&#60;')
html = html.replace('>', '&#62;')
html = html.replace(':-)', '<img src="img/happy.png" alt="Smiley face">')
html = html.replace(':-(', '<img src="img/sad.png" alt="sad face">')
html = html.replace(':-p', '<img src="img/langue.png" alt="langue face">')
html = html.replace(';-)', '<img src="img/oeil.png" alt="oeil face">')
html = html.replace(':-D', '<img src="img/veryHappy.png" alt="very happy face">')
html = html.replace(':-o', '<img src="img/etonne.png" alt="etonne face">')
html = html.replace(':\'(', '<img src="img/cry.png" alt="cry face">')
html = html.replace('(y)', '<img src="img/like.png" alt="like face">')
html = html.replace('8|', '<img src="img/lunette.png" alt="lunette face">')
html = html.replace('3:)', '<img src="img/hell.png" alt="hell face">')
html = html.replace(':pedobear', '<img src="img/pedo.gif" alt="hell face">')
html = html.replace(':homer', '<img src="img/homer.gif" alt="homer face">')
2015-04-05 13:44:36 +02:00
2015-04-07 19:27:33 +02:00
return html
def ShowMessageErreur(self, txt):
self.message_buffer2 += '<br> <span style="color : red; font-weight: bold;"> '+ self.htmlToText(txt) +' </span>'
2015-04-05 13:44:36 +02:00
def send(self):
2015-04-07 19:27:33 +02:00
self.cmdP = self.ui.lineEdit.text()
if self.cmdP != "":
2015-04-05 13:44:36 +02:00
self.ui.lineEdit.setText('')
self.s.settimeout(5.0)
2015-04-07 19:27:33 +02:00
self.cmd = "/pm " +self.pmPerson+ " " + self.cmdP
2015-04-05 13:44:36 +02:00
try:
self.s.send(self.cmd.encode())
2015-04-04 23:56:10 +02:00
2015-04-05 13:44:36 +02:00
except timeout:
self.ShowMessageErreur("Erreur : Timeout. Le serveur ne repond pas")
2015-04-07 19:27:33 +02:00
self.ui.txtOutput.setText(self.message_buffer2)
2015-04-05 13:44:36 +02:00
sb = self.ui.txtOutput.verticalScrollBar()
sb.setValue(sb.maximum())
2015-04-06 17:11:47 +02:00
def UpdateChatP(self) :
if self.queueMsg2 :
m = self.queueMsg2.pop(0)
if m :
self.thread.start()
self.ShowMessageAsTextPm(m)
2015-04-07 19:27:33 +02:00
#self.ui.txtOutput.setText(self.message_buffer2)
#sb = self.ui.txtOutput.verticalScrollBar()
#sb.setValue(sb.maximum())
2015-04-04 23:56:10 +02:00
2015-04-07 19:27:33 +02:00
def getTimeStamp(self):
return ('[%s] ' % str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%H:%M')))
def ShowMessageAsTextPm(self, txt) :
self.message_buffer2 += '<br><span style="color : grey">'+txt+'</span>'
if txt.split(" ")[0] == "SUCC_PM_SENDED":
self.message_buffer2 += '<br><span style="color : grey"> ' + self.getTimeStamp() + '</span> <span style="color : red"> &#60; '+self.pmPerso +' &#62; </span> ' + self.htmlToText(self.cmdP) + ''
if txt.split(" ")[0] == "SUCC_PRIVATE_DISCUSSION_ACCEPTED":
2015-04-06 20:09:58 +02:00
self.message_buffer2 += '<br> <span style="color : green"> Chalange Accepted ! </span>'
2015-04-07 19:27:33 +02:00
if txt.split(" ")[0] == "NEW_PM" :
self.message_buffer2 += '<br><span style="color : grey"> ' + self.getTimeStamp() + '</span> <span style="color : red"> &#60; '+ self.pmPerso +' &#62; </span> ' + self.htmlToText(' '.join(txt.split(" ")[2:])) + ''
2015-04-06 17:11:47 +02:00
2015-04-07 19:27:33 +02:00
self.ui.txtOutput.setText(self.message_buffer2)
sb = self.ui.txtOutput.verticalScrollBar()
sb.setValue(sb.maximum())
2015-03-31 11:52:01 +02:00
class start(QtGui.QDialog):
2015-03-30 14:21:11 +02:00
def __init__(self):
super(start, self).__init__()
self.queueMsg= []
self.thread = MyThread()
self.thread.finished.connect(self.UpdateChat)
2015-04-03 11:18:59 +02:00
2015-03-30 14:21:11 +02:00
self.createWidgets()
def setNewMsg (self,msg) :
self.queueMsg.append(msg)
2015-03-30 21:39:02 +02:00
def getTimeStamp(self):
return ('[%s] ' % str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%H:%M')))
2015-04-02 11:49:43 +02:00
def htmlToText( self, html ):
2015-03-30 21:39:02 +02:00
2015-04-02 11:49:43 +02:00
html = html.replace('<', '&#60;')
html = html.replace('>', '&#62;')
html = html.replace(':-)', '<img src="img/happy.png" alt="Smiley face">')
html = html.replace(':-(', '<img src="img/sad.png" alt="sad face">')
html = html.replace(':-p', '<img src="img/langue.png" alt="langue face">')
html = html.replace(';-)', '<img src="img/oeil.png" alt="oeil face">')
html = html.replace(':-D', '<img src="img/veryHappy.png" alt="very happy face">')
html = html.replace(':-o', '<img src="img/etonne.png" alt="etonne face">')
html = html.replace(':\'(', '<img src="img/cry.png" alt="cry face">')
html = html.replace('(y)', '<img src="img/like.png" alt="like face">')
html = html.replace('8|', '<img src="img/lunette.png" alt="lunette face">')
html = html.replace('3:)', '<img src="img/hell.png" alt="hell face">')
2015-04-06 20:09:58 +02:00
html = html.replace(':pedobear', '<img src="img/pedo.gif" alt="hell face">')
html = html.replace(':homer', '<img src="img/homer.gif" alt="homer face">')
2015-03-30 21:39:02 +02:00
2015-04-02 11:49:43 +02:00
return html
2015-03-31 11:52:01 +02:00
def ShowMessageErreur(self, txt):
self.message_buffer += '<br> <span style="color : red; font-weight: bold;"> '+ self.htmlToText(txt) +' </span>'
2015-04-03 14:51:22 +02:00
def ShowMessageOK(self, txt):
self.message_buffer += '<br> <span style="color : green; font-weight: bold;"> '+ self.htmlToText(txt) +' </span>'
2015-04-04 20:28:02 +02:00
def ShowMessageInfo (self, txt) :
self.message_buffer += '<br> <span style="color : #FF00FF; font-weight: bold;"> '+ self.htmlToText(txt) +' </span>'
2015-03-31 18:49:29 +02:00
2015-04-02 11:49:43 +02:00
def ShowMessageAsText(self, txt):
2015-04-03 20:07:29 +02:00
if re.match("^ERR_", txt):
2015-04-04 23:56:10 +02:00
self.ShowMessageErreur("Erreur ! : " + txt)
2015-04-03 11:18:59 +02:00
2015-04-03 23:28:55 +02:00
self.message_buffer += '<br> <span style="color : #E6E6E6"> '+ txt +' </span>'
2015-04-03 12:12:01 +02:00
2015-04-04 20:28:02 +02:00
if txt.split(" ")[0] == "IS_NOW_DISABLE":
self.ShowMessageInfo(txt.split(" ")[1]+" is Away From Keyboard")
self.ui.listNames.clear()
self.ui.listNames_2.clear()
self.s.send("/userlist".encode())
self.s.send("/userlistaway".encode())
if txt.split(" ")[0] == "IS_NOW_ENABLE":
self.ShowMessageInfo(txt.split(" ")[1]+" is Back !!")
self.ui.listNames.clear()
self.ui.listNames_2.clear()
self.s.send("/userlist".encode())
self.s.send("/userlistaway".encode())
2015-04-03 20:07:29 +02:00
2015-04-06 20:09:58 +02:00
if txt.split(" ")[0] == "SUCC_PRIVATE_DISCUSSION_ACCEPTED":
self.message_buffer += '<br> <span style="color : green"> PRIVATE DISCUSSION ? challenge accepted ! '
2015-04-07 19:27:33 +02:00
2015-04-04 23:56:10 +02:00
if txt.split(" ")[0] == "SUCC_INVITED" :
self.ShowMessageOK("invitation requested")
2015-04-07 19:27:33 +02:00
self.private2 = privateMessage(self,self.s,self.demande,self.pseudo)
2015-04-04 23:56:10 +02:00
if txt.split(" ")[0] == "ASKING_FOR_PM" :
self.ShowMessageOK("private discution from "+ txt.split(" ")[1] )
2015-04-07 19:27:33 +02:00
self.private2 = privateMessage(self,self.s,txt.split(" ")[1],self.pseudo)
if txt.split(" ")[0] == "SUCC_PM_SENDED" :
self.private2.ShowMessageAsTextPm(txt.split(" ")[0])
if txt.split(" ")[0] == "NEW_PM" :
self.private2.ShowMessageAsTextPm(txt)
#if txt.split(" ")[0] == "SUCC_PM_SENDED":
# self.private
2015-04-03 14:51:22 +02:00
if txt.split(" ")[0] == "SUCCESSFUL_LOGOUT" :
self.ShowMessageOK("Sucessful logout !")
2015-04-03 20:07:29 +02:00
if txt.split(" ")[0] == "SUCC_DISABLED" :
2015-04-04 00:15:52 +02:00
self.ShowMessageOK("You are AFK !")
self.ui.listNames.clear()
2015-04-04 20:28:02 +02:00
self.ui.listNames_2.clear()
self.s.send("/userlist".encode())
2015-04-04 00:15:52 +02:00
self.s.send("/userlistaway".encode())
2015-04-04 20:28:02 +02:00
2015-04-03 20:07:29 +02:00
if txt.split(" ")[0] == "SUCC_ENABLED" :
2015-04-04 00:15:52 +02:00
self.ShowMessageOK("You are back !")
self.ui.listNames.clear()
self.ui.listNames_2.clear()
self.s.send("/userlist".encode())
self.s.send("/userlistaway".encode())
2015-04-03 20:07:29 +02:00
2015-04-03 12:19:17 +02:00
2015-04-03 14:51:22 +02:00
if txt.split(" ")[0] == "SUCC_VALID_NICKNAME" :
self.ShowMessageOK("Sucessful nickname change !")
2015-04-06 17:11:47 +02:00
if txt.split(" ")[0] == "ERR_INVALID_NICKNAME" :
self.pseudo = "INVALID_NICKNAME"
2015-04-07 19:27:33 +02:00
#HAS_LEFT anonymous52
2015-04-03 12:12:01 +02:00
if txt.split(" ")[0] == "NAME_CHANGED" :
2015-04-03 23:28:55 +02:00
self.ShowMessageNameChange(txt.split(" ")[1], txt.split(" ")[2])
self.ui.listNames.clear()
self.s.send("/userlist".encode())
2015-04-03 11:18:59 +02:00
if txt.split(" ")[0] == "HAS_JOIN" :
2015-04-03 12:12:01 +02:00
self.ShowMessageHasJoin(txt.split(" ")[1])
2015-04-03 23:28:55 +02:00
self.ui.listNames.addItem(txt.split(" ")[1])
if txt.split(" ")[0] == "HAS_LEFT" :
self.ShowMessageHasLeft(txt.split(" ")[1])
self.ui.listNames.clear()
self.s.send("/userlist".encode())
2015-04-04 00:15:52 +02:00
2015-04-03 12:19:17 +02:00
2015-04-03 14:51:22 +02:00
if txt.split(" ")[0] == "SUCC_CHANNEL_JOINED" or txt.split(" ")[0] == "SUCC_CHANNEL_JOINEDUSERLIST" :
2015-04-03 12:19:17 +02:00
self.ShowMessageHasJoin(self.pseudo)
2015-04-03 23:28:55 +02:00
if re.compile('USERLIST').search(txt.split(" ")[0] ) :
n = len(txt.split(" ")[1:]) +1
for i in range(1,n) :
2015-04-04 15:47:24 +02:00
self.ui.listNames.addItem(str(txt.split(" ")[i]).replace("USERAWAY",""))
2015-04-03 23:28:55 +02:00
print(str(txt.split(" ")[1:]))
2015-04-04 00:15:52 +02:00
if re.compile('USERAWAY').search(txt.split(" ")[0] ) :
n = len(txt.split(" ")[1:]) +1
for i in range(1,n) :
self.ui.listNames_2.addItem(str(txt.split(" ")[i]))
print(str(txt.split(" ")[1:]))
2015-04-03 14:51:22 +02:00
2015-04-03 12:19:17 +02:00
2015-04-03 11:18:59 +02:00
if txt.split(" ")[0] == "NEW_MSG" :
self.message_buffer += '<br><span style="color : grey"> ' + self.getTimeStamp() + '</span> <span style="color : red"> &#60; '+txt.split(" ")[1] +' &#62; </span> ' + self.htmlToText(' '.join(txt.split(" ")[2:])) + ''
if txt == "SUCC_MESSAGE_SENDED" :
2015-04-03 12:12:01 +02:00
self.message_buffer += '<br><span style="color : grey"> ' + self.getTimeStamp() + '</span> <span style="color : red"> &#60; '+ self.pseudo +' &#62; </span> ' + self.htmlToText(self.cmd) + ''
2015-04-03 11:18:59 +02:00
2015-04-03 12:12:01 +02:00
def ShowMessageHasJoin (self, txt) :
2015-04-03 11:18:59 +02:00
self.message_buffer += '<br> <span style="color : #FF00FF; font-weight: bold;"> '+ self.htmlToText(txt) +' has joined DNC </span>'
2015-04-03 12:12:01 +02:00
2015-04-03 23:28:55 +02:00
def ShowMessageHasLeft (self, txt) :
self.message_buffer += '<br> <span style="color : #FF00FF; font-weight: bold;"> '+ self.htmlToText(txt) +' has left DNC </span>'
2015-04-03 12:12:01 +02:00
def ShowMessageNameChange (self, txt, txt2) :
self.message_buffer += '<br> <span style="color : #FF00FF; font-weight: bold;"> '+ self.htmlToText(txt) +' is now : '+self.htmlToText(txt2)+' </span>'
2015-04-03 11:18:59 +02:00
def UpdateChat(self) :
if self.queueMsg :
m = self.queueMsg.pop(0)
if m :
self.thread.start()
self.ShowMessageAsText(m)
self.ui.txtOutput.setText(self.message_buffer)
sb = self.ui.txtOutput.verticalScrollBar()
sb.setValue(sb.maximum())
2015-03-30 21:39:02 +02:00
2015-04-03 12:12:01 +02:00
2015-03-30 14:21:11 +02:00
def connectActions(self):
2015-03-31 11:52:01 +02:00
self.ui.pushButton_2.clicked.connect(self.connecter)
self.ui.pushButton_3.clicked.connect(self.deco)
2015-03-30 14:21:11 +02:00
self.ui.pushButton.clicked.connect(self.client)
2015-04-03 14:51:22 +02:00
self.ui.pushButton_6.clicked.connect(self.changeN)
2015-04-03 20:07:29 +02:00
self.ui.pushButton_5.clicked.connect(self.away)
2015-04-06 17:11:47 +02:00
#self.connect(self.ui.listNames,
# QtCore.SIGNAL("itemDoubleClicked(QListWidgetItem *)"),
# self.someMethod)
self.ui.listNames.itemActivated.connect(self.someMethod)
def someMethod(self,item):
2015-04-06 20:09:58 +02:00
nom = item.text().replace("SUCC_INVITED","")
2015-04-06 17:11:47 +02:00
cmdPM = "/askpm "+nom
try:
self.s.send(cmdPM.encode())
self.demande = nom
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())
2015-04-03 20:07:29 +02:00
def away(self):
if self.bouton == "disable" :
cmdAway = "/disable "
try:
self.s.send(cmdAway.encode())
self.ui.pushButton_5.setText("Back")
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())
self.bouton = "enable"
elif self.bouton == "enable" :
self.bouton = "disable"
cmdAway = "/enable "
try:
self.s.send(cmdAway.encode())
self.ui.pushButton_5.setText("Away From Keyboard")
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())
2015-04-03 14:51:22 +02:00
2015-04-03 20:07:29 +02:00
2015-04-03 14:51:22 +02:00
def changeN(self):
changePseudo = self.ui.lineEdit_2.text()
cmdChange = "/name "+changePseudo
try:
self.s.send(cmdChange.encode())
self.pseudo = changePseudo
2015-04-03 23:28:55 +02:00
self.ui.listNames.clear()
self.s.send("/userlist".encode())
2015-04-03 14:51:22 +02:00
2015-03-30 14:21:11 +02:00
2015-04-03 14:51:22 +02:00
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())
2015-03-31 11:52:01 +02:00
def connecter(self):
2015-04-03 14:51:22 +02:00
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)
2015-03-31 11:52:01 +02:00
self.s = socket(AF_INET, SOCK_STREAM)
self.s.connect(Addr)
self.thread.setConfig(self.s,self)
2015-03-31 17:05:45 +02:00
self.ui.lineEdit.setDisabled(False)
self.ui.pushButton.setDisabled(False)
self.ui.pushButton_2.setDisabled(True)
self.ui.pushButton_3.setDisabled(False)
2015-04-03 20:07:29 +02:00
self.ui.lineEdit_4.setDisabled(True)
self.ui.lineEdit_3.setDisabled(True)
self.thread.start()
2015-04-03 14:51:22 +02:00
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())
2015-04-02 11:49:43 +02:00
def deco(self):
2015-04-03 14:51:22 +02:00
quitter = "/quit"
self.s.send(quitter.encode())
#self.s.close()
2015-04-02 11:49:43 +02:00
self.ui.lineEdit.setDisabled(True)
self.ui.pushButton.setDisabled(True)
self.ui.pushButton_2.setDisabled(False)
2015-04-03 14:51:22 +02:00
self.ui.pushButton_3.setDisabled(True)
self.ui.pushButton_6.setDisabled(True)
2015-04-02 11:49:43 +02:00
2015-04-03 20:07:29 +02:00
self.ui.lineEdit_4.setDisabled(False)
self.ui.lineEdit_3.setDisabled(False)
2015-04-02 11:49:43 +02:00
def ecoute(self):
while 1 :
data = self.s.recv(4096)
if not data :
break
messgServeur = (data.decode())
2015-04-03 12:12:01 +02:00
if messgServeur == "ERR_INVALID_NICKNAME" :
self.pseudo = "INVALID_NICKNAME"
2015-04-02 11:49:43 +02:00
self.UpdateChat(messgServeur)
def createWidgets(self):
self.ui = Ui_Dialog()
self.ui.setupUi(self)
2015-04-03 14:51:22 +02:00
ano = "anonymous" + ''.join(str(random.randint(1,9)) for _ in range(2))
2015-04-08 15:23:48 +02:00
config = configparser.ConfigParser()
config.read("dncClient.conf")
port = config.get("NETWORK", "port")
ip = config.get("NETWORK", "ip")
name = config.get("PSEUDO", "name")
if name is not None :
self.ui.lineEdit_2.setText(name)
else :
self.ui.lineEdit_2.setText(ano)
if ip is not None :
self.ui.lineEdit_4.setText(ip)
if port is not None :
self.ui.lineEdit_3.setText(port)
2015-04-03 14:51:22 +02:00
2015-04-02 11:49:43 +02:00
self.ui.lineEdit.setDisabled(True)
self.ui.pushButton.setDisabled(True)
self.ui.pushButton_3.setDisabled(True)
2015-04-03 14:51:22 +02:00
self.ui.pushButton_6.setDisabled(True)
2015-04-02 11:49:43 +02:00
self.message_buffer = ""
2015-04-03 20:07:29 +02:00
self.bouton = "disable"
2015-04-03 14:51:22 +02:00
2015-04-02 11:49:43 +02:00
self.connectActions()
2015-03-30 14:21:11 +02:00
2015-03-31 18:49:29 +02:00
2015-03-31 11:52:01 +02:00
def client(self):
2015-03-30 21:39:02 +02:00
2015-04-03 11:18:59 +02:00
self.cmd = self.ui.lineEdit.text()
if self.cmd != "":
2015-03-31 18:49:29 +02:00
self.ui.lineEdit.setText('')
self.s.settimeout(5.0)
2015-03-31 18:49:29 +02:00
try:
2015-04-03 11:18:59 +02:00
self.s.send(self.cmd.encode())
2015-04-03 12:12:01 +02:00
if self.cmd.split(" ")[0] == "/newname":
self.pseudo = self.cmd.split(" ")[1]
if self.cmd.split(" ")[0] == "/name":
self.pseudo = self.cmd.split(" ")[1]
2015-04-06 17:11:47 +02:00
if self.cmd.split(" ")[0]=="/askpm":
self.demande = self.cmd.split(" ")[1]
2015-04-02 11:49:43 +02:00
2015-03-31 18:49:29 +02:00
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())
2015-03-30 14:21:11 +02:00
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
myapp = start()
myapp.show()
myapp.focusWidget()
sys.exit(app.exec_())
for t in threading.enumerate():
if t != threading.main_thread(): t.join()