-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThirdRoundAddQuestion.py
More file actions
53 lines (48 loc) · 2.55 KB
/
ThirdRoundAddQuestion.py
File metadata and controls
53 lines (48 loc) · 2.55 KB
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
from typing import override
from Button import Button
from TextBoxForFiles import TextBoxForFiles
from Constants import screen_height,screen_width,THIRD_ROUND_QUESTION_PATH,AUDIO_PATH,TIME_FOR_THIRD_ROUND
from AddQuestionMixin import AddQuestionMixin
from OpenFiles import OpenFiles
from FileCommands import FileCommands
from SaveFiles import SaveFiles
import pygame
class ThirdRoundAddQuestion(AddQuestionMixin):
def __init__(self):
super().__init__(THIRD_ROUND_QUESTION_PATH)
self._create_interface()
@override
def _create_interface(self):
self.data = {"file_path": "",
"question": '',
"answer(s)": []}
self.open_audio_button = Button(screen_width//2-420,screen_height//2+10,200,50,"Open audio",lambda : self.open_audio())
self.question_input = Button(screen_width//2-210,screen_height//2,200,50,"Question input:",lambda : None)
self.type_question = TextBoxForFiles(screen_width//2,screen_height//2+10,200,50,"question",self.data)
self.correct_answer = Button(screen_width//2-210,screen_height//2+100,200,50,"Correct answers:",lambda : None)
self.type_correct_answer = TextBoxForFiles(screen_width//2,screen_height//2+110,200,50,"answer(s)",self.data)
self.done = Button(screen_width//2-100,screen_height//2+200,200,50,"Done",lambda : self._save_data())
self.constraints = Button(screen_width//2-420,screen_height//2+70,200,50,f"Should be less than {TIME_FOR_THIRD_ROUND//1000} secons",lambda : None)
self.buttons = [self.question_input,self.type_question,self.correct_answer,self.type_correct_answer,self.done,self.open_audio_button,self.constraints]
self.audio = None
def open_audio(self):
if self.audio:
self.sound.stop()
self.audio,self.audio_path,self.original_path = OpenFiles.open_audio()
self.data['file_path'] = self.audio_path
if len(self.audio) / 1000 >TIME_FOR_THIRD_ROUND:
self.audio = None
self.audio_path = None
self.original_path = None
return
pygame.mixer.init()
self.sound = pygame.mixer.Sound((self.audio-30).raw_data)
self.sound.play()
@override
def _save_data(self):
if self.audio:
self.sound.stop()
next_screen,successful = SaveFiles.save_data(self.data,self.loaded_data,self.question_path)
if successful and not FileCommands.find_file_path_in_current_directory(self.audio_path):
FileCommands.move_file(self.original_path,AUDIO_PATH)
return next_screen