-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestsULM.py
68 lines (55 loc) · 1.75 KB
/
testsULM.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
#encoding=UTF-8
from interfaz import Ui_MainWindow
from PyQt4 import QtCore, QtGui
import sys
import sqlite3
DATABASE_NAME = './preguntas.sqlite'
class TestDataModel(object):
""" This class knows how to access the database, and is able to iterate
over the multiple-choice question
TODO: random questions
"""
def __init__(self):
self.conn = sqlite3.connect(DATABASE_NAME)
self.conn.text_factory = str
self.c = self.conn.cursor()
self.c.execute('select * from preguntas')
def get_question(self):
while True:
yield self.c.fetchone()
class TestUI(QtGui.QMainWindow):
""" This is the user interface.
"""
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
class TestData(object):
""" This class contains the data of a single test
, that is the 10, 20, 50 or 100 questions,
the solution for each question and the answer given
by the user, if any.
"""
def __init__(self):
self.question_indexes = [] # this is to keep order only, probably useless
self.questions = {}
self.results = {}
self.chosen_options = {}
def add_question(self,question_index, question, choice1, choice2, choice3, choice4, right_index):
self.question_indexes.append(question_index)
self.questions[question_index] = (choice1, choice2, choice3, choice4)
self.results[question_index] = right_index
self.chosen_options[question_index] = None
def main():
app = QtGui.QApplication(sys.argv)
myapp = TestUI()
myapp.show()
sys.exit(app.exec_())
def test_datamodel():
t = TestDataModel()
iterator = t.get_question()
for i in range(10):
print iterator.next()
if __name__ == "__main__":
main()
#test_datamodel()