-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_interaction.py
106 lines (81 loc) · 3.25 KB
/
user_interaction.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
from interface_score import *
from interface_info import *
import random
def start_timer(slot, timeout=1, interval=1000):
counter = 0
def handler():
nonlocal counter
counter += 1
slot(counter, timeout)
if counter >= timeout:
timer.stop()
timer.deleteLater()
timer = QtCore.QTimer()
timer.timeout.connect(handler)
timer.start(interval)
def timer_func(count, timeout):
#print(timeout-count, ' seconds left...')
if count >= timeout:
QtCore.QCoreApplication.quit()
def get_user_input(max_score, timeout):
app = QApplication(sys.argv)
ap = AppScore()
start_timer(timer_func, timeout)
app.exec_()
if ap.score > 0:
score = ap.score
else:
score = random.choice(range(1, max_score + 1))
#print("\nSorry, your time expired or your choice was invalid. A random choice was made for you.\n")
return score
def show_song_info(timeout,
times,
beat,
tempo,
key,
karaoke_bars,
pitch_labels,
scale_mode
):
app = QApplication(sys.argv)
ap = AppInfo(timeout,
times,
beat,
tempo,
key,
karaoke_bars,
pitch_labels,
scale_mode)
# weird that this works: the timer is being used to proceed to the song playing,
# and window is closed after it plays. maybe coz this method is called from a trycatch?
start_timer(timer_func, timeout)
app.exec_()
return ap, app
def update_chords_label(ap, app, bar, bars, chords, bar_karaoke, roles):
ap.bars.setText(str(bar)+'/'+str(bars))
for c in range(0, len(ap.chords)):
ap.chords[c].setText(chords[c]+' ')
ap.chords[c].setFont(QtGui.QFont("Chalkduster", 30))
if roles[c] == 'aj':
ap.chords[c].setStyleSheet("QLabel {background-color: #ffffff; color: #FF93EE; border: 2px solid #FF93EE;}")
if roles[c] == 'user':
ap.chords[c].setStyleSheet("QLabel {background-color: #ffffff; color: #00CFF9; border: 2px solid #00CFF9;}")
if c == bar_karaoke:
ap.chords[c].setStyleSheet("QLabel {background-color: #cccccc; color: #aa0000; border: 2px solid #aa0000;}")
ap.chords[c].setFont(QtGui.QFont("Arial", 45, QtGui.QFont.Bold))
if roles[c] == 'aj':
ap.wait2.setText(' Jam along, but...')
ap.wait.setText(" I'm the main player now. ")
ap.wait.setStyleSheet("QLabel {color: #FF93EE}")
ap.wait2.setStyleSheet("QLabel {color: #FF93EE}")
ap.wait.setFont(QtGui.QFont("Chalkduster", 25, QtGui.QFont.Bold))
if roles[c] == 'user':
ap.wait2.setText(' Play now! ')
ap.wait.setText("You're the main player now!")
ap.wait.setStyleSheet("QLabel {color: #00CFF9}")
ap.wait2.setStyleSheet("QLabel {color: #00CFF9}")
ap.wait.setFont(QtGui.QFont("Chalkduster", 25, QtGui.QFont.Bold))
start_timer(timer_func, 0)
app.exec()
delay_of_timer = 1
return ap, app, delay_of_timer