Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
Jeopardy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hacksaar
Jeopardy
Commits
9ccebfad
Commit
9ccebfad
authored
Nov 19, 2015
by
Agrigor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleaned up, Start GUI finished, Main GUI started with testcode
parent
f7a1b92e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
395 additions
and
267 deletions
+395
-267
client/GUIs/main.ui
client/GUIs/main.ui
+96
-0
client/GUIs/start.ui
client/GUIs/start.ui
+184
-203
client/gui.py
client/gui.py
+87
-64
client/test.py
client/test.py
+28
-0
No files found.
client/GUIs/main.ui
0 → 100644
View file @
9ccebfad
<?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>
client/GUIs/start.ui
View file @
9ccebfad
...
...
@@ -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,34 +10,30 @@
<height>
299
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
<string>
Hacker Jeopardy
</string>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Fixed"
vsizetype=
"Fixed"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<widget
class=
"QPushButton"
name=
"I_Start"
>
<property
name=
"enabled"
>
<bool>
false
</bool>
<property
name=
"minimumSize"
>
<size>
<width>
339
</width>
<height>
299
</height>
</size>
</property>
<property
name=
"geometry"
>
<rect>
<x>
10
</x>
<y>
220
</y>
<width>
321
</width>
<height>
31
</height>
</rect>
<property
name=
"maximumSize"
>
<size>
<width>
339
</width>
<height>
299
</height>
</size>
</property>
<property
name=
"text
"
>
<string>
Start Game
</string>
<property
name=
"windowTitle
"
>
<string>
Hacker Jeopardy
</string>
</property>
</widget>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout_3"
>
<item>
<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>
...
...
@@ -59,10 +52,10 @@
<string>
IPv4-Adresse
</string>
</property>
<property
name=
"inputMask"
>
<string/
>
<string>
000.000.000.000;_
</string
>
</property>
<property
name=
"text"
>
<string/
>
<string>
...
</string
>
</property>
<property
name=
"maxLength"
>
<number>
15
</number>
...
...
@@ -74,7 +67,7 @@
<set>
Qt::AlignCenter
</set>
</property>
<property
name=
"placeholderText"
>
<string/
>
<string>
000.000.000.000
</string
>
</property>
</widget>
</item>
...
...
@@ -86,15 +79,52 @@
</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>
</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=
"QLineEdit"
name=
"I_NamePlayer1"
>
...
...
@@ -149,68 +179,28 @@
</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
>
<widget
class=
"QPushButton"
name=
"I_Start
"
>
<property
name=
"enabled
"
>
<bool>
false
</bool
>
</property>
<property
name=
"alignmen
t"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set
>
<property
name=
"tex
t"
>
<string>
Start Game
</string
>
</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>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout_2"
>
<item>
<widget
class=
"KSeparator"
name=
"kseparator"
>
<property
name=
"frameShadow"
>
<enum>
QFrame::Sunken
</enum>
</property>
</widget>
</item>
</layout>
</widget>
<item>
<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>
...
...
@@ -224,19 +214,10 @@
<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>
</item>
</layout>
<zorder>
splitter
</zorder>
<zorder>
layoutWidget
</zorder>
<zorder>
layoutWidget
</zorder>
...
...
client/gui.py
View file @
9ccebfad
...
...
@@ -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,29 +64,26 @@ 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
.
player
Inputs
=
[
self
.
__UI_Start
.
I_NamePlayer1
,
self
.
__player_name_entered
=
[
False
]
*
PLAYERS_MAX
self
.
__playerName
Inputs
=
[
self
.
__UI_Start
.
I_NamePlayer1
,
self
.
__UI_Start
.
I_NamePlayer2
,
self
.
__UI_Start
.
I_NamePlayer3
,
self
.
__UI_Start
.
I_NamePlayer4
]
...
...
@@ -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
.
player
Inputs
)):
if
i
<=
number
and
self
.
socketCreated
:
self
.
player
Inputs
[
i
].
setDisabled
(
False
)
for
i
in
range
(
len
(
self
.
__playerName
Inputs
)):
if
i
<=
number
and
self
.
socket
.
socket
Created
:
self
.
__playerName
Inputs
[
i
].
setDisabled
(
False
)
else
:
self
.
player
Inputs
[
i
].
setDisabled
(
True
)
self
.
__playerName
Inputs
[
i
].
setDisabled
(
True
)
if
number
>=
1
:
self
.
show_msg
(
str
(
number
+
1
)
+
" Players"
)
else
:
self
.
show_msg
(
"1 Player"
)
def
name_player_changed
(
self
,
name
):
for
i
in
range
(
len
(
self
.
__playerNameInputs
)):
if
i
+
1
>
int
(
self
.
__UI_Start
.
O_NumberOfPlayers
.
text
())
or
len
(
self
.
__playerNameInputs
[
i
].
text
())
>
1
:
self
.
__player_name_entered
[
i
]
=
True
else
:
self
.
__player_name_entered
[
i
]
=
False
if
all
(
self
.
__player_name_entered
):
self
.
__UI_Start
.
I_Start
.
setDisabled
(
False
)
else
:
self
.
__UI_Start
.
I_Start
.
setDisabled
(
True
)
def
start
(
self
):
namesOfPlayers
=
[
str
(
self
.
__UI_Start
.
I_NamePlayer1
.
text
()),
str
(
self
.
__UI_Start
.
I_NamePlayer2
.
text
()),
str
(
self
.
__UI_Start
.
I_NamePlayer3
.
text
()),
str
(
self
.
__UI_Start
.
I_NamePlayer4
.
text
())]
for
i
in
range
(
0
,
int
(
self
.
__UI_Start
.
O_NumberOfPlayers
.
text
())):
self
.
players
.
append
(
Player
(
namesOfPlayers
[
i
]))
def
connect
(
self
):
self
.
UDP
=
Comunication
(
str
(
self
.
__UI_Start
.
I_IPAdress
.
text
()),
PORT
)
if
self
.
UDP
.
check_ip
()
and
not
self
.
socketCreated
:
self
.
UDP
.
create_client_socket
()
self
.
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
.
show_msg
(
"No valid IP-address"
)
self
.
socketCreated
=
False
self
.
players
[
i
].
name
=
namesOfPlayers
[
i
]
self
.
main
=
MainGUI
(
self
.
socket
,
self
.
players
)
self
.
__UI_Start
.
close
()
def
show_msg
(
self
,
msg
):
self
.
__UI_Start
.
O_Msg
.
setText
(
msg
)
# TODO Include this method if window is closed by user
def
cleanup
(
self
):
if
self
.
socketCreated
:
self
.
UDP
.
cleanup
()
if
self
.
socket
.
socket
Created
:
self
.
socket
.
cleanup
()
class
MainGUI
:
def
__init__
(
self
,
socket
,
players
):
self
.
UI_Main
=
loadUi
(
"GUIs/main.ui"
)
self
.
socket
=
socket
self
.
players
=
players
self
.
UI_Main
.
connect
(
self
.
UI_Main
.
Button
,
SIGNAL
(
"clicked()"
),
self
.
button
)
self
.
UI_Main
.
connect
(
self
.
UI_Main
.
Button_2
,
SIGNAL
(
"clicked()"
),
self
.
button_2
)
self
.
UI_Main
.
show
()
def
button_2
(
self
):
self
.
stop_event
.
set
()
def
button
(
self
):
self
.
stop_event
=
threading
.
Event
()
self
.
c_thread
=
threading
.
Thread
(
target
=
self
.
listen_communication
,
args
=
(
self
.
stop_event
,))
self
.
c_thread
.
start
()
def
listen_communication
(
self
,
stop_event
):
while
True
and
not
stop_event
.
isSet
():
daten
,
addr
=
self
.
socket
.
receive
(
1024
)
self
.
show_msg
(
addr
[
0
]
+
" -> "
+
daten
.
decode
())
time
.
sleep
(
0.1
)
def
show_msg
(
self
,
msg
):
self
.
UI_Main
.
O_Msg
.
setText
(
msg
)
# TODO Include this method if window is closed by user
def
cleanup
(
self
):
if
self
.
socket
.
socketCreated
:
self
.
socket
.
cleanup
()
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PROGRAM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
client/test.py
0 → 100644
View file @
9ccebfad
class
Player
:
def
__init__
(
self
):
self
.
punkte
=
0
self
.
name
=
"nix"
class
GUI
:
def
__init__
(
self
):
self
.
players
=
[
Player
()
for
i
in
range
(
4
)]
self
.
players
[
1
].
punkte
=
1337
self
.
players
[
1
].
name
=
"bla"
self
.
main
=
MAIN
(
self
.
players
)
class
MAIN
:
def
__init__
(
self
,
foo
):
self
.
foo
=
foo
self
.
show
()
def
show
(
self
):
print
(
self
.
foo
[
0
].
name
)
print
(
self
.
foo
[
1
].
name
)
bar
=
GUI
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment