MIL-003: Step 2 - New flash cards
Review record RC-025 (Go, autonomous mode, not independent). Task: MIL-003#1 Task: MIL-003#2 Task: MIL-003#3 Task: MIL-003#4 Task: MIL-003#5
This commit is contained in:
@@ -84,11 +84,30 @@ class FlashCardView:
|
||||
|
||||
## @brief Button for a word the user does not know.
|
||||
self.wrong_button = tk.Button(
|
||||
root, image=self._wrong_image, highlightthickness=0, bd=0
|
||||
root,
|
||||
image=self._wrong_image,
|
||||
highlightthickness=0,
|
||||
bd=0,
|
||||
command=self.next_card,
|
||||
)
|
||||
self.wrong_button.grid(row=1, column=0)
|
||||
## @brief Button for a word the user knows.
|
||||
self.right_button = tk.Button(
|
||||
root, image=self._right_image, highlightthickness=0, bd=0
|
||||
root,
|
||||
image=self._right_image,
|
||||
highlightthickness=0,
|
||||
bd=0,
|
||||
command=self.next_card,
|
||||
)
|
||||
self.right_button.grid(row=1, column=1)
|
||||
|
||||
def next_card(self) -> None:
|
||||
"""Show the next card.
|
||||
|
||||
@return Nothing.
|
||||
"""
|
||||
self._view_model.next_card()
|
||||
self.canvas.itemconfig(
|
||||
self.language_text_id, text=self._view_model.language_name
|
||||
)
|
||||
self.canvas.itemconfig(self.word_text_id, text=self._view_model.text)
|
||||
|
||||
@@ -1,27 +1,69 @@
|
||||
"""View model of the flash card screen.
|
||||
|
||||
@file flash_card_view_model.py
|
||||
@brief Exposes the texts shown on the card; free of any Tkinter import.
|
||||
"""
|
||||
|
||||
from flash_card.constants import PLACEHOLDER_LANGUAGE_NAME, PLACEHOLDER_WORD
|
||||
|
||||
|
||||
class FlashCardViewModel:
|
||||
"""Data the flash card view shows."""
|
||||
|
||||
@property
|
||||
def language_name(self) -> str:
|
||||
"""Return the language name shown on the card.
|
||||
|
||||
@return The display name of the language.
|
||||
"""
|
||||
return PLACEHOLDER_LANGUAGE_NAME
|
||||
|
||||
@property
|
||||
def text(self) -> str:
|
||||
"""Return the word shown on the card.
|
||||
|
||||
@return The word text.
|
||||
"""
|
||||
return PLACEHOLDER_WORD
|
||||
"""View model of the flash card screen.
|
||||
|
||||
@file flash_card_view_model.py
|
||||
@brief Exposes the texts shown on the card; free of any Tkinter import.
|
||||
"""
|
||||
|
||||
from collections.abc import Mapping
|
||||
|
||||
from flash_card.application.dto.card_dto import CardDto
|
||||
from flash_card.application.use_cases.study_session import StudySession
|
||||
from flash_card.constants import FINISHED_MESSAGE, LANGUAGE_NAMES
|
||||
|
||||
|
||||
class FlashCardViewModel:
|
||||
"""Data the flash card view shows."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
session: StudySession,
|
||||
language_names: Mapping[str, str] = LANGUAGE_NAMES,
|
||||
) -> None:
|
||||
"""Create the view model and draw the first card.
|
||||
|
||||
@param session The study session that supplies the cards.
|
||||
@param language_names Display names by language code.
|
||||
"""
|
||||
## @brief The study session that supplies the cards.
|
||||
self._session = session
|
||||
## @brief Display names by language code.
|
||||
self._language_names = language_names
|
||||
## @brief The card shown now, or None when none is left.
|
||||
self._card: CardDto | None = session.next_card()
|
||||
|
||||
@property
|
||||
def is_finished(self) -> bool:
|
||||
"""Tell whether no card is left to show.
|
||||
|
||||
@return True when there is no card.
|
||||
"""
|
||||
return self._card is None
|
||||
|
||||
@property
|
||||
def language_name(self) -> str:
|
||||
"""Return the language name shown on the card.
|
||||
|
||||
@return The display name of the front language, upper case code when
|
||||
unknown, or an empty string when no card is left.
|
||||
"""
|
||||
if self._card is None:
|
||||
return ""
|
||||
code = self._card.front_language
|
||||
return self._language_names.get(code, code.upper())
|
||||
|
||||
@property
|
||||
def text(self) -> str:
|
||||
"""Return the word shown on the card.
|
||||
|
||||
@return The front text, or the finished message when no card is left.
|
||||
"""
|
||||
if self._card is None:
|
||||
return FINISHED_MESSAGE
|
||||
return self._card.front_text
|
||||
|
||||
def next_card(self) -> None:
|
||||
"""Draw the next card.
|
||||
|
||||
@return Nothing.
|
||||
"""
|
||||
self._card = self._session.next_card()
|
||||
|
||||
Reference in New Issue
Block a user