Skip to content

Commit 5321bd1

Browse files
committed
Initial Commit
0 parents  commit 5321bd1

6 files changed

Lines changed: 208 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TeamsDB
2+
.venv/
3+
database/
4+
src/__pycache__/

main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from src.gui import *
2+
3+
InitialGui()
4+

src/db.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sqlite3
2+
from sqlite3 import Error
3+
4+
5+
6+
def SqlConnection(routeDB):
7+
try:
8+
con = sqlite3.connect(routeDB)
9+
cur = con.cursor()
10+
cur.execute("SELECT * from MainExam WHERE ID=1")
11+
print("Conexión establecida")
12+
return cur
13+
14+
except:
15+
print("Conexión NO establecida")
16+
return False
17+
18+
19+
20+

src/gui.py

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import PySimpleGUI as sg
2+
3+
from src.db import SqlConnection
4+
from src.question import *
5+
6+
def AnswerGui(cur, realAnswer, userAnswer):
7+
8+
layout = [
9+
[sg.Text(f"Elegiste {userAnswer} y la respuesta correcta es {realAnswer[1]}", key="-CORRECT-")],
10+
[sg.Text(realAnswer[0], key="-ANSWER-", size=(80,30))],
11+
[sg.Button('OK')]
12+
]
13+
14+
window = sg.Window('Teams Exam - Answer', layout)
15+
while True:
16+
event, values = window.read()
17+
18+
if event == "OK":
19+
break
20+
21+
elif event is None or event == 'Exit':
22+
break
23+
24+
window.close()
25+
26+
27+
def ConclusionGui(windowTest, windowInitial, totalAnswers, correctAnswers):
28+
29+
perCorrect = correctAnswers/totalAnswers
30+
if perCorrect >= 0.7:
31+
checkPass = "APROBADO"
32+
else:
33+
checkPass = "SUSPENSO"
34+
35+
layout = [
36+
[sg.Text(f"Has acertado {correctAnswers} de un total de {totalAnswers} preguntas posibles")],
37+
[sg.Text(f"Este hecho representa una tasa de acierto del {perCorrect}")],
38+
[sg.Text(f"RESULTADO FINAL = {checkPass}")],
39+
[sg.Button('OK')]
40+
]
41+
42+
window = sg.Window('Teams Exam - Answer', layout)
43+
while True:
44+
event, values = window.read()
45+
46+
if event == "OK":
47+
break
48+
49+
elif event is None or event == 'Exit':
50+
break
51+
52+
windowInitial.close()
53+
windowTest.close()
54+
window.close()
55+
56+
57+
58+
59+
60+
def TestGui(cur, numberQuest, questChoice, windowInitial):
61+
62+
randomQuestions = random.sample(range(numberQuest), questChoice)
63+
n = 0
64+
correct = 0
65+
layout = [[sg.Text(GetThings(cur, randomQuestions[n]), size=(80,30), key="-QUESTION-")],
66+
[sg.InputText('Respuesta elegida: ', readonly=True, key='-IN-')],
67+
[sg.Text('Elige tu respuesta:', key='-OUT-')],
68+
[sg.Button('A'), sg.Button('B'), sg.Button('C')],
69+
[sg.Button('D'), sg.Button('E'), sg.Button('F')],
70+
[sg.Button('Enter')]
71+
]
72+
73+
window = sg.Window('Teams Exam', layout)
74+
75+
while True:
76+
event, values = window.read()
77+
78+
if event is None or event == 'Exit':
79+
break
80+
81+
elif event in 'ABCDEF':
82+
answerFormatted = f'Respuesta elegida: {event}'
83+
window.Element("-IN-").Update(value=answerFormatted)
84+
userAnswer = event
85+
86+
elif event == "Enter":
87+
realAnswer = GetThings(cur, randomQuestions[n], question=False)
88+
AnswerGui(cur,realAnswer,userAnswer)
89+
if realAnswer[1] == userAnswer:
90+
correct+=1
91+
92+
if n != len(randomQuestions)-1:
93+
n +=1
94+
window.Element("-QUESTION-").Update(GetThings(cur, randomQuestions[n]))
95+
else:
96+
ConclusionGui(window, windowInitial,len(randomQuestions), correct)
97+
break
98+
99+
windowInitial.close()
100+
window.close()
101+
102+
103+
104+
def InitialGui():
105+
106+
commonParams = [(30, 1), (10, 1), ("Helvetica", 12), (20, 1), (38, 1)]
107+
108+
layout = [[sg.Text('Introduce los siguientes datos para iniciar el examen:', size=(50, 2), font=commonParams[2])],
109+
[sg.Text("Selecciona la DB: "), sg.Input(key="-FILE-", change_submits=True), sg.FileBrowse(button_text = "Seleccionar", key="-FILEBROWSER-"), sg.Button("Aceptar", key = "-SUB-")],
110+
[sg.Text('No se ha introducido DB', size=commonParams[0], font=commonParams[2], key="-INF-")],
111+
[sg.Text("Selecciona el número de preguntas:"), sg.Listbox(size=commonParams[1], enable_events=True, default_values=[0],values=[0], disabled=True, key="-LIST-")],
112+
[sg.Button('OK', key="-OK-", disabled=True)]]
113+
114+
window = sg.Window('Teams Exam - Answer', layout)
115+
while True:
116+
event, values = window.read()
117+
if event == "-OK-":
118+
window.Hide()
119+
TestGui(cur, numberQuest, questChoice, window)
120+
121+
elif event == "-SUB-":
122+
cur = SqlConnection(values["-FILEBROWSER-"])
123+
124+
if cur == False:
125+
sg.Popup("Base de datos no válida")
126+
127+
else:
128+
cur.execute("SELECT COUNT(*) FROM MainExam")
129+
numberQuest = cur.fetchall()[0][0]
130+
131+
window.Element('-INF-').Update(f"Número de preguntas introducidas: {numberQuest}")
132+
window.Element('-LIST-').Update(values=list(range(1,numberQuest+1)), disabled=False)
133+
134+
elif event =="-LIST-":
135+
questChoice = values["-LIST-"][0]
136+
window.Element("-OK-").Update(disabled=False)
137+
138+
if event is None or event == 'Exit':
139+
break
140+
141+
window.close()
142+
143+
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
155+

src/question.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import random
2+
3+
4+
5+
6+
def GetThings(cur, idQuestion, question=True):
7+
8+
if question == True:
9+
cur.execute(f"SELECT ID,Question FROM MainExam WHERE ID ={idQuestion}")
10+
questionExtract = cur.fetchall()[0][1]
11+
return questionExtract
12+
13+
elif question == False:
14+
cur.execute(f"SELECT ID,Answers FROM MainExam WHERE ID ={idQuestion}")
15+
answerExtract = cur.fetchall()[0][1]
16+
17+
cur.execute(f"SELECT ID,Correct FROM MainExam WHERE ID ={idQuestion}")
18+
correctExtract = cur.fetchall()[0][1]
19+
20+
return answerExtract, correctExtract
21+

test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
correct =0
3+
4+
correct +=1 if True

0 commit comments

Comments
 (0)