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

84 lines
2.2 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
2015-03-30 21:39:02 +02:00
import datetime
import time
2015-03-31 11:52:01 +02:00
from socket import *
Host = "127.0.0.1"
Port = 2222
Addr = (Host, Port)
2015-03-30 14:21:11 +02:00
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.createWidgets()
2015-03-30 21:39:02 +02:00
def getTimeStamp(self):
return ('[%s] ' % str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%H:%M')))
2015-03-31 11:52:01 +02:00
def ShowMessageAsText(self, txt):
2015-03-30 21:39:02 +02:00
self.message_buffer += '\n' + self.getTimeStamp() + txt
2015-03-30 14:21:11 +02:00
def createWidgets(self):
self.ui = Ui_Dialog()
self.ui.setupUi(self)
2015-03-30 21:39:02 +02:00
2015-03-31 17:05:45 +02:00
self.ui.lineEdit.setDisabled(True)
self.ui.pushButton.setDisabled(True)
self.ui.pushButton_3.setDisabled(True)
2015-03-30 21:39:02 +02:00
self.message_buffer = ""
self.ShowMessageAsText("coucou ! comment ça va ?")
2015-03-31 11:52:01 +02:00
self.connectActions()
2015-03-30 21:39:02 +02:00
2015-03-31 11:52:01 +02:00
# self.UpdateMainDisplay()
2015-03-30 21:39:02 +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-03-31 11:52:01 +02:00
def connecter(self):
self.s = socket(AF_INET, SOCK_STREAM)
self.s.connect(Addr)
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-03-30 14:21:11 +02:00
2015-03-31 11:52:01 +02:00
def deco(self):
self.s.close()
2015-03-31 17:05:45 +02:00
self.ui.lineEdit.setDisabled(True)
self.ui.pushButton.setDisabled(True)
self.ui.pushButton_2.setDisabled(False)
2015-03-30 21:39:02 +02:00
2015-03-31 11:52:01 +02:00
def client(self):
2015-03-30 21:39:02 +02:00
2015-03-31 11:52:01 +02:00
cmd = self.ui.lineEdit.text()
2015-03-31 12:17:44 +02:00
self.ui.lineEdit.setText('')
2015-03-31 11:52:01 +02:00
if cmd.lower() == "quit":
exit(0)
try:
self.s.send(cmd.encode())
2015-03-31 13:25:34 +02:00
data = self.s.recv(4096)
2015-03-31 17:05:45 +02:00
messgServeur = (data.decode())
self.ShowMessageAsText(messgServeur)
self.ui.txtOutput.setText(self.message_buffer)
2015-03-31 11:52:01 +02:00
except timeout:
print("Erreur : Timeout. Le serveur ne repond pas.")
2015-03-30 21:39:02 +02:00
2015-03-30 14:21:11 +02:00
if __name__ == "__main__":
import sys
2015-03-31 11:52:01 +02:00
2015-03-30 14:21:11 +02:00
app = QtGui.QApplication(sys.argv)
myapp = start()
myapp.show()
myapp.focusWidget()
sys.exit(app.exec_())