#!/usr/bin/python3
import os
from mylib.braille import *


def load_modules():
    myfile = open("modules/modules.kdp", 'r')
    modules = myfile.read()
    modules = modules.split("\n")
    i = 0
    while i < len(modules):
        modules[i] = modules[i].split(":")
        i += 1
    return modules


def main():
    modules = load_modules()
    key = 0
    i = 0
    rp = 1
    while 42:
        printb(modules[i][0], rp)
        key = get_key()
        if key == keyboard['key_down'] and i < len(modules) - 1:
            i += 1
            rp = 1
        elif key == keyboard['key_up'] and i > 0:
            i -= 1
            rp = 1
        elif key == keyboard['key_ok']:
            os.system("modules/"+modules[i][1]+"main")
        elif key == 536870935 and rp > 1:
            rp = rp - 1
        elif key == 536870936:
            rp = rp + 1
        elif key == 120:
            exit(0)
        else:
            flashb("Erreur: Touche invalide")
main()
