Commit 4294f06f authored by Agrigor's avatar Agrigor

question dialog now with countdown and socket connection

parent 00ada187
......@@ -24,7 +24,7 @@ IP = "127.0.0.1"
PLAYERS_MAX = 4
CATEGORIES_MAX = 5
QUESTION_LENGTH_MAX = 1024 * 1024
TIMEOUT = 60
TIMEOUT = 30
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~ CLASS DEFINITION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -61,6 +61,20 @@ class Player:
self.solved = [[0 for i in range(5)] for j in range(5)]
class WaitForButton(QThread):
def __init__(self, socket):
QThread.__init__(self)
self.socket = socket
def run(self):
daten, addr = self.socket.receive(1024)
try:
buttonNumber = int(daten.decode()[7])
except:
buttonNumber = 0
self.emit(SIGNAL("finished(int)"), buttonNumber)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAIN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -338,23 +352,41 @@ class ChangePointsGUI(QDialog):
class QuestionGUI(QDialog):
def __init__(self, text):
def __init__(self, text, socket, UI_Main):
QDialog.__init__(self)
self.UI_Question = loadUi("GUIs/question.ui", self)
self.UI_Question.QuestionText.setHtml(text)
self.UI_Question.TimeLCD.display(TIMEOUT)
self.socket = socket
self.UI_Main = UI_Main
self.buttonNumber = 0
self.waitforbutton = WaitForButton(self.socket)
self.connect(self.waitforbutton, SIGNAL("finished(int)"), self.done)
self.waitforbutton.start()
self.time = TIMEOUT
self.timer = QTimer(self)
self.timer.timeout.connect(self.timeHandler)
self.timer.start(1000)
self.UI_Question.show()
def done(self, buttonNumber):
self.waitforbutton.exit()
self.timer.stop()
self.UI_Main.showMsg("Player " + str(buttonNumber) + " pressed the button")
def timeHandler(self):
if self.time > 0:
self.time -= 1
else:
self.time = 0
self.UI_Question.TimeLCD.display(self.time)
else:
self.UI_Main.showMsg("No one pressed a button")
def closeEvent(self, event):
pass
class MainGUI(QMainWindow):
......@@ -445,7 +477,7 @@ class MainGUI(QMainWindow):
question = int(sender[3]) - 1
with zipfile.ZipFile(self.questionPaths[cat]) as zip:
text = (zip.open(zip.namelist()[question]).read(QUESTION_LENGTH_MAX)).decode()
self.UI_Question = QuestionGUI(text)
self.UI_Question = QuestionGUI(text, self.socket, self.UI_Main)
def loadQuestionSet(self):
self.questionPaths = QFileDialog.getOpenFileNames(self, "Load Question Set", '', "ZIP-Files (*.zip)")
......
......@@ -61,7 +61,7 @@ class Server:
try:
while True:
self.send_simulation()
time.sleep(1)
time.sleep(random.randint(5, 10))
finally:
self.cleanup()
......
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