-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormWindow.py
91 lines (71 loc) · 3.22 KB
/
FormWindow.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
import PyQt5
from PyQt5.QtWidgets import (QApplication, QFileDialog, QHBoxLayout, QLabel,
QPushButton, QSizePolicy, QSlider, QStyle, QVBoxLayout, QWidget, QButtonGroup)
from PyQt5.QtWidgets import QMainWindow,QWidget, QPushButton, QAction, QLineEdit, QGridLayout, QComboBox, QCheckBox
import sys
import MediaPlayer
import Form
import MultiLanguage
class FormWindow(QMainWindow):
def __init__(self, parent=None, form_list = None):
super(FormWindow, self).__init__(parent)
self.parent = parent
self.setWindowTitle("Dynamic State Tracker 2.0")
self.form_list = form_list
self.question_fields = list()
self.number_of_fields = 0
self.layout = QGridLayout()
self.main_widget = QWidget()
self.setCentralWidget(self.main_widget)
self.main_widget.setLayout(self.layout)
self.initalize_questions()
self.initalize_buttons()
def initalize_buttons(self):
'''
Initalizes the submit button and links it to the submit function.
'''
self.submitButton = QPushButton(self.parent.MultiLang.find_correct_word("Submit"), self)
self.submitButton.setEnabled(True)
self.submitButton.clicked.connect(self.submit_form)
self.layout.addWidget(self.submitButton,0,1)
self.remember = QCheckBox(self.parent.MultiLang.find_correct_word("Remember me"))
self.layout.addWidget(self.remember, 0 , 0)
self.remember.toggle()
def initalize_questions(self):
'''
For every questions in the form, add an answer field.
'''
for q in self.form_list:
self.add_answer(q.get_question(),1, q.get_data())
def add_answer(self, text = None, type = 0, past_data = " "):
'''
Adds a question into the window, if there is no text provided the question is set to "Failed to load.". Also inserts an answer box for each question.
'''
if(text == None):
question = QLabel("Failed to load.")
else:
question = QLabel(text)
field = QLineEdit(self)
field.setText(past_data)
self.question_fields.append(field)
self.number_of_fields = self.number_of_fields+1
self.layout.addWidget(question,self.number_of_fields,0)
self.layout.addWidget(field,self.number_of_fields,1)
def submit_form(self):
'''
Opens the player and sends it the answered questions as a list.
'''
if self.remember.isChecked():
for i in range(0, len(self.question_fields)):
self.form_list[i].set_data(self.question_fields[i].text())
else:
for i in range(0, len(self.question_fields)):
self.form_list[i].set_data(" ")
self.answered_form = list()
for i in range(0, len(self.question_fields)):
newFormComponent = Form.Form()
newFormComponent.set_question(self.form_list[i].get_question())
newFormComponent.set_data(self.question_fields[i].text())
self.answered_form.append(newFormComponent)
self.parent.video_player(self.answered_form)
self.close()