Un script qui va vous permettre de créer des fiches de révisions sur votre numworks avec un aspect graphique simple mais efficace .

La navigation se fait uniquement avec les touche 1 a 9 pour choisir les menu, et la touche Clear pour revenir au menu précédent .
Chaque fiche a un ID unique . Le script est organisé en module pour simplifier la réutilisation et personnalisation.
Pour une meilleur organisation et un fonctionnement optimal voici un exemple pour vous aider à comprendre le système d'arborescence .

Je vous mets aussi un fichier Excel pour simplifier la création des pages et gérer l'affichage au mieux

Le fichier centre le titre de page et créer des chiffres de menu pour aider à la navigation .
Pour une page en fin d'arborescence cocher la case "Fin d'arborescence" , cela retire les chiffres de guide et remplace la valeur par true ( pour bonne interprétation du script )
Si vous avez des questions, remarques ou besoin d'aides aucun problèmes
Le fichier Excel ici -> https://www.petit-fichier.fr/2024/03/24/ficherevision/
- Code: Select all
from kandinsky import draw_string, fill_rect
from ion import keydown
import time
# Variables globales et configuration
x, y, width, height = 10, 10, 300, 172
input_area_y = height + 24
border_color = (128, 128, 128)
text_color = (0, 0, 0)
background_color = (255, 255, 255)
pages = {
1: (" Fiches de révision " ,["1 :Math", "2 :Science", "3 :Dessin construction", "4 :Divers", "5 :Formule divers", "6 :Liste programmes", "7 :Convertion"],False) ,
}
key_mapping = {
48: 0, 42: 1, 43: 2, 44: 3, 36: 4, 37: 5, 38: 6, 30: 7, 31: 8, 32: 9, 4: "OK", 17: "back"
}
def draw_frame_once():
fill_rect(0, 0, 320, 240, background_color)
fill_rect(x, y, width, height, border_color)
fill_rect(x+2, y+2, width-4, height-4, background_color)
fill_rect(x, input_area_y, width, 20, background_color)
def draw_text_only(page_title, lines, user_input="", is_terminal=False):
fill_rect(x+2, y+2, width-4, height-4, background_color)
fill_rect(x+10, input_area_y, width-20, 20, background_color)
draw_string(page_title, x+10, y+5, text_color)
line_height = 20
for i, line in enumerate(lines):
draw_string(line, x+10, y+10+(i+1)*line_height, text_color)
if is_terminal:
draw_string("retour", x+10, input_area_y, text_color)
def get_user_input(current_page, is_terminal, title, lines):
debounce_time = 0.3
last_press_time = time.monotonic()
draw_text_only(title, lines, is_terminal=is_terminal)
while True:
for key, digit in key_mapping.items():
if keydown(key):
current_time = time.monotonic()
if (current_time - last_press_time) >= debounce_time:
last_press_time = current_time
if key == 17 or (is_terminal and key == 4):
return 'back'
elif not is_terminal and key != 4 and key != 17:
return digit
while keydown(key):
pass
time.sleep(0.05)
def main():
current_page = 1
draw_frame_once()
while True:
page_info = pages.get(current_page, None)
if page_info is None:
draw_text_only("Erreur", ["Page non trouvée."], is_terminal=False)
time.sleep(2)
current_page = 1
continue
title, lines, is_terminal = page_info
user_input = get_user_input(current_page, is_terminal, title, lines)
if user_input == 'back':
if current_page != 1:
current_page //= 10
elif isinstance(user_input, int):
new_page = current_page * 10 + user_input
if new_page in pages:
current_page = new_page
else:
draw_text_only("Erreur", ["Page non trouvée."], is_terminal=is_terminal)
time.sleep(2)
draw_text_only(*pages[current_page][:2], is_terminal=is_terminal)
if __name__ == "__main__":
main()
main()
A Bientôt
