-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
102 lines (74 loc) · 2.78 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
# -*- coding: utf-8 -*-
import threading
import sys
import pygame
import time
import random
from another import TIMINGS, NAMES, FONT_COLORS, ALL_TEXT
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QMainWindow
from PyQt5 import uic
NUM = random.randint(0, len(ALL_TEXT)) % len(ALL_TEXT)
IMAGE_NUM = random.randint(0, len(FONT_COLORS)) % len(FONT_COLORS)
SONG_NAME = NAMES[NUM]
text = ALL_TEXT[NUM]
Timer = True
# parallel checking input of user without intervention in working of program
class TimerChange:
# checking timer function
def timer(timing, widget):
while Timer:
time.sleep(0.001)
if time.time() - timing > TIMINGS[NUM][window.index]:
window.index = (window.index + 1) % len(TIMINGS[NUM])
window.update_text()
class MyWidget(QMainWindow):
def __init__(self):
super().__init__()
# program design
self.uic = uic.loadUi('Project.ui', self)
# conntect with cycle of functions which take part in parallel-checking
self.text_line.textChanged.connect(self.solve_changes)
# background image (chosen by random)
s = "#MainWindow { border-image: url(images/"
t = ") 0 0 0 0 stretch stretch; }"
self.uic.setStyleSheet(s + str(IMAGE_NUM) + t)
# background image (chosen by random but simultaneously)
self.cur_color = FONT_COLORS[IMAGE_NUM]
self.uic.label.setStyleSheet("color:" + self.cur_color + ";")
self.uic.melodyList.setStyleSheet("color:" + self.cur_color + ";")
# print name of a playing song
self.uic.melodyList.setText(SONG_NAME.rstrip('.mp3'))
self.index = 0
self.score = 0
# current time
self.t = time.time()
# music playing (SONG_NAME is a file going to play)
pygame.mixer.music.load("music\\" + SONG_NAME)
pygame.mixer.music.play()
def solve_changes(self):
tindex = 0
for i in self.text_line.text():
if i != text[self.index][tindex]:
self.text_line.setText(self.text_line.text()[:-1])
tindex = (tindex + 1) % len(text[self.index])
def update_text(self):
self.score += len(self.text_line.text())
if self.index < len(text):
self.label.setText(text[self.index])
self.text_line.setText('')
else:
self.label.setText('your score is ' + str(self.score))
self.text_line.setText('')
while(1):
pass
if __name__ == '__main__':
pygame.mixer.init()
app = QApplication(sys.argv)
window = MyWidget()
t = threading.Thread(target=TimerChange.timer, args=[time.time(), window])
t.start()
window.show()
sys.exit(app.exec_())
Timer = False
t.join()