Commit 9ccebfad authored by Agrigor's avatar Agrigor

Code cleaned up, Start GUI finished, Main GUI started with testcode

parent f7a1b92e
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="Button">
<property name="geometry">
<rect>
<x>210</x>
<y>170</y>
<width>99</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QLabel" name="O_Msg">
<property name="geometry">
<rect>
<x>100</x>
<y>340</y>
<width>551</width>
<height>51</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QLabel" name="O_Msg_2">
<property name="geometry">
<rect>
<x>120</x>
<y>250</y>
<width>551</width>
<height>51</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QPushButton" name="Button_2">
<property name="geometry">
<rect>
<x>510</x>
<y>160</y>
<width>99</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
......@@ -2,9 +2,6 @@
<ui version="4.0">
<class>StartGUI</class>
<widget class="QDialog" name="StartGUI">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
......@@ -13,230 +10,214 @@
<height>299</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</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">
<string>Hacker Jeopardy</string>
</property>
<widget class="QPushButton" name="I_Start">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>220</y>
<width>321</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Start Game</string>
</property>
</widget>
<widget class="QSplitter" name="splitter">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>321</width>
<height>41</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="Input_IPAddress">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="Input_IPAddress">
<item>
<widget class="QLabel" name="O_Name_IPAddress_Edit">
<property name="text">
<string>IP-Adresse</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="I_IPAdress">
<property name="toolTip">
<string>IPv4-Adresse</string>
</property>
<property name="inputMask">
<string>000.000.000.000;_</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="maxLength">
<number>15</number>
</property>
<property name="cursorPosition">
<number>0</number>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="placeholderText">
<string>000.000.000.000</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QPushButton" name="I_Connect">
<property name="text">
<string>Connect</string>
</property>
</widget>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="O_Name_NumberOfPlayers_Edit">
<property name="text">
<string>Anzahl Spieler:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="O_NumberOfPlayers">
<property name="text">
<string>1</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QSlider" name="I_NumberOfPlayers">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>4</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="Input_PlayerNames">
<item>
<widget class="QLabel" name="O_Name_IPAddress_Edit">
<widget class="QLineEdit" name="I_NamePlayer1">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>IP-Adresse</string>
<string/>
</property>
<property name="placeholderText">
<string>Spieler 1</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="I_IPAdress">
<property name="toolTip">
<string>IPv4-Adresse</string>
<widget class="QLineEdit" name="I_NamePlayer2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="inputMask">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Spieler 2</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="I_NamePlayer3">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="maxLength">
<number>15</number>
<property name="placeholderText">
<string>Spieler 3</string>
</property>
<property name="cursorPosition">
<number>0</number>
</widget>
</item>
<item>
<widget class="QLineEdit" name="I_NamePlayer4">
<property name="enabled">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Spieler 4</string>
</property>
</widget>
</item>
</layout>
</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>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="KSeparator" name="kseparator">
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="O_Msg">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QPushButton" name="I_Connect">
<property name="text">
<string>Connect</string>
</property>
</widget>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>110</y>
<width>321</width>
<height>102</height>
</rect>
</property>
<layout class="QVBoxLayout" name="Input_PlayerNames">
<item>
<widget class="QLineEdit" name="I_NamePlayer1">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Spieler 1</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="I_NamePlayer2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Spieler 2</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="I_NamePlayer3">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Spieler 3</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="I_NamePlayer4">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Spieler 4</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>11</x>
<y>60</y>
<width>321</width>
<height>45</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="O_Name_NumberOfPlayers_Edit">
<property name="text">
<string>Anzahl Spieler:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="O_NumberOfPlayers">
<property name="text">
<string>1</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QSlider" name="I_NumberOfPlayers">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>4</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QLabel" name="O_Msg">
<property name="geometry">
<rect>
<x>10</x>
<y>260</y>
<width>321</width>
<height>31</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="KSeparator" name="kseparator">
<property name="geometry">
<rect>
<x>10</x>
<y>250</y>
<width>321</width>
<height>20</height>
</rect>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
</widget>
</item>
</layout>
<zorder>splitter</zorder>
<zorder>layoutWidget</zorder>
<zorder>layoutWidget</zorder>
......
......@@ -6,13 +6,14 @@
import sys
#import psutil
import threading
import socket
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.uic import *
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~ GLOBAL CONSTANTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -30,6 +31,7 @@ class Comunication:
def __init__(self, ip, port):
self.__ip = ip
self.__port = port
self.socketCreated = False
def check_ip(self):
try:
......@@ -50,21 +52,9 @@ class Comunication:
class Player:
def __init__(self, name):
self.Points = 0
self.Name = name
def get_Points(self):
return self.Points
def set_Points(self, newPoints):
self.Points = newPoints
def get_Name(self):
return self.Name
def set_Name(self, newName):
self.Name = newName
def __init__(self):
self.points = 0
self.name = ""
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -74,32 +64,29 @@ class Player:
class GUI:
def __init__(self):
self.socketCreated = False
self.players = []
self.players = [Player() for i in range(PLAYERS_MAX)]
self.__app = QApplication(sys.argv)
self.__start = StartGUI(self.players)
self.__app.exec_()
#self.kill_proc_tree(os.getpid())
self.app = QApplication(sys.argv)
start = StartGUI(self.socketCreated, self.players)
self.app.exec_()
self.app.aboutToQuit(self.cleanup())
#def kill_proc_tree(pid, including_parent=True):
#parent = psutil.Process(pid)
#if including_parent:
#parent.kill()
def cleanup(self):
if self.socketCreated:
self.UDP.cleanup()
print("Bye Bye")
sys.exit(0)
class StartGUI:
def __init__(self, socketCreated, players):
def __init__(self, players):
self.__UI_Start = loadUi("GUIs/start.ui")
self.socketCreated = socketCreated
self.players = players
self.players_ready = [False] * PLAYERS_MAX
self.playerInputs = [self.__UI_Start.I_NamePlayer1,
self.__UI_Start.I_NamePlayer2,
self.__UI_Start.I_NamePlayer3,
self.__UI_Start.I_NamePlayer4]
self.__player_name_entered = [False] * PLAYERS_MAX
self.__playerNameInputs = [self.__UI_Start.I_NamePlayer1,
self.__UI_Start.I_NamePlayer2,
self.__UI_Start.I_NamePlayer3,
self.__UI_Start.I_NamePlayer4]
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)
......@@ -111,59 +98,95 @@ class StartGUI:
self.__UI_Start.show()
def name_player_changed(self, name):
for i in range(len(self.playerInputs)):
if i + 1 > int(self.__UI_Start.O_NumberOfPlayers.text()) or len(self.playerInputs[i].text()) > 1:
self.players_ready[i] = True
else:
self.players_ready[i] = False
if all(self.players_ready):
self.__UI_Start.I_Start.setDisabled(False)
def connect(self):
self.socket = Comunication(str(self.__UI_Start.I_IPAdress.text()), PORT)
if self.socket.check_ip() and not self.socket.socketCreated:
self.socket.create_client_socket()
self.socket.socketCreated = True
self.__UI_Start.I_Connect.setDisabled(True)
self.__UI_Start.I_IPAdress.setDisabled(True)
self.show_msg("Connected")
self.__UI_Start.I_NumberOfPlayers.setDisabled(False)
self.__UI_Start.I_NamePlayer1.setDisabled(False)
else:
self.__UI_Start.I_Start.setDisabled(True)
self.show_msg("No valid IP-address")
self.socket.socketCreated = False
def show_names_input_field(self, number):
number -= 1
for i in range(len(self.playerInputs)):
if i <= number and self.socketCreated:
self.playerInputs[i].setDisabled(False)
for i in range(len(self.__playerNameInputs)):
if i <= number and self.socket.socketCreated:
self.__playerNameInputs[i].setDisabled(False)
else:
self.playerInputs[i].setDisabled(True)
self.__playerNameInputs[i].setDisabled(True)
if number >= 1:
self.show_msg(str(number + 1) + " Players")
else:
self.show_msg("1 Player")