Commit a9343d84 authored by Agrigor's avatar Agrigor

New Main_GUI, new dialog structure, new Change_Name dialog, new Change_Points...

New Main_GUI, new dialog structure, new Change_Name dialog, new Change_Points dialog and a lot of other improvements
parent 42e0ebb2
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Change Names</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLineEdit" name="name_player_1"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_player_4">
<property name="text">
<string>Player 4</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="name_player_3">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_player_1">
<property name="text">
<string>Player 1</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_player_2">
<property name="text">
<string>Player 2</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_player_3">
<property name="text">
<string>Player 3</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="name_player_2">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="name_player_4">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>name_player_1</tabstop>
<tabstop>name_player_2</tabstop>
<tabstop>name_player_3</tabstop>
<tabstop>name_player_4</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Change Points</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QLabel" name="label_player_4">
<property name="text">
<string>Player 4</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_player_1">
<property name="text">
<string>Player 1</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_player_2">
<property name="text">
<string>Player 2</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_player_3">
<property name="text">
<string>Player 3</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="points_player_1">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="maximum">
<number>9900</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="points_player_2">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="maximum">
<number>9900</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="points_player_3">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="maximum">
<number>9900</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="points_player_4">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="maximum">
<number>9900</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>points_player_1</tabstop>
<tabstop>points_player_2</tabstop>
<tabstop>points_player_3</tabstop>
<tabstop>points_player_4</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
This diff is collapsed.
...@@ -2,32 +2,23 @@ ...@@ -2,32 +2,23 @@
<ui version="4.0"> <ui version="4.0">
<class>StartGUI</class> <class>StartGUI</class>
<widget class="QDialog" name="StartGUI"> <widget class="QDialog" name="StartGUI">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>339</width> <width>300</width>
<height>299</height> <height>300</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize">
<size>
<width>339</width>
<height>299</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>339</width>
<height>299</height>
</size>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Hacker Jeopardy</string> <string>Hacker Jeopardy</string>
</property> </property>
...@@ -52,17 +43,20 @@ ...@@ -52,17 +43,20 @@
<string>IPv4-Adresse</string> <string>IPv4-Adresse</string>
</property> </property>
<property name="text"> <property name="text">
<string/> <string>127.0.0.1</string>
</property> </property>
<property name="maxLength"> <property name="maxLength">
<number>32767</number> <number>32767</number>
</property> </property>
<property name="cursorPosition"> <property name="cursorPosition">
<number>0</number> <number>9</number>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
</property> </property>
<property name="placeholderText">
<string>127.0.0.1</string>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
...@@ -172,18 +166,18 @@ ...@@ -172,18 +166,18 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="I_Start">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Start Game</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item>
<widget class="QPushButton" name="I_Start">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Start Game</string>
</property>
</widget>
</item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
...@@ -214,7 +208,6 @@ ...@@ -214,7 +208,6 @@
<tabstop>I_NamePlayer2</tabstop> <tabstop>I_NamePlayer2</tabstop>
<tabstop>I_NamePlayer3</tabstop> <tabstop>I_NamePlayer3</tabstop>
<tabstop>I_NamePlayer4</tabstop> <tabstop>I_NamePlayer4</tabstop>
<tabstop>I_Start</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections> <connections>
......
...@@ -62,47 +62,50 @@ class Player: ...@@ -62,47 +62,50 @@ class Player:
class GUI: class GUI:
def __init__(self): def __init__(self):
self.app = QApplication(sys.argv) self.app = QApplication(sys.argv)
self.start = StartGUI() self.start = MainGUI()
sys.exit(self.app.exec_()) sys.exit(self.app.exec())
class StartGUI(QDialog): class StartGUI(QDialog):
def __init__(self): def __init__(self, socket, players, UI_Main):
QDialog.__init__(self) QDialog.__init__(self)
self.UI_Start = loadUi("GUIs/start.ui", self) self.UI_Start = loadUi("GUIs/start.ui", self)
self.players = [Player() for i in range(PLAYERS_MAX)] self.socket = socket
self.player_name_entered = [False] * PLAYERS_MAX self.players = players
self.UI_Main = UI_Main
self.playerNameEntered = [False] * PLAYERS_MAX
self.playerNameInputs = [self.UI_Start.I_NamePlayer1, self.playerNameInputs = [self.UI_Start.I_NamePlayer1,
self.UI_Start.I_NamePlayer2, self.UI_Start.I_NamePlayer2,
self.UI_Start.I_NamePlayer3, self.UI_Start.I_NamePlayer3,
self.UI_Start.I_NamePlayer4] self.UI_Start.I_NamePlayer4]
self.UI_Start.connect(self.UI_Start.I_Connect, SIGNAL("clicked()"), self.connect_server) self.UI_Start.connect(self.UI_Start.I_Connect, SIGNAL("clicked()"), self.connectServer)
self.UI_Start.connect(self.UI_Start.I_Start, SIGNAL("clicked()"), self.start) 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_field) self.UI_Start.connect(self.UI_Start.I_NumberOfPlayers, SIGNAL("valueChanged(int)"), self.showNamesInputField)
self.UI_Start.connect(self.UI_Start.I_NamePlayer1, SIGNAL("textChanged(QString)"), self.name_player_changed) self.UI_Start.connect(self.UI_Start.I_NamePlayer1, SIGNAL("textChanged(QString)"), self.namePlayerChanged)
self.UI_Start.connect(self.UI_Start.I_NamePlayer2, SIGNAL("textChanged(QString)"), self.name_player_changed) self.UI_Start.connect(self.UI_Start.I_NamePlayer2, SIGNAL("textChanged(QString)"), self.namePlayerChanged)
self.UI_Start.connect(self.UI_Start.I_NamePlayer3, SIGNAL("textChanged(QString)"), self.name_player_changed) self.UI_Start.connect(self.UI_Start.I_NamePlayer3, SIGNAL("textChanged(QString)"), self.namePlayerChanged)
self.UI_Start.connect(self.UI_Start.I_NamePlayer4, SIGNAL("textChanged(QString)"), self.name_player_changed) self.UI_Start.connect(self.UI_Start.I_NamePlayer4, SIGNAL("textChanged(QString)"), self.namePlayerChanged)
self.killSocket = True self.killSocket = True
self.UI_Start.show() self.UI_Start.show()
def connect_server(self): def connectServer(self):
self.socket = Comunication(str(self.UI_Start.I_IPAdress.text()), PORT) self.socket.ip = str(self.UI_Start.I_IPAdress.text())
if self.socket.check_ip(): if self.socket.check_ip():
self.socket.create_client_socket() self.socket.create_client_socket()
self.UI_Start.I_Connect.setDisabled(True) self.UI_Start.I_Connect.setDisabled(True)
self.UI_Start.I_IPAdress.setDisabled(True) self.UI_Start.I_IPAdress.setDisabled(True)
self.show_msg("Connected") self.showMsg("Connected")
self.UI_Start.I_NumberOfPlayers.setDisabled(False) self.UI_Start.I_NumberOfPlayers.setDisabled(False)
self.UI_Start.I_NamePlayer1.setDisabled(False) self.UI_Start.I_NamePlayer1.setDisabled(False)
else: else:
self.show_msg("No valid IP-address") self.showMsg("No valid IP-address")
def show_names_input_field(self, number): def showNamesInputField(self, number):
number -= 1 number -= 1
for i in range(len(self.playerNameInputs)): for i in range(len(self.playerNameInputs)):
if i <= number: if i <= number:
...@@ -110,17 +113,18 @@ class StartGUI(QDialog): ...@@ -110,17 +113,18 @@ class StartGUI(QDialog):
else: else:
self.playerNameInputs[i].setDisabled(True) self.playerNameInputs[i].setDisabled(True)
if number >= 1: if number >= 1:
self.show_msg(str(number + 1) + " Players") self.showMsg(str(number + 1) + " Players")
else: else:
self.show_msg("1 Player") self.showMsg("1 Player")
def name_player_changed(self, name): def namePlayerChanged(self, name):
for i in range(len(self.playerNameInputs)): for i in range(len(self.playerNameInputs)):
if i + 1 > int(self.UI_Start.O_NumberOfPlayers.text()) or len(self.playerNameInputs[i].text()) > 1: if i + 1 > int(self.UI_Start.O_NumberOfPlayers.text()) or len(self.playerNameInputs[i].text()) > 0:
self.player_name_entered[i] = True
self.playerNameEntered[i] = True
else: else:
self.player_name_entered[i] = False self.playerNameEntered[i] = False
if all(self.player_name_entered): if all(self.playerNameEntered):
self.UI_Start.I_Start.setDisabled(False) self.UI_Start.I_Start.setDisabled(False)
else: else:
self.UI_Start.I_Start.setDisabled(True) self.UI_Start.I_Start.setDisabled(True)
...@@ -130,13 +134,51 @@ class StartGUI(QDialog): ...@@ -130,13 +134,51 @@ class StartGUI(QDialog):
str(self.UI_Start.I_NamePlayer2.text()), str(self.UI_Start.I_NamePlayer2.text()),
str(self.UI_Start.I_NamePlayer3.text()), str(self.UI_Start.I_NamePlayer3.text()),
str(self.UI_Start.I_NamePlayer4.text())] str(self.UI_Start.I_NamePlayer4.text())]
for i in range(0, int(self.UI_Start.O_NumberOfPlayers.text())): for i in range(PLAYERS_MAX):
self.players[i].name = namesOfPlayers[i] self.players[i].name = namesOfPlayers[i]
self.main = MainGUI(self.socket, self.players) self.players[i].points = 0
self.killSocket = False self.killSocket = False
self.setupPlayersView()
self.UI_Start.close() self.UI_Start.close()
def show_msg(self, msg): def setupPlayersView(self):
if self.players[0].name:
self.UI_Main.Name_P1.setVisible(True)
self.UI_Main.Name_P1.setText(self.players[0].name)
self.UI_Main.Points_P1.setVisible(True)
self.UI_Main.Points_P1.display(self.players[0].points)
else:
self.UI_Main.Name_P1.setVisible(False)
self.UI_Main.Points_P1.setVisible(False)
if self.players[1].name:
self.UI_Main.Name_P2.setVisible(True)
self.UI_Main.Name_P2.setText(self.players[1].name)
self.UI_Main.Points_P2.setVisible(True)
self.UI_Main.Points_P2.display(self.players[1].points)
else:
self.UI_Main.Name_P2.setVisible(False)
self.UI_Main.Points_P2.setVisible(False)
if self.players[2].name:
self.UI_Main.Name_P3.setVisible(True)
self.UI_Main.Name_P3.setText(self.players[2].name)
self.UI_Main.Points_P3.setVisible(True)
self.UI_Main.Points_P3.display(self.players[2].points)
else:
self.UI_Main.Name_P3.setVisible(False)
self.UI_Main.Points_P3.setVisible(False)
if self.players[3].name:
self.UI_Main.Name_P4.setVisible(True)
self.UI_Main.Name_P4.setText(self.players[3].name)
self.UI_Main.Points_P4.setVisible(True)
self.UI_Main.Points_P4.display(self.players[3].points)
else:
self.UI_Main.Name_P4.setVisible(False)
self.UI_Main.Points_P4.setVisible(False)
def showMsg(self, msg):
self.UI_Start.O_Msg.setText(msg) self.UI_Start.O_Msg.setText(msg)
def closeEvent(self, event): def closeEvent(self, event):
...@@ -147,38 +189,124 @@ class StartGUI(QDialog): ...@@ -147,38 +189,124 @@ class StartGUI(QDialog):
pass pass
class MainGUI(QMainWindow): class ChangeNamesGUI(QDialog):
def __init__(self, socket, players): def __init__(self, players, UI_Main):
QMainWindow.__init__(self) QDialog.__init__(self)
self.UI_Main = loadUi("GUIs/main.ui", self) self.players = players
self.UI_Main = UI_Main
self.UI_ChangeNames = loadUi("GUIs/change_names.ui")
self.UI_ChangeNames.buttonBox.accepted.connect(self.accept)
self.UI_ChangeNames.buttonBox.rejected.connect(self.reject)
if self.players[0].name:
self.UI_ChangeNames.name_player_1.setDisabled(False)
self.UI_ChangeNames.name_player_1.setText(self.players[0].name)
else:
self.UI_ChangeNames.name_player_1.setDisabled(True)
if self.players[1].name:
self.UI_ChangeNames.name_player_2.setDisabled(False)
self.UI_ChangeNames.name_player_2.setText(self.players[1].name)
else:
self.UI_ChangeNames.name_player_2.setDisabled(True)
if self.players[2].name:
self.UI_ChangeNames.name_player_3.setDisabled(False)
self.UI_ChangeNames.name_player_3.setText(self.players[