-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui.py
114 lines (89 loc) · 3.89 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont, QIcon
from PyQt5.QtWidgets import QApplication, QLabel, QGridLayout, QPushButton, QWidget
import sys
class DisplayWindow(QWidget):
def __init__(self, font, font_size, font_color, bg_color):
super().__init__()
self.setGeometry(300, 300, 200, 400)
self.setWindowTitle('Display')
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.setStyleSheet('QWidget {background-color: ' + bg_color + '}')
text = 'ATTACKERS:\n' \
' BLACKBEARD\n' \
' --\n' \
' --\n' \
'DEFENDERS:\n' \
' --\n' \
' --\n' \
' --'
self._label = QLabel(text, self)
self._label.setFont(QFont(font, font_size, QFont.Bold))
self._label.setStyleSheet('QLabel { color: ' + font_color + ';}')
self._offset = None
self.show()
text = 'ATTACKERS:\n' \
' --\n' \
' --\n' \
' --\n' \
'DEFENDERS:\n' \
' --\n' \
' --\n' \
' --'
self._label.setText(text)
def update_text(self, text):
self._label.setText(text)
def mousePressEvent(self, event):
self._offset = event.pos()
def mouseMoveEvent(self, event):
if event.buttons() == Qt.RightButton:
x = event.globalX()
y = event.globalY()
x_w = self._offset.x()
y_w = self._offset.y()
self.move(x - x_w, y - y_w)
class ControlWindow(QWidget):
def __init__(self, font, font_size, font_color):
super().__init__()
self.setGeometry(550, 350, 100, 100)
self.setWindowTitle('Control')
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.setAttribute(Qt.WA_TranslucentBackground)
grid = QGridLayout()
self.setLayout(grid)
self.button_attacker = QPushButton('Next Attacker', self)
self.button_attacker.clicked.connect(self.handle_button_attacker)
self.button_attacker.setFont((QFont(font, font_size, QFont.Bold)))
self.button_attacker.setStyleSheet('QPushButton {background-color: rgba(255, 255, 255, 55); color: '
+ font_color + ';}')
self.button_defender = QPushButton('Next Defender', self)
self.button_defender.clicked.connect(self.handle_button_defender)
self.button_defender.setFont((QFont(font, font_size, QFont.Bold)))
self.button_defender.setStyleSheet('QPushButton {background-color: rgba(255, 255, 255, 55); color: '
+ font_color + ';}')
grid.addWidget(self.button_attacker, 0, 0)
grid.addWidget(self.button_defender, 1, 0)
self._offset = None
self.show()
def handle_button_attacker(self):
pass # overridden in run.py
def handle_button_defender(self):
pass # overridden in run.py
def mousePressEvent(self, event):
self._offset = event.pos()
def mouseMoveEvent(self, event):
if event.buttons() == Qt.RightButton:
x = event.globalX()
y = event.globalY()
x_w = self._offset.x()
y_w = self._offset.y()
self.move(x - x_w, y - y_w)
class GUI:
def __init__(self, button_attacker_fn, button_defender_fn, font, bg_color):
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
self.app = QApplication(sys.argv)
self.app.setWindowIcon(QIcon('icon.png'))
ControlWindow.handle_button_attacker = button_attacker_fn
ControlWindow.handle_button_defender = button_defender_fn
self.display_window = DisplayWindow(font[0], font[1], font[2], bg_color)
self.control_window = ControlWindow(font[0], font[1], font[2])