summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gui-project/cards.py83
-rw-r--r--gui-project/main.py26
2 files changed, 109 insertions, 0 deletions
diff --git a/gui-project/cards.py b/gui-project/cards.py
new file mode 100644
index 0000000..f175aa1
--- /dev/null
+++ b/gui-project/cards.py
@@ -0,0 +1,83 @@
+import asyncio
+
+from nicegui import ui
+
+class CardComponent():
+ def __init__(self, front : str, back : str):
+ if front is None or front == "":
+ raise Exception("Cannot have empty front on the card")
+
+ if back is None or back == "":
+ raise Exception("Cannot have empty back on the card")
+
+ self.front = front
+ self.back = back
+
+ def get_front(self):
+ return self.front
+
+ def get_back(self):
+ return self.back
+
+
+class CardUI():
+ def __init__(self, parent_ui, card : CardComponent):
+ self.parent_ui = parent_ui
+ self.card = card
+ self.is_resolved = asyncio.Event()
+ self.init_card()
+
+ def init_card(self):
+ with self.parent_ui:
+ self.row_parent = ui.row()
+ self.init_front()
+ self.init_back()
+
+ def init_front(self):
+ with self.row_parent:
+ ui.colors(frontc='#bcdbc6')
+ with ui.card().classes('bg-frontc') as self.front:
+ ui.markdown("**Front**")
+ ui.separator()
+ ui.markdown(self.card.get_front())
+ ui.button("Revert", on_click=lambda: self.revert_card())
+ self.front.set_visibility(False)
+
+ def init_back(self):
+ with self.row_parent:
+ ui.colors(back="#c4bcdb")
+ with ui.card().classes('bg-back') as self.back:
+ ui.markdown("_Back_")
+ ui.separator()
+ ui.markdown(self.card.get_back())
+ with ui.button_group():
+ ui.button("Got it", on_click=lambda: self.user_clicked_correct())
+ ui.button("Ain't got it", on_click=lambda: self.user_clicked_incorrect())
+ self.back.set_visibility(False)
+
+
+ def show_front(self):
+ self.back.set_visibility(False)
+ self.front.set_visibility(True)
+
+ def show_back(self):
+ self.front.set_visibility(False)
+ 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.is_resolved.set()
+
+ def user_clicked_incorrect(self):
+ ui.notify("Keep at it!")
+ self.is_resolved.set()
+
+ async def is_answered(self):
+ await self.is_resolved.wait()
+
+ def hide_card(self):
+ self.row_parent.delete()
diff --git a/gui-project/main.py b/gui-project/main.py
new file mode 100644
index 0000000..7e52c77
--- /dev/null
+++ b/gui-project/main.py
@@ -0,0 +1,26 @@
+from nicegui import ui
+from cards import CardUI, CardComponent
+from flashcards import Session, SCHEDULERS
+
+@ui.page("/")
+def main_page():
+ with ui.row() as main_row:
+ start_button = ui.button("Start", on_click=lambda: start_session(main_row, start_button))
+
+
+async def start_session(parent_ui, start_button):
+ ui.notify("Started session")
+ session = Session("brutal", ["/home/andreear/git/schwiizertuutsch/flashcards/diverse.fcard"], "/home/andreear/git/flashcards/state.txt")
+
+ start_button.set_visibility(False)
+ for i, card in enumerate(session.practice(20)):
+ # print(f"Showing card id {i}")
+ # print(f"Card front {card.front}")
+ # print(f"Card back {card.back}")
+ card_component = CardComponent(card.front, card.back)
+ card_ui = CardUI(parent_ui, card_component)
+ card_ui.show_front()
+ await card_ui.is_answered()
+ card_ui.hide_card()
+
+ui.run(port=3011) \ No newline at end of file