Commit a8c6dfde authored by Agrigor's avatar Agrigor

Some nasty hacks which aren't done yet

parent 17a635d6
......@@ -17,7 +17,6 @@ from PyQt4.uic import *
# ~~~~~~~~~~~~~~~~~~~~~~~~ GLOBAL CONSTANTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PORT = 50000
IP = "127.0.0.1"
......@@ -48,10 +47,11 @@ class Comunication:
def cleanup(self):
self.__socket.close()
class Player:
def __init__(self, Name):
def __init__(self, name):
self.Points = 0
self.Name = Name
self.Name = name
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAIN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -60,47 +60,64 @@ class Player:
class GUI:
def __init__(self):
self.app = QApplication(sys.argv)
self.UI_Start = loadUi("GUIs/start.ui")
self.socketCreated = False
self.players = []
self.UI_Start.connect(self.UI_Start.I_Connect, SIGNAL("clicked()"), self.connect)
self.UI_Start.connect(self.UI_Start.I_Start, SIGNAL("clicked()"), self.start)
self.UI_Start.connect(self.UI_Start.I_NumberOfPlayers, SIGNAL("valueChanged(int)"), self.show_names_input)
self.UI_Start.show()
self.app = QApplication(sys.argv)
start = StartGUI(self.socketCreated, self.players)
self.app.exec_()
self.app.aboutToQuit(self.cleanup())
def cleanup(self):
if self.socketCreated:
self.UDP.cleanup()
print("Bye Bye")
sys.exit(0)
class StartGUI:
def __init__(self, socketCreated, players):
self.__UI_Start = loadUi("GUIs/start.ui")
self.socketCreated = socketCreated
self.players = players
self.__UI_Start.connect(self.__UI_Start.I_Connect, SIGNAL("clicked()"), self.connect)
self.__UI_Start.connect(self.__UI_Start.I_Start, SIGNAL("clicked()"), self.start)
self.__UI_Start.connect(self.__UI_Start.I_NumberOfPlayers, SIGNAL("valueChanged(int)"), self.show_names_input)
self.__UI_Start.connect(self.__UI_Start.I_NamePlayer1, SIGNAL("textChanged(QString)"), self.name_player_1_changed)
self.__UI_Start.show()
def name_player_1_changed(self, name):
if int(self.__UI_Start.O_NumberOfPlayers.text()) == 1 and self.socketCreated and len(str(self.__UI_Start.I_NamePlayer1.text())) > 1:
self.__UI_Start.I_Start.setDisabled(False)
def show_names_input(self, number):
number -= 1
playerInputs = [self.UI_Start.I_NamePlayer1,
self.UI_Start.I_NamePlayer2,
self.UI_Start.I_NamePlayer3,
self.UI_Start.I_NamePlayer4]
for i in range (len(playerInputs)):
playerInputs = [self.__UI_Start.I_NamePlayer1,
self.__UI_Start.I_NamePlayer2,
self.__UI_Start.I_NamePlayer3,
self.__UI_Start.I_NamePlayer4]
for i in range(len(playerInputs)):
if i <= number:
playerInputs[i].setDisabled(False)
else:
playerInputs[i].setDisabled(True)
def start(self):
namesOfPlayers = [str(self.UI_Start.I_NamePlayer1.text()),
str(self.UI_Start.I_NamePlayer2.text()),
str(self.UI_Start.I_NamePlayer3.text()),
str(self.UI_Start.I_NamePlayer4.text())]
for i in range (0, int(self.UI_Start.O_NumberOfPlayers.text())):
namesOfPlayers = [str(self.__UI_Start.I_NamePlayer1.text()),
str(self.__UI_Start.I_NamePlayer2.text()),
str(self.__UI_Start.I_NamePlayer3.text()),
str(self.__UI_Start.I_NamePlayer4.text())]
for i in range(0, int(self.__UI_Start.O_NumberOfPlayers.text())):
self.players.append(Player(namesOfPlayers[i]))
def connect(self):
self.ip = str(self.UI_Start.I_IPAdress.text())
self.UDP = Comunication(self.ip, PORT)
self.UDP = Comunication(str(self.__UI_Start.I_IPAdress.text()), PORT)
if self.UDP.check_ip():
self.UDP.create_client_socket()
self.socketCreated = True
self.UI_Start.I_Start.setDisabled(False)
else:
print("First argument was no valid IP-address")
self.socketCreated = False
......@@ -109,8 +126,6 @@ class GUI:
def cleanup(self):
if self.socketCreated:
self.UDP.cleanup()
print("Bye Bye")
sys.exit(0)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -121,6 +136,7 @@ class GUI:
# Start Client
client = GUI()
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ END ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment