Commit 1c9df158 authored by Agrigor's avatar Agrigor

Now there is a question dialog, that shows a plain text or html dynamically...

Now there is a question dialog, that shows a plain text or html dynamically *jeah* Also a lot of gui usability fuckups are now impossible
parent 86ac2788
......@@ -836,8 +836,33 @@
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<widget class="QLabel" name="Name_P3">
<item row="1" column="0">
<widget class="QLCDNumber" name="Points_P1">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::WinPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="numDigits">
<number>4</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="Name_P2">
<property name="minimumSize">
<size>
<width>0</width>
......@@ -858,7 +883,7 @@
</font>
</property>
<property name="text">
<string>Player 3</string>
<string>Player 2</string>
</property>
<property name="scaledContents">
<bool>false</bool>
......@@ -868,12 +893,12 @@
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLCDNumber" name="Points_P4">
<item row="0" column="2">
<widget class="QLabel" name="Name_P3">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
<height>20</height>
</size>
</property>
<property name="maximumSize">
......@@ -882,19 +907,26 @@
<height>100</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::WinPanel</enum>
<property name="font">
<font>
<pointsize>15</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<property name="text">
<string>Player 3</string>
</property>
<property name="numDigits">
<number>4</number>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLCDNumber" name="Points_P2">
<item row="1" column="3">
<widget class="QLCDNumber" name="Points_P4">
<property name="minimumSize">
<size>
<width>0</width>
......@@ -918,8 +950,8 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLCDNumber" name="Points_P1">
<item row="1" column="1">
<widget class="QLCDNumber" name="Points_P2">
<property name="minimumSize">
<size>
<width>0</width>
......@@ -943,38 +975,6 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="Name_P2">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Player 2</string>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="Name_P1">
<property name="minimumSize">
......@@ -1083,6 +1083,7 @@
</property>
<addaction name="actionNew_Game"/>
<addaction name="actionLoad"/>
<addaction name="actionStart_Game"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
......@@ -1092,6 +1093,7 @@
</property>
<addaction name="actionChange_Name"/>
<addaction name="actionChange_Points"/>
<addaction name="actionWhich_Player"/>
<addaction name="separator"/>
<addaction name="actionReconnect"/>
</widget>
......@@ -1138,11 +1140,6 @@
<string>Ctrl+P</string>
</property>
</action>
<action name="actionChoose_Player">
<property name="text">
<string>Choose Player</string>
</property>
</action>
<action name="actionReconnect">
<property name="text">
<string>Reconnect</string>
......@@ -1175,6 +1172,22 @@
<string>Ctrl+Alt+N</string>
</property>
</action>
<action name="actionStart_Game">
<property name="text">
<string>Start Game</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionWhich_Player">
<property name="text">
<string>Which Player?</string>
</property>
<property name="shortcut">
<string>Ctrl+W</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>C1_1</tabstop>
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="windowModality">
<enum>Qt::NonModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>668</width>
<height>498</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="QuestionText">
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -9,6 +9,8 @@ import threading
import socket
import time
import zipfile
import random
from os import path
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.uic import *
......@@ -20,6 +22,8 @@ from PyQt4.uic import *
PORT = 50000
IP = "127.0.0.1"
PLAYERS_MAX = 4
CATEGORIES_MAX = 5
QUESTION_LENGTH_MAX = 1024 * 1024
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~ CLASS DEFINITION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -184,10 +188,15 @@ class StartGUI(QDialog):
self.players[i].solved = [[0 for i in range(5)] for j in range(5)]
self.killSocket = False
self.setupPlayersView()
self.UI_Main.actionLoad.setEnabled(True)
self.UI_Main.actionStart_Game.setEnabled(False)
self.UI_Main.setVisible(True)
self.UI_Start.close()
def setupPlayersView(self):
self.UI_Main.numberOfPlayers = int(self.UI_Start.O_NumberOfPlayers.text())
self.UI_Main.questionPaths = []
if self.players[0].name:
self.UI_Main.Name_P1.setVisible(True)
self.UI_Main.Name_P1.setText(self.players[0].name)
......@@ -327,34 +336,149 @@ class ChangePointsGUI(QDialog):
pass
class QuestionGUI(QDialog):
def __init__(self, text):
QDialog.__init__(self)
self.UI_Question = loadUi("GUIs/question.ui", self)
self.UI_Question.QuestionText.setHtml(text)
self.UI_Question.show()
class MainGUI(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.UI_Main = loadUi("GUIs/main.ui", self)
self.socket = Comunication("", PORT)
self.players = [Player() for i in range(PLAYERS_MAX)]
self.questionPaths = []
self.numberOfPlayers = 0
self.categoryNames = [self.UI_Main.Cat_Name_1,
self.UI_Main.Cat_Name_2,
self.UI_Main.Cat_Name_3,
self.UI_Main.Cat_Name_4,
self.UI_Main.Cat_Name_5]
self.UI_Main.C1_1.setEnabled(False)
self.UI_Main.C1_2.setEnabled(False)
self.UI_Main.C1_3.setEnabled(False)
self.UI_Main.C1_4.setEnabled(False)
self.UI_Main.C1_5.setEnabled(False)
self.UI_Main.C2_1.setEnabled(False)
self.UI_Main.C2_2.setEnabled(False)
self.UI_Main.C2_3.setEnabled(False)
self.UI_Main.C2_4.setEnabled(False)
self.UI_Main.C2_5.setEnabled(False)
self.UI_Main.C3_1.setEnabled(False)
self.UI_Main.C3_2.setEnabled(False)
self.UI_Main.C3_3.setEnabled(False)
self.UI_Main.C3_4.setEnabled(False)
self.UI_Main.C3_5.setEnabled(False)
self.UI_Main.C4_1.setEnabled(False)
self.UI_Main.C4_2.setEnabled(False)
self.UI_Main.C4_3.setEnabled(False)
self.UI_Main.C4_4.setEnabled(False)
self.UI_Main.C4_5.setEnabled(False)
self.UI_Main.C5_1.setEnabled(False)
self.UI_Main.C5_2.setEnabled(False)
self.UI_Main.C5_3.setEnabled(False)
self.UI_Main.C5_4.setEnabled(False)
self.UI_Main.C5_5.setEnabled(False)
self.UI_Main.actionStart_Game.setEnabled(False)
self.UI_Main.actionChange_Name.triggered.connect(self.changePlayerName)
self.UI_Main.actionChange_Points.triggered.connect(self.changePlayerPoints)
self.UI_Main.actionNew_Game.triggered.connect(self.newGame)
self.UI_Main.actionAbout.triggered.connect(self.about)
self.UI_Main.actionReconnect.triggered.connect(self.reconnect)
self.UI_Main.actionLoad.triggered.connect(self.LoadQuestionSet)
self.UI_Main.actionLoad.triggered.connect(self.loadQuestionSet)
self.UI_Main.actionStart_Game.triggered.connect(self.startGame)
self.UI_Main.actionWhich_Player.triggered.connect(self.whichPlayer)
self.UI_Main.connect(self.UI_Main.C1_1, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C1_2, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C1_3, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C1_4, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C1_5, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C2_1, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C2_2, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C2_3, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C2_4, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C2_5, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C3_1, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C3_2, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C3_3, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C3_4, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C3_5, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C4_1, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C4_2, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C4_3, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C4_4, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C4_5, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C5_2, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C5_3, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C5_1, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C5_4, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.connect(self.UI_Main.C5_5, SIGNAL("clicked()"), self.questionClicked)
self.UI_Main.show()
self.UI_Main.actionNew_Game.trigger()
def LoadQuestionSet(self):
# TODO only show the pure filname as name of the category
# TODO only read when the question window pops up
# TODO support multiple types (textfiles, Images, soundfiles)
zipfilenames = QFileDialog.getOpenFileNames(self, "Load Question Set", '', "ZIP-Files (*.zip)")
questions = []
if zipfilenames:
for zipfilename in zipfilenames:
self.UI_Main.Cat_Name_1.setText(zipfilename[0:-3])
with zipfile.ZipFile(zipfilename) as z:
for filename in z.namelist():
questions.append(str(z.open(filename).read()))
print(questions)
def questionClicked(self):
# TODO Possibility to show more then text, e.g. html, sound, picture
sender = self.sender().objectName()
cat = int(sender[1]) - 1
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)
def loadQuestionSet(self):
self.questionPaths = QFileDialog.getOpenFileNames(self, "Load Question Set", '', "ZIP-Files (*.zip)")
if self.questionPaths:
if len(self.questionPaths) >= CATEGORIES_MAX:
self.UI_Main.actionLoad.setEnabled(False)
self.UI_Main.actionStart_Game.setEnabled(True)
self.questionPaths = self.questionPaths[:CATEGORIES_MAX]
for i in range(len(self.questionPaths)):
self.categoryNames[i].setText(path.splitext(path.basename(self.questionPaths[i]))[0])
self.showMsg(str(len(self.questionPaths)) + " categories loaded")
def startGame(self):
if len(self.questionPaths) < CATEGORIES_MAX:
self.showMsg("Load more categories to start the game, only " + len(self.questionPaths) + " categorie(s) loaded")
else:
self.UI_Main.C1_1.setEnabled(True)
self.UI_Main.C1_2.setEnabled(True)
self.UI_Main.C1_3.setEnabled(True)
self.UI_Main.C1_4.setEnabled(True)
self.UI_Main.C1_5.setEnabled(True)
self.UI_Main.C2_1.setEnabled(True)
self.UI_Main.C2_2.setEnabled(True)
self.UI_Main.C2_3.setEnabled(True)
self.UI_Main.C2_4.setEnabled(True)
self.UI_Main.C2_5.setEnabled(True)
self.UI_Main.C3_1.setEnabled(True)
self.UI_Main.C3_2.setEnabled(True)
self.UI_Main.C3_3.setEnabled(True)
self.UI_Main.C3_4.setEnabled(True)
self.UI_Main.C3_5.setEnabled(True)
self.UI_Main.C4_1.setEnabled(True)
self.UI_Main.C4_2.setEnabled(True)
self.UI_Main.C4_3.setEnabled(True)
self.UI_Main.C4_4.setEnabled(True)
self.UI_Main.C4_5.setEnabled(True)
self.UI_Main.C5_1.setEnabled(True)
self.UI_Main.C5_2.setEnabled(True)
self.UI_Main.C5_3.setEnabled(True)
self.UI_Main.C5_4.setEnabled(True)
self.UI_Main.C5_5.setEnabled(True)
self.UI_Main.actionStart_Game.setEnabled(False)
self.showMsg("Game started, >> Player " + str(random.randint(1, int(self.numberOfPlayers))) + " << begins")
def whichPlayer(self):
self.showMsg(">> Player " + str(random.randint(1, int(self.numberOfPlayers))) + " << has to choose the next task")
def reconnect(self):
self.UI_Reconnect = ReconnectGUI(self.socket, self.UI_Main)
......
This is Question for 200 bucks in Category 1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;">
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Wie ist die Frage auf<br /><br />folgende</p>
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Antwort:</p>
<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:36pt; font-weight:600;">42</span></p>
<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This is Question for 200 bucks in Category 1</p>
<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">ENDE</p></body></html>
No preview for this file type
import sys
from PyQt4 import QtGui, QtCore
class Main(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.initUI()
def initUI(self):
self.timer = QtCore.QTimer(self)
self.lcd = QtGui.QLCDNumber(self)
self.lcd.setDigitCount(8)
self.time = QtGui.QTimeEdit(self)
self.timer.timeout.connect(self.Time)
self.set = QtGui.QPushButton("Set",self)
self.set.clicked.connect(self.Set)
self.stop = QtGui.QPushButton("Stop",self)
self.stop.clicked.connect(lambda: self.timer.stop())
grid = QtGui.QGridLayout(self)
grid.addWidget(self.lcd,3,0)
grid.addWidget(self.time,0,0)
grid.addWidget(self.set,1,0)
grid.addWidget(self.stop,2,0)
centralwidget = QtGui.QWidget()
self.setCentralWidget(centralwidget)
centralwidget.setLayout(grid)
#---------Window settings --------------------------------
self.setGeometry(300,300,280,170)
def Set(self):
global t,h,m,s
t = self.time.time()
self.lcd.display(t.toString())
self.timer.start(1000)
h = t.hour()
m = t.minute()
s = t.second()
def Time(self):
global t,h,m,s
if s > 0:
s -=1
else:
if m > 0:
m -= 1
s = 59
elif m == 0 and h > 0:
h -= 1
m = 59
s = 59
else:
self.timer.stop()
stop = QtGui.QMessageBox.warning(self,"Time is up","Time is up")
time = ("{0}:{1}:{2}".format(h,m,s))
self.lcd.setDigitCount(len(time))
self.lcd.display(time)
def main():
app = QtGui.QApplication(sys.argv)
main= Main()
main.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
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