-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexercise_tree.py
More file actions
33 lines (27 loc) · 872 Bytes
/
Copy pathexercise_tree.py
File metadata and controls
33 lines (27 loc) · 872 Bytes
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
# pythonlings/widgets/exercise_tree.py
from __future__ import annotations
from typing import TYPE_CHECKING
from textual.widgets import Tree
if TYPE_CHECKING:
from pythonlings.core.exercise import Exercise
class ExerciseTree(Tree[str]):
def __init__(self) -> None:
super().__init__("exercises", id="tree")
self.show_root = False
def render_topic(
self,
topic: str,
exercises: list["Exercise"],
completed: set[str],
current: str | None,
) -> None:
self.clear()
node = self.root.add(topic, expand=True)
for ex in exercises:
if ex.name in completed:
marker = "✓"
elif ex.name == current:
marker = "●"
else:
marker = "🔒"
node.add_leaf(f"{marker} {ex.name}", data=ex.name)