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 @@ ...@@ -2,9 +2,6 @@
<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>
...@@ -13,230 +10,214 @@ ...@@ -13,230 +10,214 @@
<height>299</height> <height>299</height>
</rect> </rect>
</property> </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"> <property name="windowTitle">
<string>Hacker Jeopardy</string> <string>Hacker Jeopardy</string>
</property> </property>
<widget class="QPushButton" name="I_Start"> <layout class="QVBoxLayout" name="verticalLayout_3">
<property name="enabled"> <item>
<bool>false</bool> <widget class="QSplitter" name="splitter">
</property> <property name="orientation">
<property name="geometry"> <enum>Qt::Horizontal</enum>
<rect> </property>
<x>10</x> <widget class="QWidget" name="layoutWidget">
<y>220</y> <layout class="QVBoxLayout" name="Input_IPAddress">
<width>321</width> <item>
<height>31</height> <widget class="QLabel" name="O_Name_IPAddress_Edit">
</rect> <property name="text">
</property> <string>IP-Adresse</string>
<property name="text"> </property>
<string>Start Game</string> </widget>
</property> </item>
</widget> <item>
<widget class="QSplitter" name="splitter"> <widget class="QLineEdit" name="I_IPAdress">
<property name="geometry"> <property name="toolTip">
<rect> <string>IPv4-Adresse</string>
<x>10</x> </property>
<y>10</y> <property name="inputMask">
<width>321</width> <string>000.000.000.000;_</string>
<height>41</height> </property>
</rect> <property name="text">
</property> <string>...</string>
<property name="orientation"> </property>
<enum>Qt::Horizontal</enum> <property name="maxLength">
</property> <number>15</number>
<widget class="QWidget" name="layoutWidget"> </property>
<layout class="QVBoxLayout" name="Input_IPAddress"> <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> <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"> <property name="text">
<string>IP-Adresse</string> <string/>
</property>
<property name="placeholderText">
<string>Spieler 1</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="I_IPAdress"> <widget class="QLineEdit" name="I_NamePlayer2">
<property name="toolTip"> <property name="enabled">
<string>IPv4-Adresse</string> <bool>false</bool>
</property> </property>
<property name="inputMask"> <property name="text">
<string/> <string/>
</property> </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"> <property name="text">
<string/> <string/>
</property> </property>
<property name="maxLength"> <property name="placeholderText">
<number>15</number> <string>Spieler 3</string>
</property> </property>
<property name="cursorPosition"> </widget>
<number>0</number> </item>
<item>
<widget class="QLineEdit" name="I_NamePlayer4">
<property name="enabled">
<bool>false</bool>
</property> </property>
<property name="alignment"> <property name="text">
<set>Qt::AlignCenter</set> <string/>
</property> </property>
<property name="placeholderText"> <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/> <string/>
</property> </property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </item>
<widget class="QPushButton" name="I_Connect"> </layout>
<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>
<zorder>splitter</zorder> <zorder>splitter</zorder>
<zorder>layoutWidget</zorder> <zorder>layoutWidget</zorder>
<zorder>layoutWidget</zorder> <zorder>layoutWidget</zorder>
......
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
import sys import sys
#import psutil
import threading import threading
import socket import socket
import time
from PyQt4.QtCore import * from PyQt4.QtCore import *
from PyQt4.QtGui import * from PyQt4.QtGui import *
from PyQt4.uic import * from PyQt4.uic import *
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~ GLOBAL CONSTANTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~ GLOBAL CONSTANTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...@@ -30,6 +31,7 @@ class Comunication: ...@@ -30,6 +31,7 @@ class Comunication:
def __init__(self, ip, port): def __init__(self, ip, port):
self.__ip = ip self.__ip = ip
self.__port = port self.__port = port
self.socketCreated = False
def check_ip(self): def check_ip(self):
try: try:
...@@ -50,21 +52,9 @@ class Comunication: ...@@ -50,21 +52,9 @@ class Comunication:
class Player: class Player:
def __init__(self, name): def __init__(self):
self.Points = 0 self.points = 0
self.Name = name self.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
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...@@ -74,32 +64,29 @@ class Player: ...@@ -74,32 +64,29 @@ class Player:
class GUI: class GUI:
def __init__(self): def __init__(self):
self.socketCreated = False self.players = [Player() for i in range(PLAYERS_MAX)]
self.players = [] self.__app = QApplication(sys.argv)
self.__start = StartGUI(self.players)
self.__app.exec_()
#self.kill_proc_tree(os.getpid())
self.app = QApplication(sys.argv) #def kill_proc_tree(pid, including_parent=True):
start = StartGUI(self.socketCreated, self.players) #parent = psutil.Process(pid)
self.app.exec_() #if including_parent:
self.app.aboutToQuit(self.cleanup()) #parent.kill()
def cleanup(self):
if self.socketCreated:
self.UDP.cleanup()
print("Bye Bye")
sys.exit(0)
class StartGUI: class StartGUI:
def __init__(self, socketCreated, players): def __init__(self, players):
self.__UI_Start = loadUi("GUIs/start.ui") self.__UI_Start = loadUi("GUIs/start.ui")
self.socketCreated = socketCreated
self.players = players self.players = players
self.players_ready = [False] * PLAYERS_MAX self.__player_name_entered = [False] * PLAYERS_MAX
self.playerInputs = [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) 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_Start, SIGNAL("clicked()"), self.start)
...@@ -111,59 +98,95 @@ class StartGUI: ...@@ -111,59 +98,95 @@ class StartGUI: