-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
148 lines (118 loc) · 3.04 KB
/
Copy pathui.py
File metadata and controls
148 lines (118 loc) · 3.04 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""Banner, colors, menu, and record presentation."""
from rich import box
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
from rich.text import Text
from storage import FIELDS
console = Console()
def banner():
title = Text(
">_ PYTHON DATA SHELL",
style="bold cyan",
justify="center",
)
title.append(
"\nACADEMY MANAGER / v2.0",
style="bold white",
)
title.append(
"\nCourses | Trainers | Students | Assignments",
style="dim",
)
console.print(
Panel(
title,
border_style="cyan",
padding=(1, 2),
subtitle="sakispat / local workspace",
)
)
def dashboard(data):
"""Display record counts and menu options."""
stats = Table(
box=box.SIMPLE,
expand=True,
border_style="cyan",
)
for key in FIELDS:
stats.add_column(
key.upper(),
justify="center",
style="bold cyan",
)
stats.add_row(
*(str(len(data[key])) for key in FIELDS)
)
console.print(stats)
menu = Table(
box=None,
show_header=False,
padding=(0, 2),
)
options = [
("1", "Add course"),
("2", "Add trainer"),
("3", "Add student"),
("4", "Add assignment"),
("5", "View records"),
("6", "Search records"),
("0", "Exit"),
]
for key, label in options:
menu.add_row(
Text(key, style="bold cyan"),
Text(label),
)
console.print(
Panel(
menu,
title="MAIN MENU",
border_style="blue",
)
)
console.print(
"Saved after each entry. "
"Type /cancel in a form to go back.",
style="dim",
)
def show_records(key, rows):
"""Display tables in wide terminals and cards in narrow terminals."""
if not rows:
console.print(
f"{key.title()}: no records.",
style="yellow",
)
return
if console.width < 100:
for index, row in enumerate(rows, 1):
table = Table.grid(padding=(0, 2))
for field in FIELDS[key]:
table.add_row(
Text(field, style="cyan"),
Text(row[field]),
)
console.print(
Panel(
table,
title=f"{key.title()} #{index}",
border_style="blue",
)
)
return
table = Table(
title=key.title(),
box=box.ROUNDED,
header_style="bold cyan",
border_style="blue",
show_lines=True,
)
table.add_column("#", style="dim")
for field in FIELDS[key]:
table.add_column(field, overflow="fold")
for index, row in enumerate(rows, 1):
table.add_row(
str(index),
*(Text(row[field]) for field in FIELDS[key]),
)
console.print(table)