-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWidget.py
144 lines (115 loc) · 5.25 KB
/
MainWidget.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import sys
from PyQt5 import QtCore
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QGridLayout, \
QPushButton, QRadioButton, QTextEdit, QLabel, QSizePolicy, QSlider, QHBoxLayout
from PyQt5.QtGui import QFont, QPixmap, QImage
from KZGamer import KZGamerThread
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.kzgamer_thread = KZGamerThread(self)
self.kzgamer_thread.vid_display.new_frame.connect(self.update_video_pane)
self.kzgamer_thread.new_roll.connect(self.log_roll)
self.kzgamer_thread.log.connect(self.log_message)
self.button_grid = QWidget()
self.button_layout = QGridLayout()
self.init_ui()
self.kzgamer_thread.start()
def init_ui(self):
self.setWindowTitle("KZGamer")
main_layout = QVBoxLayout()
# Video pane
self.video_pane = QLabel()
#self.video_pane.setFixedWidth(480)
main_layout.addWidget(self.video_pane)
# game log pane
self.log_pane = QTextEdit()
self.log_pane.setReadOnly(True)
main_layout.addWidget(self.log_pane)
# output of the last roll
self.last_roll_display = QLabel()
self.last_roll_display.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
self.last_roll_display.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.last_roll_display.setMaximumHeight(32) # Set the maximum height to 14 pixels
self.last_roll_display.setStyleSheet("font-size: 28px") # Set the font size to 14
main_layout.addWidget(self.last_roll_display)
# Add the radio buttons for the mode input
radio_button_size = "25px"
radio_button_font_size = "18px"
self.hit_damage_radio = QRadioButton("Hit/Damage")
self.hit_damage_radio.setStyleSheet(f"QRadioButton::indicator {{ width: {radio_button_size}; height: {radio_button_size}; font-size: {radio_button_font_size}; }}")
self.morale_radio = QRadioButton("Morale")
self.morale_radio.setStyleSheet(f"QRadioButton::indicator {{ width: {radio_button_size}; height: {radio_button_size}; font-size: {radio_button_font_size}; }}")
self.hit_damage_radio.toggled.connect(self.hit_damage_mode)
self.morale_radio.toggled.connect(self.morale_mode)
mode_layout = QHBoxLayout()
mode_layout.addWidget(self.hit_damage_radio)
mode_layout.addWidget(self.morale_radio)
main_layout.addLayout(mode_layout)
self.button_layout.setSpacing(0)
self.button_layout.setContentsMargins(0, 0, 0, 0)
button_size = 50
button_font = QFont()
button_font.setPixelSize(18)
for i in range(0, 10):
button = QPushButton(str(i+1))
button.setObjectName(str(i+1))
button.clicked.connect(self.button_click_handler)
row = int(i/6)
col = (i+6)%6
button.setMinimumSize(button_size, button_size)
button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
button.setFont(button_font)
self.button_layout.addWidget(button, row, col)
self.button_grid.setLayout(self.button_layout)
self.morale_radio.setChecked(True) # Set Hit/Damage mode as the default
self.last_roll_display.setMaximumWidth(self.button_grid.width())
main_layout.addWidget(self.button_grid)
self.setLayout(main_layout)
def button_click_handler(self):
sender = self.sender()
self.log_roll(f"hitting on {sender.text()}s")
self.kzgamer_thread.target_selected(int(sender.text()))
@pyqtSlot(QPixmap)
def update_video_pane(self, pixmap):
self.video_pane.setPixmap(pixmap)
@pyqtSlot(object)
def log_roll(self, message):
log_message = "NOOP"
if isinstance(message, list):
color_to_log = message[1]
log_message = message[0]
else:
log_message = message
color_to_log = "#000000"
self.last_roll_display.clear()
self.last_roll_display.setStyleSheet(f"color: {color_to_log}; font-size: 28px")
self.last_roll_display.setText(log_message)
self.log_message(log_message)
def log_message(self, message):
self.log_pane.append(f"[{QtCore.QTime.currentTime().toString('hh:mm:ss')}] {message}")
def hit_damage_mode(self, checked):
if checked:
self.log_roll("rolling Hit/Damage")
for i in range(1, 11):
button = self.button_grid.findChild(QPushButton, str(i))
if i <= 6:
button.setEnabled(True)
else:
button.setEnabled(False)
self.kzgamer_thread.mode_selected("Hit/Damage")
def morale_mode(self, checked):
if checked:
self.log_roll("rolling Morale")
for i in range(1, 11):
button = self.button_grid.findChild(QPushButton, str(i))
button.setEnabled(True)
self.kzgamer_thread.mode_selected("Morale")
def main():
app = QApplication(sys.argv)
main_window = MainWindow()
main_window.showMaximized()
sys.exit(app.exec_())
if __name__ == "__main__":
main()