summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreeaRadoescu <randreea23@gmail.com>2024-10-16 20:56:17 +0200
committerAndreeaRadoescu <randreea23@gmail.com>2024-10-16 20:56:17 +0200
commite5ee95a78113ab245168916e15fc411b6ab999a9 (patch)
tree0b1f7ad527c441a0ac2589c7f9d9ab50c156e2ea
parent2d385a869488c54513c58e95cd78bb3053a41208 (diff)
update current question number, added final score, fix width of cards, remove notification when revealing cards
-rw-r--r--gui-project/cards.py8
-rw-r--r--gui-project/main_ui.py23
2 files changed, 23 insertions, 8 deletions
diff --git a/gui-project/cards.py b/gui-project/cards.py
index 42a08b0..1bb4320 100644
--- a/gui-project/cards.py
+++ b/gui-project/cards.py
@@ -29,6 +29,7 @@ class CardUI():
self.card = card
self.is_resolved = asyncio.Event()
self.init_card()
+ self.correctly_answered = False
def init_card(self):
with self.parent_ui:
@@ -38,7 +39,7 @@ class CardUI():
def init_front(self):
with self.row_parent:
- with ui.card().classes('bg-frontc') as self.front:
+ with ui.card().classes('bg-frontc w-[600px] h-[200px] mx-auto') as self.front:
ui.markdown("**Front**")
ui.separator()
ui.markdown(self.card.get_front())
@@ -47,7 +48,7 @@ class CardUI():
def init_back(self):
with self.row_parent:
- with ui.card().classes('bg-back') as self.back:
+ with ui.card().classes('bg-back w-[600px] h-[200px] mx-auto') as self.back:
ui.markdown("_Back_")
ui.separator()
ui.markdown(self.card.get_back())
@@ -65,15 +66,14 @@ class CardUI():
self.back.set_visibility(True)
def revert_card(self):
- ui.notify("Showing back")
self.show_back()
def user_clicked_correct(self):
ui.notify("You got this")
+ self.correctly_answered = True
self.is_resolved.set()
def user_clicked_incorrect(self):
- ui.notify("Keep at it!")
self.is_resolved.set()
async def is_answered(self):
diff --git a/gui-project/main_ui.py b/gui-project/main_ui.py
index f6351b0..8f3371c 100644
--- a/gui-project/main_ui.py
+++ b/gui-project/main_ui.py
@@ -1,3 +1,5 @@
+from typing import final
+
from nicegui import ui
import os
import random
@@ -16,7 +18,7 @@ class MainUI():
# ========= start initializing UI ===========
with ui.header() as self.header:
- self.header_element = ui.label("Session Configuration")
+ self.header_element = ui.markdown("Session Configuration")
self.root_ui = ui.row().classes("fixed-center")
with self.root_ui:
with ui.card(align_items="baseline") as self.session_configuration:
@@ -51,8 +53,7 @@ class MainUI():
self.header.classes("bg-negative")
with self.header:
- self.header_element = ui.markdown(f"Currently in **{run_mode}** mode")
-
+ self.header_element = ui.markdown(f"Currently in **{run_mode}** mode\nQuestion 1/{self.nb_questions_ui.value}")
self.run_mode = run_mode
# read values from UI and set session configuration
self.nb_questions = int(self.nb_questions_ui.value)
@@ -73,8 +74,11 @@ class MainUI():
session = Session("brutal", cards_paths,
"/home/andreear/git/flashcards/state.txt")
- ui.colors(frontc='#bcdbc6', back="#c4bcdb")
+ final_score = 0
+ ui.colors(frontc='#bcdbc6', back="#c4bcdb", final="#9cfcfc")
for i, card in enumerate(session.practice(self.nb_questions)):
+ self.header_element.set_content(f"Currently in **practice** mode\n\nQuestion {i+1}/{int(self.nb_questions_ui.value)}")
+ # print(self.header_element.content)
prompt_type_binary = self.prompt_type.lower()
if self.prompt_type.lower() == "random":
random_nb = random.randint(0, sys.maxsize)
@@ -92,5 +96,16 @@ class MainUI():
card_ui.show_front()
await card_ui.is_answered()
+ if card_ui.correctly_answered:
+ final_score += 1
card_ui.hide_card()
+ with self.root_ui:
+ with ui.card(align_items="center").classes("bg-final"):
+ ui.markdown("## Finished")
+ ui.label(f"Your final score is: {final_score}/{self.nb_questions}")
+ ui.label("To start again, refresh the page")
+
+
+
+