-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
111 lines (86 loc) · 3.51 KB
/
main.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
from widgets.gameWidget import GameWidget
from widgets.menuWidget import MenuWidget
from widgets.intermWidget import IntermWidget
from widgets.settingsWidget import SettingsWidget
from widgets.helpDialog import HelpDialog
from widgets.conclusionWidget import ConclusionWidget
from widgets.aboutDialog import AboutDialog
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import random as rand
import sys, utils
from functools import partial
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.central_widget = QStackedWidget()
self.setObjectName("centralWidget")
self.stageGenerator = utils.StageGenerator(utils.readSettings())
self.setCentralWidget(self.central_widget)
self.menu_widget = MenuWidget(self)
self.central_widget.addWidget(self.menu_widget)
self.central_widget.backToMenu = self.backToMenu
self.central_widget.stageGenerator = self.stageGenerator
self.central_widget.newGame = self.newGame
self.central_widget.nextStage = self.nextStage
self.central_widget.conclusionWidget = self.conclusionWidget
self.central_widget.incScore = self.incScore
self.central_widget.getScore = self.getScore
self.menu_widget.trainModeBtn.clicked.connect(partial(self.settingsWidget, test=False))
self.menu_widget.testModeBtn.clicked.connect(partial(self.settingsWidget, test=True))
self.menu_widget.helpBtn.clicked.connect(self.showHelpDialog)
self.menu_widget.aboutBtn.clicked.connect(self.showAboutDialog)
self.menu_widget.exitBtn.clicked.connect(self.close)
self.helpShortcut = QShortcut(QKeySequence("f1"), self)
self.setWindowTitle("MaskTrainer")
self.setWindowIcon(QIcon("assets/icon.ico"))
self.setGeometry(200, 200, 640, 640)
def settingsWidget(self, test):
settings_widget = SettingsWidget(test=test, parent=self)
self.central_widget.addWidget(settings_widget)
self.central_widget.setCurrentWidget(settings_widget)
def newGame(self, test):
if test:
self.helpShortcut.activated.connect(self.nothing)
self.question = 1
self.stages = []
self.total_questions = utils.readSettings()["ANSWERS_COUNT"]
else:
self.helpShortcut.activated.connect(self.showHelpDialog)
self.score = 0
stage = utils.Stage(self.central_widget.stageGenerator)
game_widget = GameWidget(stage=stage, test=test, parent=self)
self.central_widget.addWidget(game_widget)
self.central_widget.setCurrentWidget(game_widget)
def nextStage(self, test, stage=None, opts=None, last=False):
if test:
self.question += 1
self.stages.append([stage, opts])
last = (self.question == self.total_questions)
stage = utils.Stage(self.central_widget.stageGenerator)
game_widget = GameWidget(stage=stage, test=test, last=last, parent=self)
self.central_widget.addWidget(game_widget)
self.central_widget.setCurrentWidget(game_widget)
def conclusionWidget(self, test, stage, opts):
if test:
self.stages.append([stage, opts])
conclusion_widget = ConclusionWidget(stages=self.stages, parent=self)
else:
conclusion_widget = IntermWidget(stage=stage, opts=opts, parent=self)
self.central_widget.addWidget(conclusion_widget)
self.central_widget.setCurrentWidget(conclusion_widget)
def showHelpDialog(self):
helpDialog = HelpDialog(self)
helpDialog.show()
def showAboutDialog(self):
aboutDialog = AboutDialog(self)
aboutDialog.show()
def backToMenu(self):
self.central_widget.setCurrentWidget(self.menu_widget)
def incScore(self):
self.score += 1
def getScore(self):
return self.score
def nothing(self):
pass