-
Notifications
You must be signed in to change notification settings - Fork 2
/
seleziona_lingua.py
40 lines (29 loc) · 1.13 KB
/
seleziona_lingua.py
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
import curses
def seleziona_lingua(stdscr):
lingue = ['Italiano', 'English', 'Français', 'Español']
selezione = 0
curses.curs_set(0) # Nascondo il cursore
while True:
stdscr.clear()
h, w = stdscr.getmaxyx()
x_start = w // 2 - 10
for idx, lingua in enumerate(lingue):
y = h // 2 - 2 + idx
x = x_start + 3
if idx == selezione:
stdscr.attron(curses.A_BOLD)
stdscr.addstr(y, x, lingua)
stdscr.attroff(curses.A_BOLD)
stdscr.addstr(y, x - 3, ">") # Aggiungo la freccia per indicare la selezione corrente
else:
stdscr.addstr(y, x, lingua)
stdscr.refresh()
key = stdscr.getch()
if key == curses.KEY_UP and selezione > 0:
selezione -= 1
elif key == curses.KEY_DOWN and selezione < len(lingue) - 1:
selezione += 1
elif key == curses.KEY_ENTER or key in [10, 13]:
return lingue[selezione]
if __name__ == '__main__':
print(curses.wrapper(seleziona_lingua))