c'est une turie ça marche git add .git add .git add .
This commit is contained in:
parent
1fdd69c4cb
commit
1ffc04b5ff
@ -1,6 +1,8 @@
|
|||||||
from mainWindow import Ui_Dialog
|
from mainWindow import Ui_Dialog
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
import time, threading, datetime
|
from PySide.QtCore import *
|
||||||
|
from PySide.QtGui import *
|
||||||
|
import time, threading, datetime, time
|
||||||
from socket import *
|
from socket import *
|
||||||
|
|
||||||
Host = "127.0.0.1"
|
Host = "127.0.0.1"
|
||||||
@ -8,11 +10,56 @@ Port = 2222
|
|||||||
Addr = (Host, Port)
|
Addr = (Host, Port)
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class start(QtGui.QDialog):
|
class start(QtGui.QDialog):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(start, self).__init__()
|
super(start, self).__init__()
|
||||||
|
self.queueMsg= []
|
||||||
|
self.thread = MyThread()
|
||||||
|
self.thread.finished.connect(self.UpdateChat)
|
||||||
|
|
||||||
self.createWidgets()
|
self.createWidgets()
|
||||||
|
|
||||||
|
def setNewMsg (self,msg) :
|
||||||
|
self.queueMsg.append(msg)
|
||||||
|
|
||||||
def getTimeStamp(self):
|
def getTimeStamp(self):
|
||||||
return ('[%s] ' % str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%H:%M')))
|
return ('[%s] ' % str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%H:%M')))
|
||||||
|
|
||||||
@ -25,15 +72,22 @@ class start(QtGui.QDialog):
|
|||||||
|
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
def ShowMessageErreur(self, txt):
|
||||||
|
self.message_buffer += '<br> <span style="color : red; font-weight: bold;"> '+ self.htmlToText(txt) +' </span>'
|
||||||
|
|
||||||
def ShowMessageAsText(self, txt):
|
def ShowMessageAsText(self, txt):
|
||||||
self.message_buffer += '<br><span style="color : grey"> ' + self.getTimeStamp() + '</span> <span style="color : red"> <BOB> </span> ' + self.htmlToText(txt) + ''
|
self.message_buffer += '<br><span style="color : grey"> ' + self.getTimeStamp() + '</span> <span style="color : red"> <BOB> </span> ' + self.htmlToText(txt) + ''
|
||||||
|
|
||||||
def UpdateChat(self, messgServeur) :
|
def UpdateChat(self) :
|
||||||
self.ShowMessageAsText(messgServeur)
|
if self.queueMsg :
|
||||||
self.ui.txtOutput.setText(self.message_buffer)
|
m = self.queueMsg.pop(0)
|
||||||
sb = self.ui.txtOutput.verticalScrollBar()
|
if m :
|
||||||
sb.setValue(sb.maximum())
|
self.thread.start()
|
||||||
|
self.ShowMessageAsText(m)
|
||||||
|
self.ui.txtOutput.setText(self.message_buffer)
|
||||||
|
sb = self.ui.txtOutput.verticalScrollBar()
|
||||||
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
|
|
||||||
def connectActions(self):
|
def connectActions(self):
|
||||||
self.ui.pushButton_2.clicked.connect(self.connecter)
|
self.ui.pushButton_2.clicked.connect(self.connecter)
|
||||||
@ -43,14 +97,15 @@ class start(QtGui.QDialog):
|
|||||||
def connecter(self):
|
def connecter(self):
|
||||||
self.s = socket(AF_INET, SOCK_STREAM)
|
self.s = socket(AF_INET, SOCK_STREAM)
|
||||||
self.s.connect(Addr)
|
self.s.connect(Addr)
|
||||||
|
self.thread.setConfig(self.s,self)
|
||||||
self.ui.lineEdit.setDisabled(False)
|
self.ui.lineEdit.setDisabled(False)
|
||||||
self.ui.pushButton.setDisabled(False)
|
self.ui.pushButton.setDisabled(False)
|
||||||
self.ui.pushButton_2.setDisabled(True)
|
self.ui.pushButton_2.setDisabled(True)
|
||||||
self.ui.pushButton_3.setDisabled(False)
|
self.ui.pushButton_3.setDisabled(False)
|
||||||
|
self.thread.start()
|
||||||
|
|
||||||
|
|
||||||
#threading.Thread(target=self.ecoute).start()
|
#threading.Thread(target=self.ecoute).start()
|
||||||
#for t in threading.enumerate():
|
|
||||||
# if t != threading.main_thread(): t.join()
|
|
||||||
|
|
||||||
def deco(self):
|
def deco(self):
|
||||||
self.s.close()
|
self.s.close()
|
||||||
@ -101,16 +156,21 @@ class start(QtGui.QDialog):
|
|||||||
cmd = self.ui.lineEdit.text()
|
cmd = self.ui.lineEdit.text()
|
||||||
if cmd != "":
|
if cmd != "":
|
||||||
self.ui.lineEdit.setText('')
|
self.ui.lineEdit.setText('')
|
||||||
|
self.s.settimeout(5.0)
|
||||||
try:
|
try:
|
||||||
self.s.send(cmd.encode())
|
self.s.send(cmd.encode())
|
||||||
data = self.s.recv(4096)
|
data = self.s.recv(4096)
|
||||||
messgServeur = (data.decode())
|
messgServeur = (data.decode())
|
||||||
self.UpdateChat(messgServeur)
|
self.ShowMessageAsText(messgServeur)
|
||||||
|
self.ui.txtOutput.setText(self.message_buffer)
|
||||||
|
sb = self.ui.txtOutput.verticalScrollBar()
|
||||||
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
|
|
||||||
except timeout:
|
except timeout:
|
||||||
print("Erreur : Timeout. Le serveur ne repond pas.")
|
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())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -120,3 +180,5 @@ if __name__ == "__main__":
|
|||||||
myapp.show()
|
myapp.show()
|
||||||
myapp.focusWidget()
|
myapp.focusWidget()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
for t in threading.enumerate():
|
||||||
|
if t != threading.main_thread(): t.join()
|
||||||
|
Reference in New Issue
Block a user